mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 18:37:59 +00:00
Remove on_block_imported (#6039)
* remove on_block_imported * Update client/network/src/service.rs Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com> Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
@@ -111,7 +111,7 @@ mod rep {
|
||||
/// reputation change should be refunded with `ANY_EXTRINSIC_REFUND`
|
||||
pub const ANY_EXTRINSIC: Rep = Rep::new(-(1 << 4), "Any extrinsic");
|
||||
/// Reputation change when a peer sends us any extrinsic that is not invalid.
|
||||
pub const ANY_EXTRINSIC_REFUND: Rep = Rep::new(1 << 4, "Any extrinsic (refund)");
|
||||
pub const ANY_EXTRINSIC_REFUND: Rep = Rep::new(1 << 4, "Any extrinsic (refund)");
|
||||
/// Reputation change when a peer sends us an extrinsic that we didn't know about.
|
||||
pub const GOOD_EXTRINSIC: Rep = Rep::new(1 << 7, "Good extrinsic");
|
||||
/// Reputation change when a peer sends us a bad extrinsic.
|
||||
@@ -535,6 +535,12 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
||||
self.sync.num_sync_requests()
|
||||
}
|
||||
|
||||
/// Sync local state with the blockchain state.
|
||||
pub fn update_chain(&mut self) {
|
||||
let info = self.context_data.chain.info();
|
||||
self.sync.update_chain_info(&info.best_hash, info.best_number);
|
||||
}
|
||||
|
||||
/// Accepts a response from the legacy substream and determines what the corresponding
|
||||
/// request was.
|
||||
fn handle_response(
|
||||
@@ -1419,17 +1425,6 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Call this when a block has been imported in the import queue
|
||||
pub fn on_block_imported(&mut self, header: &B::Header, is_best: bool) {
|
||||
if is_best {
|
||||
self.sync.update_chain_info(header);
|
||||
self.behaviour.set_notif_protocol_handshake(
|
||||
&self.block_announces_protocol,
|
||||
BlockAnnouncesHandshake::build(&self.config, &self.context_data.chain).encode()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Call this when a block has been finalized. The sync layer may have some additional
|
||||
/// requesting to perform.
|
||||
pub fn on_block_finalized(&mut self, hash: B::Hash, header: &B::Header) {
|
||||
@@ -1494,12 +1489,23 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
||||
/// A batch of blocks have been processed, with or without errors.
|
||||
/// Call this when a batch of blocks have been processed by the importqueue, with or without
|
||||
/// errors.
|
||||
pub fn blocks_processed(
|
||||
pub fn on_blocks_processed(
|
||||
&mut self,
|
||||
imported: usize,
|
||||
count: usize,
|
||||
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>
|
||||
) {
|
||||
let new_best = results.iter().rev().find_map(|r| match r {
|
||||
(Ok(BlockImportResult::ImportedUnknown(n, aux, _)), hash) if aux.is_new_best => Some((*n, hash.clone())),
|
||||
_ => None,
|
||||
});
|
||||
if let Some((best_num, best_hash)) = new_best {
|
||||
self.sync.update_chain_info(&best_hash, best_num);
|
||||
self.behaviour.set_notif_protocol_handshake(
|
||||
&self.block_announces_protocol,
|
||||
BlockAnnouncesHandshake::build(&self.config, &self.context_data.chain).encode()
|
||||
);
|
||||
}
|
||||
let results = self.sync.on_blocks_processed(
|
||||
imported,
|
||||
count,
|
||||
|
||||
Reference in New Issue
Block a user