diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 904b59b8a2..96fe0e2871 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -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" diff --git a/substrate/core/finality-grandpa/Cargo.toml b/substrate/core/finality-grandpa/Cargo.toml index ea8880137d..cc269f68a3 100644 --- a/substrate/core/finality-grandpa/Cargo.toml +++ b/substrate/core/finality-grandpa/Cargo.toml @@ -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] diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index f66eabe7fe..795bcdb9a6 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -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 voter::Environment for Environment) { + fn completed(&self, round: u64, state: RoundState) -> 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 voter::Environment for Environment( +pub fn run_grandpa( config: Config, client: Arc>, voters: HashMap, @@ -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(),