Skip to content

Commit b4a1fc5

Browse files
yiweichifrisitano
andauthored
feat: NetworkHandle support announce block to peer (#377)
* feat: NetworkHandle support announce block to peer * update comment * remove unused file * fix clippy * fix deny * fix deny * fix: comment * fix: fmt * update cargo deny --------- Co-authored-by: frisitano <[email protected]>
1 parent 079764e commit b4a1fc5

File tree

13 files changed

+48
-12
lines changed

13 files changed

+48
-12
lines changed

crates/era-downloader/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn read_dir(
4343
.collect::<eyre::Result<Vec<_>>>()?;
4444
let mut checksums = checksums.ok_or_eyre("Missing file `checksums.txt` in the `dir`")?;
4545

46-
entries.sort_by(|(left, _), (right, _)| left.cmp(right));
46+
entries.sort_by_key(|(left, _)| *left);
4747

4848
Ok(stream::iter(entries.into_iter().skip(start_from as usize / BLOCKS_PER_FILE).map(
4949
move |(_, path)| {

crates/net/discv4/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ impl Discv4Service {
16281628
.filter(|entry| entry.node.value.is_expired())
16291629
.map(|n| n.node.value)
16301630
.collect::<Vec<_>>();
1631-
nodes.sort_by(|a, b| a.last_seen.cmp(&b.last_seen));
1631+
nodes.sort_by_key(|a| a.last_seen);
16321632
let to_ping = nodes.into_iter().map(|n| n.record).take(MAX_NODES_PING).collect::<Vec<_>>();
16331633
for node in to_ping {
16341634
self.try_ping(node, PingReason::RePing)

crates/net/network-api/src/block.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ pub trait EthWireProvider<N: NetworkPrimitives> {
2323

2424
/// Announce a new block to the network over the eth wire protocol.
2525
fn eth_wire_announce_block(&self, block: N::NewBlockPayload, hash: B256);
26+
27+
/// Announce a new block to a specific peer over the eth wire protocol.
28+
fn eth_wire_announce_block_to_peer(
29+
&self,
30+
peer_id: PeerId,
31+
block: N::NewBlockPayload,
32+
hash: B256,
33+
);
2634
}

crates/net/network-api/src/noop.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ impl<N: NetworkPrimitives> EthWireProvider<N> for NoopNetwork<N> {
223223
) {
224224
unreachable!()
225225
}
226+
227+
fn eth_wire_announce_block_to_peer(
228+
&self,
229+
_peer_id: PeerId,
230+
_block: <N as NetworkPrimitives>::NewBlockPayload,
231+
_hash: alloy_primitives::B256,
232+
) {
233+
unreachable!()
234+
}
226235
}
227236

228237
impl<Net> NetworkPeersEvents for NoopNetwork<Net>

crates/net/network/src/network.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use crate::{
2-
config::NetworkMode, message::PeerMessage, protocol::RlpxSubProtocol,
3-
swarm::NetworkConnectionState, transactions::TransactionsHandle, FetchClient,
2+
config::NetworkMode,
3+
message::{NewBlockMessage, PeerMessage},
4+
protocol::RlpxSubProtocol,
5+
swarm::NetworkConnectionState,
6+
transactions::TransactionsHandle,
7+
FetchClient,
48
};
59
use alloy_primitives::B256;
610
use enr::Enr;
@@ -237,6 +241,16 @@ impl<N: NetworkPrimitives> EthWireProvider<N> for NetworkHandle<N> {
237241
fn eth_wire_announce_block(&self, block: N::NewBlockPayload, hash: B256) {
238242
self.announce_block(block, hash)
239243
}
244+
245+
fn eth_wire_announce_block_to_peer(
246+
&self,
247+
peer_id: PeerId,
248+
block: N::NewBlockPayload,
249+
hash: B256,
250+
) {
251+
let msg = NewBlockMessage { hash, block: Arc::new(block) };
252+
self.send_eth_message(peer_id, PeerMessage::NewBlock(msg))
253+
}
240254
}
241255

242256
impl<N: NetworkPrimitives> NetworkProtocols for NetworkHandle<N> {

crates/scroll/alloy/evm/src/block/curie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ mod tests {
151151

152152
// check oracle storage changeset
153153
let mut storage = oracle.storage.into_iter().collect::<Vec<(U256, StorageSlot)>>();
154-
storage.sort_by(|(a, _), (b, _)| a.cmp(b));
154+
storage.sort_by_key(|(a, _)| *a);
155155
for (got, expected) in storage.into_iter().zip(CURIE_L1_GAS_PRICE_ORACLE_STORAGE) {
156156
assert_eq!(got.0, expected.0);
157157
assert_eq!(got.1, StorageSlot { present_value: expected.1, ..Default::default() });

crates/scroll/alloy/evm/src/block/feynman.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ mod tests {
148148

149149
// check oracle storage changeset
150150
let mut storage = oracle.storage.into_iter().collect::<Vec<(U256, StorageSlot)>>();
151-
storage.sort_by(|(a, _), (b, _)| a.cmp(b));
151+
storage.sort_by_key(|(a, _)| *a);
152152
for (got, expected) in storage.into_iter().zip(FEYNMAN_L1_GAS_PRICE_ORACLE_STORAGE) {
153153
assert_eq!(got.0, expected.0);
154154
assert_eq!(got.1, StorageSlot { present_value: expected.1, ..Default::default() });

crates/scroll/alloy/evm/src/block/galileo_v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ mod tests {
148148

149149
// check oracle storage changeset
150150
let mut storage = oracle.storage.into_iter().collect::<Vec<(U256, StorageSlot)>>();
151-
storage.sort_by(|(a, _), (b, _)| a.cmp(b));
151+
storage.sort_by_key(|(a, _)| *a);
152152
for (got, expected) in storage.into_iter().zip(GALILEO_V2_L1_GAS_PRICE_ORACLE_STORAGE) {
153153
assert_eq!(got.0, expected.0);
154154
assert_eq!(got.1, StorageSlot { present_value: expected.1, ..Default::default() });

crates/scroll/evm/src/execute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ mod tests {
446446

447447
// check oracle contract contains storage changeset
448448
let mut storage = oracle.storage.into_iter().collect::<Vec<(U256, StorageSlot)>>();
449-
storage.sort_by(|(a, _), (b, _)| a.cmp(b));
449+
storage.sort_by_key(|(a, _)| *a);
450450
for (got, expected) in storage.into_iter().zip(CURIE_L1_GAS_PRICE_ORACLE_STORAGE) {
451451
assert_eq!(got.0, expected.0);
452452
assert_eq!(got.1, StorageSlot { present_value: expected.1, ..Default::default() });

crates/stages/stages/src/stages/hashing_account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl AccountHashingStage {
9999
// Account State generator
100100
let mut account_cursor =
101101
provider.tx_ref().cursor_write::<tables::PlainAccountState>()?;
102-
accounts.sort_by(|a, b| a.0.cmp(&b.0));
102+
accounts.sort_by_key(|a| a.0);
103103
for (addr, acc) in &accounts {
104104
account_cursor.append(*addr, acc)?;
105105
}

0 commit comments

Comments
 (0)