mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: remove some unnecessary calls to unwrap/expect (#6727)
This commit is contained in:
@ -545,8 +545,7 @@ impl Discv4Service {
|
||||
for (key, val) in config.additional_eip868_rlp_pairs.iter() {
|
||||
builder.add_value_rlp(key, val.clone());
|
||||
}
|
||||
|
||||
builder.build(&secret_key).expect("v4 is set; qed")
|
||||
builder.build(&secret_key).expect("v4 is set")
|
||||
};
|
||||
|
||||
let (to_service, commands_rx) = mpsc::unbounded_channel();
|
||||
|
||||
@ -113,7 +113,7 @@ impl Message {
|
||||
// Sign the payload with the secret key using recoverable ECDSA
|
||||
let signature: RecoverableSignature = SECP256K1.sign_ecdsa_recoverable(
|
||||
&secp256k1::Message::from_slice(keccak256(&payload).as_ref())
|
||||
.expect("is correct MESSAGE_SIZE; qed"),
|
||||
.expect("B256.len() == MESSAGE_SIZE"),
|
||||
secret_key,
|
||||
);
|
||||
|
||||
|
||||
@ -359,32 +359,32 @@ pub struct SharedCapabilities(Vec<SharedCapability>);
|
||||
|
||||
impl SharedCapabilities {
|
||||
/// Merges the local and peer capabilities and returns a new [`SharedCapabilities`] instance.
|
||||
#[inline]
|
||||
pub fn try_new(
|
||||
local_protocols: Vec<Protocol>,
|
||||
peer_capabilities: Vec<Capability>,
|
||||
) -> Result<Self, P2PStreamError> {
|
||||
Ok(Self(shared_capability_offsets(local_protocols, peer_capabilities)?))
|
||||
shared_capability_offsets(local_protocols, peer_capabilities).map(Self)
|
||||
}
|
||||
|
||||
/// Iterates over the shared capabilities.
|
||||
#[inline]
|
||||
pub fn iter_caps(&self) -> impl Iterator<Item = &SharedCapability> {
|
||||
self.0.iter()
|
||||
}
|
||||
|
||||
/// Returns the eth capability if it is shared.
|
||||
#[inline]
|
||||
pub fn eth(&self) -> Result<&SharedCapability, P2PStreamError> {
|
||||
for cap in self.iter_caps() {
|
||||
if cap.is_eth() {
|
||||
return Ok(cap)
|
||||
}
|
||||
}
|
||||
Err(P2PStreamError::CapabilityNotShared)
|
||||
self.iter_caps().find(|c| c.is_eth()).ok_or(P2PStreamError::CapabilityNotShared)
|
||||
}
|
||||
|
||||
/// Returns the negotiated eth version if it is shared.
|
||||
#[inline]
|
||||
pub fn eth_version(&self) -> Result<EthVersion, P2PStreamError> {
|
||||
self.eth().map(|cap| cap.eth_version().expect("is eth; qed"))
|
||||
self.iter_caps()
|
||||
.find_map(SharedCapability::eth_version)
|
||||
.ok_or(P2PStreamError::CapabilityNotShared)
|
||||
}
|
||||
|
||||
/// Returns true if the shared capabilities contain the given capability.
|
||||
@ -526,15 +526,13 @@ pub fn shared_capability_offsets(
|
||||
// alphabetic order.
|
||||
let mut offset = MAX_RESERVED_MESSAGE_ID + 1;
|
||||
for name in shared_capability_names {
|
||||
let proto_version = shared_capabilities.get(&name).expect("shared; qed");
|
||||
|
||||
let proto_version = &shared_capabilities[&name];
|
||||
let shared_capability = SharedCapability::new(
|
||||
&name,
|
||||
proto_version.version as u8,
|
||||
offset,
|
||||
proto_version.messages,
|
||||
)?;
|
||||
|
||||
offset += shared_capability.num_messages();
|
||||
shared_with_offsets.push(shared_capability);
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ impl StateFetcher {
|
||||
|
||||
let Some(peer_id) = self.next_peer() else { return PollAction::NoPeersAvailable };
|
||||
|
||||
let request = self.queued_requests.pop_front().expect("not empty; qed");
|
||||
let request = self.queued_requests.pop_front().expect("not empty");
|
||||
let request = self.prepare_block_request(peer_id, request);
|
||||
|
||||
PollAction::Ready(FetchAction::BlockRequest { peer_id, request })
|
||||
|
||||
@ -857,36 +857,39 @@ where
|
||||
NetworkEvent::SessionEstablished {
|
||||
peer_id, client_version, messages, version, ..
|
||||
} => {
|
||||
// insert a new peer into the peerset
|
||||
self.peers.insert(peer_id, Peer::new(messages, version, client_version));
|
||||
// Insert a new peer into the peerset.
|
||||
let peer = Peer::new(messages, version, client_version);
|
||||
let peer = match self.peers.entry(peer_id) {
|
||||
Entry::Occupied(mut entry) => {
|
||||
entry.insert(peer);
|
||||
entry.into_mut()
|
||||
}
|
||||
Entry::Vacant(entry) => entry.insert(peer),
|
||||
};
|
||||
|
||||
// Send a `NewPooledTransactionHashes` to the peer with up to
|
||||
// `NEW_POOLED_TRANSACTION_HASHES_SOFT_LIMIT` transactions in the
|
||||
// pool
|
||||
if !self.network.is_initially_syncing() {
|
||||
if self.network.tx_gossip_disabled() {
|
||||
return
|
||||
}
|
||||
let peer = self.peers.get_mut(&peer_id).expect("is present; qed");
|
||||
|
||||
let mut msg_builder = PooledTransactionsHashesBuilder::new(version);
|
||||
|
||||
let pooled_txs = self.pool.pooled_transactions_max(
|
||||
SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE,
|
||||
);
|
||||
if pooled_txs.is_empty() {
|
||||
// do not send a message if there are no transactions in the pool
|
||||
return
|
||||
}
|
||||
|
||||
for pooled_tx in pooled_txs.into_iter() {
|
||||
peer.seen_transactions.insert(*pooled_tx.hash());
|
||||
msg_builder.push_pooled(pooled_tx);
|
||||
}
|
||||
|
||||
let msg = msg_builder.build();
|
||||
self.network.send_transactions_hashes(peer_id, msg);
|
||||
// `SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE`
|
||||
// transactions in the pool.
|
||||
if self.network.is_initially_syncing() || self.network.tx_gossip_disabled() {
|
||||
return
|
||||
}
|
||||
|
||||
let pooled_txs = self.pool.pooled_transactions_max(
|
||||
SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE,
|
||||
);
|
||||
if pooled_txs.is_empty() {
|
||||
// do not send a message if there are no transactions in the pool
|
||||
return
|
||||
}
|
||||
|
||||
let mut msg_builder = PooledTransactionsHashesBuilder::new(version);
|
||||
for pooled_tx in pooled_txs {
|
||||
peer.seen_transactions.insert(*pooled_tx.hash());
|
||||
msg_builder.push_pooled(pooled_tx);
|
||||
}
|
||||
|
||||
let msg = msg_builder.build();
|
||||
self.network.send_transactions_hashes(peer_id, msg);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user