@@ -43,6 +43,8 @@ pub struct ScrollNetworkManager<N> {
4343 from_handle_rx : UnboundedReceiverStream < NetworkHandleMessage > ,
4444 /// The scroll wire protocol manager.
4545 scroll_wire : ScrollWireManager ,
46+ /// The constant value that must be added to the block number to get the total difficulty.
47+ td_constant : U128 ,
4648}
4749
4850impl ScrollNetworkManager < RethNetworkHandle < ScrollNetworkPrimitives > > {
@@ -51,6 +53,7 @@ impl ScrollNetworkManager<RethNetworkHandle<ScrollNetworkPrimitives>> {
5153 pub async fn new < C : BlockNumReaderT + ' static > (
5254 mut network_config : RethNetworkConfig < C , ScrollNetworkPrimitives > ,
5355 scroll_wire_config : ScrollWireConfig ,
56+ td_constant : U128 ,
5457 ) -> Self {
5558 // Create the scroll-wire protocol handler.
5659 let ( scroll_wire_handler, events) = ScrollWireProtocolHandler :: new ( scroll_wire_config) ;
@@ -74,7 +77,7 @@ impl ScrollNetworkManager<RethNetworkHandle<ScrollNetworkPrimitives>> {
7477 // Spawn the inner network manager.
7578 tokio:: spawn ( inner_network_manager) ;
7679
77- Self { handle, from_handle_rx : from_handle_rx. into ( ) , scroll_wire }
80+ Self { handle, from_handle_rx : from_handle_rx. into ( ) , scroll_wire, td_constant }
7881 }
7982}
8083
@@ -83,7 +86,11 @@ impl<N: FullNetwork<Primitives = ScrollNetworkPrimitives>> ScrollNetworkManager<
8386 ///
8487 /// This is used when the scroll-wire [`ScrollWireProtocolHandler`] and the inner network
8588 /// manager [`RethNetworkManager`] are instantiated externally.
86- pub fn from_parts ( inner_network_handle : N , events : UnboundedReceiver < ScrollWireEvent > ) -> Self {
89+ pub fn from_parts (
90+ inner_network_handle : N ,
91+ events : UnboundedReceiver < ScrollWireEvent > ,
92+ td_constant : U128 ,
93+ ) -> Self {
8794 // Create the channel for sending messages to the network manager from the network handle.
8895 let ( to_manager_tx, from_handle_rx) = mpsc:: unbounded_channel ( ) ;
8996
@@ -92,7 +99,7 @@ impl<N: FullNetwork<Primitives = ScrollNetworkPrimitives>> ScrollNetworkManager<
9299
93100 let handle = ScrollNetworkHandle :: new ( to_manager_tx, inner_network_handle) ;
94101
95- Self { handle, from_handle_rx : from_handle_rx. into ( ) , scroll_wire }
102+ Self { handle, from_handle_rx : from_handle_rx. into ( ) , scroll_wire, td_constant }
96103 }
97104
98105 /// Returns a new [`ScrollNetworkHandle`] instance.
@@ -119,7 +126,7 @@ impl<N: FullNetwork<Primitives = ScrollNetworkPrimitives>> ScrollNetworkManager<
119126 . collect ( ) ;
120127
121128 let eth_wire_new_block = {
122- let td = U128 :: from ( block. block . header . number ) ;
129+ let td = compute_td ( self . td_constant , block. block . header . number ) ;
123130 let mut eth_wire_block = block. block . clone ( ) ;
124131 eth_wire_block. header . extra_data = block. signature . clone ( ) . into ( ) ;
125132 EthWireNewBlock { block : eth_wire_block, td }
@@ -223,3 +230,8 @@ impl<N: FullNetwork<Primitives = ScrollNetworkPrimitives>> Stream for ScrollNetw
223230 Poll :: Pending
224231 }
225232}
233+
234+ /// Compute totally difficulty for a given block number.
235+ fn compute_td ( td_constant : U128 , block_number : u64 ) -> U128 {
236+ td_constant. saturating_add ( U128 :: from ( block_number) )
237+ }
0 commit comments