Skip to content

Commit

Permalink
Add aura finalize
Browse files Browse the repository at this point in the history
Add get_finalized_info in client
  • Loading branch information
gguoss authored and atenjin committed Jun 17, 2019
1 parent d291161 commit 2e3bb96
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 152 deletions.
7 changes: 4 additions & 3 deletions core/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
};
last_number = Some(best_number);
let txpool_status = txpool.status();
let finalized_number: u64 = info.chain.finalized_number.as_();
let (finalized_number, finalized_hash) = client.get_finalized_info(best_hash);
let finalized_number: u64 = finalized_number.as_();
let bandwidth_download = network.average_download_per_sec();
let bandwidth_upload = network.average_upload_per_sec();
info!(
Expand All @@ -71,7 +72,7 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
Colour::White.paint(format!("{}", best_number)),
best_hash,
Colour::White.paint(format!("{}", finalized_number)),
info.chain.finalized_hash,
finalized_hash.clone().unwrap_or_default(),
TransferRateFormat(bandwidth_download),
TransferRateFormat(bandwidth_upload),
);
Expand Down Expand Up @@ -102,7 +103,7 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
"cpu" => cpu_usage,
"memory" => memory,
"finalized_height" => finalized_number,
"finalized_hash" => ?info.chain.finalized_hash,
"finalized_hash" => ?finalized_hash.unwrap_or_default(),
"bandwidth_download" => bandwidth_download,
"bandwidth_upload" => bandwidth_upload,
"used_state_cache_size" => used_state_cache_size,
Expand Down
11 changes: 11 additions & 0 deletions core/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,17 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
result
}

pub fn get_finalized_info(&self, hash: Block::Hash) -> (NumberFor<Block>, Option<Block::Hash>) {
let finalized_number = match self.storage(&BlockId::Hash(hash),
&StorageKey(well_known_keys::AURA_FINALIZE.to_vec())) {
Ok(Some(number)) => Decode::decode(&mut number.0.as_slice()).unwrap_or(NumberFor::<Block>::zero()),
_ => NumberFor::<Block>::zero(),
};
let finalized_hash = self.block_hash(finalized_number).unwrap_or(None);

(finalized_number, finalized_hash)
}

fn execute_and_import_block(
&self,
operation: &mut ClientImportOperation<Block, Blake2Hasher, B>,
Expand Down
5 changes: 3 additions & 2 deletions core/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,14 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
GenericMessage::FinalityProofResponse(response) =>
return self.on_finality_proof_response(network_out, who, response),
GenericMessage::Consensus(msg) => {
if self.context_data.peers.get(&who).map_or(false, |peer| peer.info.protocol_version > 2) {
debug!(target: "gossip", "---Received Consensus message---");
/*if self.context_data.peers.get(&who).map_or(false, |peer| peer.info.protocol_version > 2) {
self.consensus_gossip.on_incoming(
&mut ProtocolContext::new(&mut self.context_data, network_out),
who,
msg,
);
}
}*/
}
other => self.specialization.on_message(
&mut ProtocolContext::new(&mut self.context_data, network_out),
Expand Down
3 changes: 3 additions & 0 deletions core/primitives/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub mod well_known_keys {
/// The type of this value is encoded `u32`.
pub const MAX_EXTRINSICS_COUNT: &'static [u8] = b":max_extrinsics_count";

/// aura DPOS finalize.
pub const AURA_FINALIZE: &'static [u8] = b":aura_finalize";

/// Whether a key is a child storage key.
///
/// This is convenience function which basically checks if the given `key` starts
Expand Down
Loading

0 comments on commit 2e3bb96

Please sign in to comment.