mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Storing multiple Justifications per block (#7640)
* primitives/runtime: initial changes on supporting multiple Justifications * primitives/runtime: make Justifications strongly typed * Encode/decode Justifications * primitives/runtime: add Justification type * backend: apply_finality and finalize_block takes a single Justification * manual-seal: create engine id and let rpc take encoded justification * backend: skeleton functions for appending justifications * backend: initial implementation append_justification Initial implementation of append_justification on the Backend trait, and also remove unused skeleton functions for append_justificaton on Finaziler trait. k * backend: guard against duplicate consensus engine id * client/db: add check for block finality * client/api: add append_justification to in_mem db * client/light: add no-op append_justification * network: fix decode call for Justification * network: only send a single Justification in BlockData * network: minor comment update * protocol: update field names to distinguish single justification * client: further field renames to plural * client: update function names to plural justifications * client/db: upgrade existing database for new format * network: remove dependency on grandpa crate * db: fix check for finalized block * grandpa: check for multiple grandpa justifications hwne importing * backend: update Finalizer trait to take multiple Justifications * db: remove debugging statements in migration code * manual-seal: update note about engine id * db: fix check for finalized block * client: update variable name to reflect it is now plural * grandpa: fix incorrect empty Justications in test * primitives: make Justifications opaque to avoid being empty * network: fix detecting empty Justification * runtime: doc strings for Justifications functions * runtime: add into_justifications * primitives: check for duplicates in when adding to Justifications * network/test: use real grandpa engine id in test * client: fix reviewer comments * primitives: rename Justifications::push to append * backend: revert changes to Finalizer trait * backend: revert mark_finalized * backend: revert changes to finalize_block * backend: revert finalized_blocks * db: add a quick early return for performance * client: minor reviewer comments * service/test: use local ConsensusEngineId * network: add link to issue for sending multiple Justifications * Apply suggestions from code review Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com> * Apply suggestions from code review Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com> * network: tweaks to review suggestions * network: revert change to BlockData for backwards compatibility * Apply suggestion from code review Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com> * Apply suggestions from code review Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * primitives: update doc comment for Justifications * client/db/upgrade: avoid grandpa crate dependency * consensus: revert to single Justification for import_justification * primitives: improve justifications docs * style cleanups * use and_then * client: rename JUSTIFICATIONS db column * network: revert to using FRNK in network-test Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -28,8 +28,9 @@ use sc_light::{
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, HashFor, NumberFor},
|
||||
generic::BlockId, traits::{Block as _, Header as HeaderT}, Digest,
|
||||
generic::BlockId,
|
||||
traits::{BlakeTwo256, Block as _, HashFor, Header as HeaderT, NumberFor},
|
||||
Digest, Justifications,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use parking_lot::Mutex;
|
||||
@@ -377,7 +378,7 @@ fn execution_proof_is_generated_and_checked() {
|
||||
remote_client.import_justified(
|
||||
BlockOrigin::Own,
|
||||
remote_client.new_block(digest).unwrap().build().unwrap().block,
|
||||
Default::default(),
|
||||
Justifications::from((*b"TEST", Default::default())),
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,9 @@ use sc_client_db::{
|
||||
};
|
||||
use sc_block_builder::BlockBuilderProvider;
|
||||
use sc_service::client::{self, Client, LocalCallExecutor, new_in_mem};
|
||||
use sp_runtime::traits::{
|
||||
BlakeTwo256, Block as BlockT, Header as HeaderT,
|
||||
use sp_runtime::{
|
||||
ConsensusEngineId,
|
||||
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT},
|
||||
};
|
||||
use substrate_test_runtime::TestAPI;
|
||||
use sp_state_machine::backend::Backend as _;
|
||||
@@ -51,12 +52,14 @@ use sp_consensus::{
|
||||
};
|
||||
use sp_storage::StorageKey;
|
||||
use sp_trie::{TrieConfiguration, trie_types::Layout};
|
||||
use sp_runtime::{generic::BlockId, DigestItem};
|
||||
use sp_runtime::{generic::BlockId, DigestItem, Justifications};
|
||||
use hex_literal::hex;
|
||||
|
||||
mod light;
|
||||
mod db;
|
||||
|
||||
const TEST_ENGINE_ID: ConsensusEngineId = *b"TEST";
|
||||
|
||||
native_executor_instance!(
|
||||
Executor,
|
||||
substrate_test_runtime_client::runtime::api::dispatch,
|
||||
@@ -1016,7 +1019,7 @@ fn import_with_justification() {
|
||||
client.import(BlockOrigin::Own, a2.clone()).unwrap();
|
||||
|
||||
// A2 -> A3
|
||||
let justification = vec![1, 2, 3];
|
||||
let justification = Justifications::from((TEST_ENGINE_ID, vec![1, 2, 3]));
|
||||
let a3 = client.new_block_at(
|
||||
&BlockId::Hash(a2.hash()),
|
||||
Default::default(),
|
||||
@@ -1030,17 +1033,17 @@ fn import_with_justification() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
client.justification(&BlockId::Hash(a3.hash())).unwrap(),
|
||||
client.justifications(&BlockId::Hash(a3.hash())).unwrap(),
|
||||
Some(justification),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
client.justification(&BlockId::Hash(a1.hash())).unwrap(),
|
||||
client.justifications(&BlockId::Hash(a1.hash())).unwrap(),
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
client.justification(&BlockId::Hash(a2.hash())).unwrap(),
|
||||
client.justifications(&BlockId::Hash(a2.hash())).unwrap(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
@@ -1088,7 +1091,7 @@ fn importing_diverged_finalized_block_should_trigger_reorg() {
|
||||
);
|
||||
|
||||
// importing B1 as finalized should trigger a re-org and set it as new best
|
||||
let justification = vec![1, 2, 3];
|
||||
let justification = Justifications::from((TEST_ENGINE_ID, vec![1, 2, 3]));
|
||||
client.import_justified(BlockOrigin::Own, b1.clone(), justification).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user