mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-28 11:01:14 +00:00
e779eeb2ec
* core: make block justification optional * runtime: update wasm binaries * core: optionally pass justification on finalize_block * finality-grandpa: add channel to trigger authority set changes this will allow the `BlockImport` to trigger an authority set change when importing a change block that provides a justification (when syncing) * finality-grandpa: move finalize_block to free function * finality-grandpa: add GrandpaOracle for auth set liveness checking this will be used by `BlockImport` to check whether the authority set for a given block is still live, if the authority set isn't live then importing a change block requires a justification. * finality-grandpa: store justification on finalized transition blocks * finality-grandpa: check justification on authority set change blocks * finality-grandpa: poll grandpa liveness oracle every 10 seconds * finality-grandpa: spawn grandpa oracle in service setup * core: support multiple subscriptions per consensus gossip topic * finality-grandpa: create and verify justifications * finality-grandpa: update to local branch of grandpa * finality-grandpa: update to finality-grandpa v0.5.0 * finality-grandpa: move grandpa oracle code * finality-grandpa: fix canonality check * finality-grandpa: clean up error handling * finality-grandpa: fix canonical_at_height * finality-grandpa: fix tests * runtime: update wasm binaries * core: add tests for finalizing block with justification * finality-grandpa: improve validation of justifications * core: remove unused IncompleteJustification block import error * core: test multiple subscribers for same consensus gossip topic * Revert "finality-grandpa: improve validation of justifications" This reverts commit 51eb2c58c2219801e876af6d6c9371bdd9ff2477. * finality-grandpa: fix commit validation * finality-grandpa: fix commit ancestry validation * finality-grandpa: use grandpa v0.5.1 * finality-grandpa: add docs * finality-grandpa: fix failing test * finality-grandpa: only allow a pending authority set change per fork * finality-grandpa: fix validator set transition test
89 lines
2.8 KiB
Rust
89 lines
2.8 KiB
Rust
// Copyright 2018 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Client extension for tests.
|
|
|
|
use client::{self, Client};
|
|
use consensus::{ImportBlock, BlockImport, BlockOrigin};
|
|
use runtime_primitives::Justification;
|
|
use runtime_primitives::generic::BlockId;
|
|
use primitives::Blake2Hasher;
|
|
use runtime;
|
|
|
|
/// Extension trait for a test client.
|
|
pub trait TestClient: Sized {
|
|
/// Import block to the chain. No finality.
|
|
fn import(&self, origin: BlockOrigin, block: runtime::Block)
|
|
-> client::error::Result<()>;
|
|
|
|
/// Import block with justification, finalizes block.
|
|
fn import_justified(&self, origin: BlockOrigin, block: runtime::Block, justification: Justification)
|
|
-> client::error::Result<()>;
|
|
|
|
/// Finalize a block.
|
|
fn finalize_block(&self, id: BlockId<runtime::Block>, justification: Option<Justification>) -> client::error::Result<()>;
|
|
|
|
/// Returns hash of the genesis block.
|
|
fn genesis_hash(&self) -> runtime::Hash;
|
|
}
|
|
|
|
impl<B, E, RA> TestClient for Client<B, E, runtime::Block, RA>
|
|
where
|
|
B: client::backend::Backend<runtime::Block, Blake2Hasher>,
|
|
E: client::CallExecutor<runtime::Block, Blake2Hasher>,
|
|
Self: BlockImport<runtime::Block, Error=client::error::Error>,
|
|
{
|
|
fn import(&self, origin: BlockOrigin, block: runtime::Block)
|
|
-> client::error::Result<()>
|
|
{
|
|
let import = ImportBlock {
|
|
origin,
|
|
header: block.header,
|
|
justification: None,
|
|
post_digests: vec![],
|
|
body: Some(block.extrinsics),
|
|
finalized: false,
|
|
auxiliary: Vec::new(),
|
|
};
|
|
|
|
self.import_block(import, None).map(|_| ())
|
|
}
|
|
|
|
fn import_justified(&self, origin: BlockOrigin, block: runtime::Block, justification: Justification)
|
|
-> client::error::Result<()>
|
|
{
|
|
let import = ImportBlock {
|
|
origin,
|
|
header: block.header,
|
|
justification: Some(justification),
|
|
post_digests: vec![],
|
|
body: Some(block.extrinsics),
|
|
finalized: true,
|
|
auxiliary: Vec::new(),
|
|
};
|
|
|
|
self.import_block(import, None).map(|_| ())
|
|
}
|
|
|
|
fn finalize_block(&self, id: BlockId<runtime::Block>, justification: Option<Justification>) -> client::error::Result<()> {
|
|
self.finalize_block(id, justification, true)
|
|
}
|
|
|
|
fn genesis_hash(&self) -> runtime::Hash {
|
|
self.block_hash(0).unwrap().unwrap()
|
|
}
|
|
}
|