update Substrate/Polkadot/Cumulus refs (#1562)

* update Substrate/Polkadot/Cumulus refs

* finality-grandpa 0.16

* fix miillau-runtime compilation

* fix rialto runtime compilation

* fixed rialto-parachain runtime compilation

* backport GRANDPA test fixes

* helper instead of removed record_all_keys

* substrate-relay is compiling

* millau-bridge-node at least compiles

* rialto-bridge-node at least compiles

* rialto-parachain-collator compiles

* fixings tests (wip)

* fmt

* fixed BEEFY alert

* clippy

* removed unused dep

* -extra var

* move Leaf to mod mmr

* fix benchmarks
This commit is contained in:
Svyatoslav Nikolsky
2022-09-09 10:56:39 +03:00
committed by Bastian Köcher
parent ad38cdb873
commit 95c30c780c
32 changed files with 416 additions and 292 deletions
+1 -2
View File
@@ -8,7 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
finality-grandpa = { version = "0.15.0", default-features = false }
finality-grandpa = { version = "0.16.0", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true }
@@ -25,7 +25,6 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
[dev-dependencies]
assert_matches = "1.5"
bp-test-utils = { path = "../test-utils" }
hex = "0.4"
hex-literal = "0.3"
@@ -20,7 +20,6 @@
//! Some of tests in this module may partially duplicate tests from `justification.rs`,
//! but their purpose is different.
use assert_matches::assert_matches;
use bp_header_chain::justification::{verify_justification, Error, GrandpaJustification};
use bp_test_utils::{
header_id, make_justification_for_header, signed_precommit, test_header, Account,
@@ -106,7 +105,7 @@ pub fn make_default_justification(header: &TestHeader) -> GrandpaJustification<T
//
// 1) to return `Err()` (which only may happen if `finality_grandpa::Chain` implementation
// returns an error);
// 2) to return `Ok(validation_result) if validation_result.ghost().is_none()`.
// 2) to return `Ok(validation_result)` if `validation_result.is_valid()` is false.
//
// Our implementation would just return error in both cases.
@@ -126,16 +125,17 @@ fn same_result_when_precommit_target_has_lower_number_than_commit_target() {
),
Err(Error::PrecommitIsNotCommitDescendant),
);
// original implementation returns empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(None)
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == false`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(!result.is_valid());
}
#[test]
@@ -158,21 +158,27 @@ fn same_result_when_precommit_target_is_not_descendant_of_commit_target() {
),
Err(Error::PrecommitIsNotCommitDescendant),
);
// original implementation returns empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(None)
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == false`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(!result.is_valid());
}
#[test]
fn same_result_when_justification_contains_duplicate_vote() {
let mut justification = make_default_justification(&test_header(1));
let mut justification = make_justification_for_header(JustificationGeneratorParams {
header: test_header(1),
authorities: minimal_accounts_set(),
ancestors: 0,
..Default::default()
});
// the justification may contain exactly the same vote (i.e. same precommit and same signature)
// multiple times && it isn't treated as an error by original implementation
justification.commit.precommits.push(justification.commit.precommits[0].clone());
@@ -188,21 +194,26 @@ fn same_result_when_justification_contains_duplicate_vote() {
),
Ok(()),
);
// original implementation returns non-empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(Some(_))
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == true`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(result.is_valid());
}
#[test]
fn same_result_when_authority_equivocates_once_in_a_round() {
let mut justification = make_default_justification(&test_header(1));
let mut justification = make_justification_for_header(JustificationGeneratorParams {
header: test_header(1),
authorities: minimal_accounts_set(),
ancestors: 0,
..Default::default()
});
// the justification original implementation allows authority to submit two different
// votes in a single round, of which only first is 'accepted'
justification.commit.precommits.push(signed_precommit::<TestHeader>(
@@ -222,21 +233,26 @@ fn same_result_when_authority_equivocates_once_in_a_round() {
),
Ok(()),
);
// original implementation returns non-empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(Some(_))
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == true`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(result.is_valid());
}
#[test]
fn same_result_when_authority_equivocates_twice_in_a_round() {
let mut justification = make_default_justification(&test_header(1));
let mut justification = make_justification_for_header(JustificationGeneratorParams {
header: test_header(1),
authorities: minimal_accounts_set(),
ancestors: 0,
..Default::default()
});
// there's some code in the original implementation that should return an error when
// same authority submits more than two different votes in a single round:
// https://github.com/paritytech/finality-grandpa/blob/6aeea2d1159d0f418f0b86e70739f2130629ca09/src/lib.rs#L473
@@ -266,16 +282,16 @@ fn same_result_when_authority_equivocates_twice_in_a_round() {
),
Ok(()),
);
// original implementation returns non-empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(Some(_))
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == true`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(result.is_valid());
}
#[test]
@@ -299,14 +315,14 @@ fn same_result_when_there_are_not_enough_cumulative_weight_to_finalize_commit_ta
),
Err(Error::TooLowCumulativeWeight),
);
// original implementation returns empty GHOST
assert_matches!(
finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.map(|result| result.ghost().cloned()),
Ok(None)
);
// original implementation returns `Ok(validation_result)`
// with `validation_result.is_valid() == false`.
let result = finality_grandpa::validate_commit(
&justification.commit,
&full_voter_set(),
&AncestryChain::new(&justification.votes_ancestries),
)
.unwrap();
assert!(!result.is_valid());
}
+2
View File
@@ -23,6 +23,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
trie-db = { version = "0.24.0", default-features = false }
[dev-dependencies]
hex-literal = "0.3"
@@ -43,4 +44,5 @@ std = [
"sp-std/std",
"sp-state-machine/std",
"sp-trie/std",
"trie-db/std",
]
+2 -1
View File
@@ -37,7 +37,8 @@ pub use frame_support::storage::storage_prefix as storage_value_final_key;
use num_traits::{CheckedSub, One};
use sp_runtime::transaction_validity::TransactionValidity;
pub use storage_proof::{
Error as StorageProofError, ProofSize as StorageProofSize, StorageProofChecker,
record_all_keys as record_all_trie_keys, Error as StorageProofError,
ProofSize as StorageProofSize, StorageProofChecker,
};
#[cfg(feature = "std")]
@@ -19,8 +19,11 @@
use codec::Decode;
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use sp_runtime::RuntimeDebug;
use sp_std::vec::Vec;
use sp_trie::{read_trie_value, LayoutV1, MemoryDB, StorageProof};
use sp_std::{boxed::Box, vec::Vec};
use sp_trie::{
read_trie_value, LayoutV1, MemoryDB, Recorder, StorageProof, Trie, TrieConfiguration,
TrieDBBuilder, TrieError, TrieHash,
};
/// Storage proof size requirements.
///
@@ -70,7 +73,7 @@ where
/// incomplete or otherwise invalid proof, this function returns an error.
pub fn read_value(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
// LayoutV1 or LayoutV0 is identical for proof that only read values.
read_trie_value::<LayoutV1<H>, _>(&self.db, &self.root, key)
read_trie_value::<LayoutV1<H>, _>(&self.db, &self.root, key, None, None)
.map_err(|_| Error::StorageValueUnavailable)
}
@@ -124,6 +127,24 @@ pub fn craft_valid_storage_proof() -> (sp_core::H256, StorageProof) {
(root, proof)
}
/// Record all keys for a given root.
pub fn record_all_keys<L: TrieConfiguration, DB>(
db: &DB,
root: &TrieHash<L>,
recorder: &mut Recorder<L>,
) -> Result<(), Box<TrieError<L>>>
where
DB: hash_db::HashDBRef<L::Hash, trie_db::DBValue>,
{
let trie = TrieDBBuilder::<L>::new(db, root).with_recorder(recorder).build();
for x in trie.iter()? {
let (key, _) = x?;
trie.get(&key)?;
}
Ok(())
}
#[cfg(test)]
pub mod tests {
use super::*;
+1 -1
View File
@@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
bp-header-chain = { path = "../header-chain", default-features = false }
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"] }
finality-grandpa = { version = "0.15.0", default-features = false }
finality-grandpa = { version = "0.16.0", default-features = false }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }