mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
Fix grumbles from previous GRANDPA PR (#880)
* implement grandpa client * consensus gossip with arbitrary topics * defer GRANDPA messages until referenced blocks imported * set up communication for voter in a transparent way * instantiate GRANDPA voter * keep last round state on disk * switch back to crates.io finality-grandpa * update cargo.lock * use new `collect_garbage` API * update sync test framework and make public * test that observers can observe * fix warning * use more idiomatic predicate for collecting garbage in gossip * kill spaces * fix date * fatal error when unable to complete * rename run_voter to run_grandpa * switch back to crates.io
This commit is contained in:
committed by
GitHub
parent
f851dcf41c
commit
02f8897648
Generated
+3
-3
@@ -602,7 +602,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "finality-grandpa"
|
||||
version = "0.1.3"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"futures 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -2951,7 +2951,7 @@ dependencies = [
|
||||
name = "substrate-finality-grandpa"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"finality-grandpa 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"finality-grandpa 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -4148,7 +4148,7 @@ dependencies = [
|
||||
"checksum failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "946d0e98a50d9831f5d589038d2ca7f8f455b1c21028c0db0e84116a12696426"
|
||||
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||
"checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa"
|
||||
"checksum finality-grandpa 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7c9a8a25e71e4a11a1a5ef36a9ad09b4ae8c4e0bcf27a900137899ac678b01b0"
|
||||
"checksum finality-grandpa 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "20d8cf871510f0d57630e75f9e65f87cba29581ccab1f78666d8b2e422d0baa6"
|
||||
"checksum fixed-hash 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d5ec8112f00ea8a483e04748a85522184418fd1cf02890b626d8fc28683f7de"
|
||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
|
||||
@@ -13,7 +13,7 @@ log = "0.4"
|
||||
tokio = "0.1.7"
|
||||
|
||||
[dependencies.finality-grandpa]
|
||||
version = "0.1.3"
|
||||
version = "0.2.0"
|
||||
features = ["derive-codec"]
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -82,6 +82,8 @@ pub enum Error {
|
||||
Network(String),
|
||||
/// A blockchain error.
|
||||
Blockchain(String),
|
||||
/// Could not complete a round on disk.
|
||||
CouldNotCompleteRound(::client::error::Error),
|
||||
/// A timer failed to fire.
|
||||
Timer(::tokio::timer::Error),
|
||||
}
|
||||
@@ -498,20 +500,27 @@ impl<B, E, Block: BlockT, N> voter::Environment<Block::Hash> for Environment<B,
|
||||
}
|
||||
}
|
||||
|
||||
fn completed(&self, round: u64, state: RoundState<Block::Hash>) {
|
||||
fn completed(&self, round: u64, state: RoundState<Block::Hash>) -> Result<(), Self::Error> {
|
||||
let encoded_state = (round, state).encode();
|
||||
if let Err(e) = self.inner.backend()
|
||||
.insert_aux(&[(LAST_COMPLETED_KEY, &encoded_state[..])], &[])
|
||||
{
|
||||
warn!(target: "afg", "Error bookkeeping last completed round in DB: {:?}", e);
|
||||
warn!(target: "afg", "Shutting down voter due to error bookkeeping last completed round in DB: {:?}", e);
|
||||
Err(Error::CouldNotCompleteRound(e))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn finalize_block(&self, hash: Block::Hash, number: u32) {
|
||||
fn finalize_block(&self, hash: Block::Hash, number: u32) -> Result<(), Self::Error> {
|
||||
// TODO: don't unconditionally notify.
|
||||
if let Err(e) = self.inner.finalize_block(BlockId::Hash(hash), true) {
|
||||
warn!(target: "afg", "Error applying finality to block {:?}: {:?}", (hash, number), e);
|
||||
}
|
||||
|
||||
// we return without error in all cases because not being able to finalize is
|
||||
// non-fatal.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prevote_equivocation(
|
||||
@@ -534,7 +543,7 @@ impl<B, E, Block: BlockT, N> voter::Environment<Block::Hash> for Environment<B,
|
||||
}
|
||||
|
||||
/// Run a GRANDPA voter as a task. The returned future should be executed in a tokio runtime.
|
||||
pub fn run_voter<B, E, Block: BlockT, N>(
|
||||
pub fn run_grandpa<B, E, Block: BlockT, N>(
|
||||
config: Config,
|
||||
client: Arc<Client<B, E, Block>>,
|
||||
voters: HashMap<AuthorityId, usize>,
|
||||
@@ -679,7 +688,7 @@ mod tests {
|
||||
.take_while(|n| Ok(n.header.number() < &20))
|
||||
.for_each(move |_| Ok(()))
|
||||
);
|
||||
let voter = run_voter(
|
||||
let voter = run_grandpa(
|
||||
Config {
|
||||
gossip_duration: TEST_GOSSIP_DURATION,
|
||||
voters: voters.clone(),
|
||||
@@ -738,7 +747,7 @@ mod tests {
|
||||
.take_while(|n| Ok(n.header.number() < &20))
|
||||
.for_each(move |_| Ok(()))
|
||||
);
|
||||
let voter = run_voter(
|
||||
let voter = run_grandpa(
|
||||
Config {
|
||||
gossip_duration: TEST_GOSSIP_DURATION,
|
||||
voters: voters.keys().cloned().collect(),
|
||||
|
||||
Reference in New Issue
Block a user