Skip to content

Commit d590bf0

Browse files
authored
feat: add missing td to rpc header (#342)
* feat: add missing td to rpc header Signed-off-by: Gregory Edison <[email protected]> * fix: lints Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]>
1 parent 7dd3b09 commit d590bf0

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

crates/scroll/rpc/src/eth/block.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
//! Loads and formats Scroll block RPC response.
22
3-
use crate::{ScrollEthApi, ScrollEthApiError};
3+
use crate::{RpcBlockHeaderMut, ScrollEthApi, ScrollEthApiError};
44

5-
use reth_rpc_convert::RpcConvert;
5+
use alloy_consensus::BlockHeader;
6+
use alloy_eips::BlockId;
7+
use reth_provider::HeaderProvider;
8+
use reth_rpc_convert::{RpcConvert, RpcTypes};
69
use reth_rpc_eth_api::{
710
helpers::{EthBlocks, LoadBlock},
8-
RpcNodeCore,
11+
EthApiTypes, FromEthApiError, FullEthApiTypes, RpcBlock, RpcNodeCore,
912
};
1013
use reth_rpc_eth_types::error::FromEvmError;
1114

@@ -14,7 +17,33 @@ where
1417
N: RpcNodeCore,
1518
ScrollEthApiError: FromEvmError<N::Evm>,
1619
Rpc: RpcConvert<Primitives = N::Primitives, Error = ScrollEthApiError>,
20+
<<Self as EthApiTypes>::NetworkTypes as RpcTypes>::Header: RpcBlockHeaderMut,
1721
{
22+
async fn rpc_block(
23+
&self,
24+
block_id: BlockId,
25+
full: bool,
26+
) -> Result<Option<RpcBlock<Self::NetworkTypes>>, Self::Error>
27+
where
28+
Self: FullEthApiTypes,
29+
{
30+
let Some(block) = self.recovered_block(block_id).await? else { return Ok(None) };
31+
32+
let td = self
33+
.provider()
34+
.header_td_by_number(block.number())
35+
.map_err(Self::Error::from_eth_err)?;
36+
37+
let mut block = block.clone_into_rpc_block(
38+
full.into(),
39+
|tx, tx_info| self.tx_resp_builder().fill(tx, tx_info),
40+
|header, size| self.tx_resp_builder().convert_header(header, size),
41+
)?;
42+
43+
*block.header.total_difficulty_mut() = td;
44+
45+
Ok(Some(block))
46+
}
1847
}
1948

2049
impl<N, Rpc> LoadBlock for ScrollEthApi<N, Rpc>

crates/scroll/rpc/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ pub mod sequencer;
1515
pub use error::{ScrollEthApiError, SequencerClientError};
1616
pub use eth::{ScrollEthApi, ScrollReceiptBuilder};
1717
pub use sequencer::SequencerClient;
18+
19+
/// Gives mutable access to the fields of an RPC block header.
20+
pub trait RpcBlockHeaderMut {
21+
/// Mutable reference to the total difficulty.
22+
fn total_difficulty_mut(&mut self) -> &mut Option<alloy_primitives::U256>;
23+
}
24+
25+
impl RpcBlockHeaderMut for alloy_rpc_types_eth::Header {
26+
fn total_difficulty_mut(&mut self) -> &mut Option<alloy_primitives::U256> {
27+
&mut self.total_difficulty
28+
}
29+
}

0 commit comments

Comments
 (0)