Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
b1561e7
primitives/runtime: initial changes on supporting multiple Justificat…
octol Nov 19, 2020
16bfd2c
primitives/runtime: make Justifications strongly typed
octol Nov 30, 2020
d72b5eb
Encode/decode Justifications
octol Nov 30, 2020
88d1e1a
primitives/runtime: add Justification type
octol Dec 1, 2020
12f8f7e
backend: apply_finality and finalize_block takes a single Justification
octol Dec 2, 2020
75dc977
manual-seal: create engine id and let rpc take encoded justification
octol Dec 2, 2020
9920319
backend: skeleton functions for appending justifications
octol Dec 2, 2020
1f7f2d1
backend: initial implementation append_justification
octol Dec 10, 2020
523038a
backend: guard against duplicate consensus engine id
octol Dec 11, 2020
52a0dff
client/db: add check for block finality
octol Dec 14, 2020
a25d33d
client/api: add append_justification to in_mem db
octol Dec 14, 2020
f023cca
client/light: add no-op append_justification
octol Dec 15, 2020
2a6e9cd
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Dec 15, 2020
46b4584
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Jan 7, 2021
544c8e2
network: fix decode call for Justification
octol Jan 14, 2021
6aabece
network: only send a single Justification in BlockData
octol Jan 14, 2021
10e9f22
network: minor comment update
octol Jan 14, 2021
3613fdb
protocol: update field names to distinguish single justification
octol Jan 14, 2021
ce5dad9
client: further field renames to plural
octol Jan 14, 2021
b0f9b5c
client: update function names to plural justifications
octol Jan 14, 2021
4dc856e
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Jan 14, 2021
2e23810
client/db: upgrade existing database for new format
octol Jan 19, 2021
66b2c4e
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Jan 20, 2021
0b69a39
network: remove dependency on grandpa crate
octol Jan 29, 2021
b91f821
db: fix check for finalized block
octol Jan 29, 2021
9301c86
grandpa: check for multiple grandpa justifications hwne importing
octol Jan 29, 2021
63291b5
backend: update Finalizer trait to take multiple Justifications
octol Feb 1, 2021
206447c
db: remove debugging statements in migration code
octol Feb 1, 2021
4185aa5
manual-seal: update note about engine id
octol Feb 1, 2021
d0adabb
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Feb 1, 2021
5cae4b1
db: fix check for finalized block
octol Feb 1, 2021
1d7e50b
client: update variable name to reflect it is now plural
octol Feb 10, 2021
4d1ed93
grandpa: fix incorrect empty Justications in test
octol Feb 10, 2021
a0cb5e3
primitives: make Justifications opaque to avoid being empty
octol Feb 11, 2021
c32e538
network: fix detecting empty Justification
octol Feb 11, 2021
2545ed2
runtime: doc strings for Justifications functions
octol Feb 12, 2021
45f9e20
runtime: add into_justifications
octol Feb 12, 2021
47bda20
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Feb 12, 2021
b65b38a
primitives: check for duplicates in when adding to Justifications
octol Feb 16, 2021
c69833e
network/test: use real grandpa engine id in test
octol Feb 16, 2021
1019de3
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Feb 16, 2021
8391a9d
client: fix reviewer comments
octol Feb 16, 2021
c9cc2c8
primitives: rename Justifications::push to append
octol Feb 16, 2021
7bbc156
backend: revert changes to Finalizer trait
octol Feb 22, 2021
a42122b
backend: revert mark_finalized
octol Feb 22, 2021
356176f
backend: revert changes to finalize_block
octol Feb 22, 2021
609bbe0
backend: revert finalized_blocks
octol Feb 22, 2021
037e0a4
db: add a quick early return for performance
octol Feb 22, 2021
c5fe8f2
client: minor reviewer comments
octol Feb 22, 2021
5c4a735
service/test: use local ConsensusEngineId
octol Feb 22, 2021
693757f
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Feb 22, 2021
1667e41
network: add link to issue for sending multiple Justifications
octol Feb 22, 2021
d7ea7bd
Apply suggestions from code review
octol Feb 23, 2021
87cf0d3
Apply suggestions from code review
octol Feb 23, 2021
b266679
network: tweaks to review suggestions
octol Feb 23, 2021
7f8e0b3
network: revert change to BlockData for backwards compatibility
octol Feb 24, 2021
ad05998
Apply suggestion from code review
octol Feb 24, 2021
bcc69ce
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Feb 24, 2021
3af1962
Apply suggestions from code review
octol Feb 25, 2021
3f5e07c
primitives: update doc comment for Justifications
octol Feb 26, 2021
a829791
client/db/upgrade: avoid grandpa crate dependency
octol Feb 26, 2021
dda0b2d
consensus: revert to single Justification for import_justification
octol Mar 1, 2021
711984f
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Mar 1, 2021
9a2ba3c
Merge branch 'master' into jon/store-multiple-justifications
andresilva Mar 15, 2021
e405ce9
primitives: improve justifications docs
andresilva Mar 15, 2021
aaac8c5
style cleanups
andresilva Mar 15, 2021
3e4443f
use and_then
andresilva Mar 15, 2021
340e092
client: rename JUSTIFICATIONS db column
andresilva Mar 15, 2021
5c5449e
network: revert to using FRNK in network-test
octol Mar 16, 2021
c338058
Merge remote-tracking branch 'upstream/master' into jon/store-multipl…
octol Mar 16, 2021
ed93ea0
Merge branch 'master' into jon/store-multiple-justifications
andresilva Mar 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
primitives/runtime: make Justifications strongly typed
  • Loading branch information
octol committed Nov 30, 2020
commit 16bfd2c6d3ed608b7b97ede589e03c53d0ec219b
5 changes: 3 additions & 2 deletions client/db/src/changes_tries_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ mod tests {
use sp_blockchain::HeaderBackend as BlockchainHeaderBackend;
use sp_core::H256;
use sp_finality_grandpa::GRANDPA_ENGINE_ID;
use sp_runtime::testing::{Digest, Header};
use sp_runtime::{Justifications, testing::{Digest, Header}};
use sp_runtime::traits::{Hash, BlakeTwo256};
use sp_state_machine::{ChangesTrieRootsStorage, ChangesTrieStorage};
use crate::Backend;
Expand Down Expand Up @@ -954,7 +954,8 @@ mod tests {
let block0 = insert_header_with_configuration_change(&backend, 0, Default::default(), None, config0);
let config1 = Some(ChangesTrieConfiguration::new(2, 6));
let block1 = insert_header_with_configuration_change(&backend, 1, block0, changes(0), config1);
backend.finalize_block(BlockId::Number(1), Some(vec![(GRANDPA_ENGINE_ID, vec![42])])).unwrap();
let just1 = Some(Justifications(vec![(GRANDPA_ENGINE_ID, vec![42])]));
backend.finalize_block(BlockId::Number(1), just1).unwrap();
let config2 = Some(ChangesTrieConfiguration::new(2, 7));
let block2 = insert_header_with_configuration_change(&backend, 2, block1, changes(1), config2);
let config2_1 = Some(ChangesTrieConfiguration::new(2, 8));
Expand Down
3 changes: 2 additions & 1 deletion client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,7 @@ pub(crate) mod tests {
use sp_runtime::generic::DigestItem;
use sp_state_machine::{TrieMut, TrieDBMut};
use sp_blockchain::{lowest_common_ancestor, tree_route};
use sp_finality_grandpa::GRANDPA_ENGINE_ID;

pub(crate) type Block = RawBlock<ExtrinsicWrapper<u64>>;

Expand Down Expand Up @@ -2354,7 +2355,7 @@ pub(crate) mod tests {
let block0 = insert_header(&backend, 0, Default::default(), None, Default::default());
let _ = insert_header(&backend, 1, block0, None, Default::default());

let justification = Some(vec![(sp_finality_grandpa::GRANDPA_ENGINE_ID, vec![1, 2, 3])]);
let justification = Some(Justifications(vec![(GRANDPA_ENGINE_ID, vec![1, 2, 3])]));
backend.finalize_block(BlockId::Number(1), justification.clone()).unwrap();

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion client/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ where

// ideally some handle to a synchronization oracle would be used
// to avoid unconditionally notifying.
let justification = justification.map(|j| vec![(GRANDPA_ENGINE_ID, j.clone())]);
let justification = justification.map(|j| sp_runtime::Justifications(vec![(GRANDPA_ENGINE_ID, j.clone())]));
client
.apply_finality(import_op, BlockId::Hash(hash), justification, true)
.map_err(|e| {
Expand Down
54 changes: 33 additions & 21 deletions client/finality-grandpa/src/finality_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub(crate) fn prove_finality<Block: BlockT, B: BlockchainBackend<Block>, J>(
}

if let Some(justification) = blockchain.justification(current_id)? {
if let Some((_, grandpa_justification)) = justification.into_iter().find(|j| j.0 == GRANDPA_ENGINE_ID) {
if let Some((_, grandpa_justification)) = justification.0.into_iter().find(|j| j.0 == GRANDPA_ENGINE_ID) {
// check if the current block enacts new GRANDPA authorities set
let new_authorities = authorities_provider.authorities(&current_id)?;
let new_authorities_proof = if current_authorities != new_authorities {
Expand Down Expand Up @@ -594,6 +594,7 @@ pub(crate) mod tests {
use sc_client_api::in_mem::Blockchain as InMemoryBlockchain;
use super::*;
use sp_core::crypto::Public;
use sp_runtime::Justifications;

pub(crate) type FinalityProof = super::FinalityProof<Header>;

Expand Down Expand Up @@ -671,10 +672,14 @@ pub(crate) mod tests {
fn test_blockchain() -> InMemoryBlockchain<Block> {
use sp_finality_grandpa::GRANDPA_ENGINE_ID as ID;
let blockchain = InMemoryBlockchain::<Block>::new();
blockchain.insert(header(0).hash(), header(0), Some(vec![(ID, vec![0])]), None, NewBlockState::Final).unwrap();
blockchain.insert(header(1).hash(), header(1), Some(vec![(ID, vec![1])]), None, NewBlockState::Final).unwrap();
blockchain.insert(header(2).hash(), header(2), None, None, NewBlockState::Best).unwrap();
blockchain.insert(header(3).hash(), header(3), Some(vec![(ID, vec![3])]), None, NewBlockState::Final).unwrap();
let just0 = Some(Justifications(vec![(ID, vec![0])]));
let just1 = Some(Justifications(vec![(ID, vec![1])]));
let just2 = None;
let just3 = Some(Justifications(vec![(ID, vec![3])]));
blockchain.insert(header(0).hash(), header(0), just0, None, NewBlockState::Final).unwrap();
blockchain.insert(header(1).hash(), header(1), just1, None, NewBlockState::Final).unwrap();
blockchain.insert(header(2).hash(), header(2), just2, None, NewBlockState::Best).unwrap();
blockchain.insert(header(3).hash(), header(3), just3, None, NewBlockState::Final).unwrap();
blockchain
}

Expand Down Expand Up @@ -726,7 +731,8 @@ pub(crate) mod tests {
blockchain.insert(side_header(4).hash(), side_header(4), None, None, NewBlockState::Best).unwrap();
blockchain.insert(second_side_header(5).hash(), second_side_header(5), None, None, NewBlockState::Best)
.unwrap();
blockchain.insert(header(5).hash(), header(5), Some(vec![(ID, vec![5])]), None, NewBlockState::Final).unwrap();
let just = Some(Justifications(vec![(ID, vec![5])]));
blockchain.insert(header(5).hash(), header(5), just, None, NewBlockState::Final).unwrap();

// chain is 1 -> 2 -> 3 -> 4 -> 5
// \> 4' -> 5'
Expand Down Expand Up @@ -769,10 +775,12 @@ pub(crate) mod tests {
use sp_finality_grandpa::GRANDPA_ENGINE_ID as ID;
let blockchain = test_blockchain();
let authorities = vec![(AuthorityId::from_slice(&[1u8; 32]), 1u64)];
let just4 = TestJustification((0, authorities.clone()), vec![4]).encode();
let just5 = TestJustification((0, authorities.clone()), vec![5]).encode();
blockchain.insert(header(4).hash(), header(4), Some(vec![(ID, just4)]), None, NewBlockState::Final).unwrap();
blockchain.insert(header(5).hash(), header(5), Some(vec![(ID, just5.clone())]), None, NewBlockState::Final).unwrap();
let just4_grandpa = TestJustification((0, authorities.clone()), vec![4]).encode();
let just4 = Justifications(vec![(ID, just4_grandpa)]);
let just5_grandpa = TestJustification((0, authorities.clone()), vec![5]).encode();
let just5 = Justifications(vec![(ID, just5_grandpa.clone())]);
blockchain.insert(header(4).hash(), header(4), Some(just4), None, NewBlockState::Final).unwrap();
blockchain.insert(header(5).hash(), header(5), Some(just5), None, NewBlockState::Final).unwrap();

// blocks 4 && 5 are finalized with justification
// => since authorities are the same, we only need justification for 5
Expand All @@ -788,7 +796,7 @@ pub(crate) mod tests {
).unwrap().unwrap()[..]).unwrap();
assert_eq!(proof_of_5, vec![FinalityProofFragment {
block: header(5).hash(),
justification: just5,
justification: just5_grandpa,
unknown_headers: Vec::new(),
authorities_proof: None,
}]);
Expand All @@ -798,7 +806,7 @@ pub(crate) mod tests {
fn finality_proof_finalized_earlier_block_if_no_justification_for_target_is_known() {
use sp_finality_grandpa::GRANDPA_ENGINE_ID as ID;
let blockchain = test_blockchain();
blockchain.insert(header(4).hash(), header(4), Some(vec![(ID, vec![4])]), None, NewBlockState::Final).unwrap();
blockchain.insert(header(4).hash(), header(4), Some(Justifications(vec![(ID, vec![4])])), None, NewBlockState::Final).unwrap();
blockchain.insert(header(5).hash(), header(5), None, None, NewBlockState::Final).unwrap();

// block 4 is finalized with justification + we request for finality of 5
Expand Down Expand Up @@ -828,13 +836,16 @@ pub(crate) mod tests {
let auth3 = vec![(AuthorityId::from_slice(&[3u8; 32]), 1u64)];
let auth5 = vec![(AuthorityId::from_slice(&[5u8; 32]), 1u64)];
let auth7 = vec![(AuthorityId::from_slice(&[7u8; 32]), 1u64)];
let just4 = TestJustification((0, auth3.clone()), vec![4]).encode();
let just5 = TestJustification((0, auth3.clone()), vec![5]).encode();
let just7 = TestJustification((1, auth5.clone()), vec![7]).encode();
blockchain.insert(header(4).hash(), header(4), Some(vec![(ID, just4)]), None, NewBlockState::Final).unwrap();
blockchain.insert(header(5).hash(), header(5), Some(vec![(ID, just5.clone())]), None, NewBlockState::Final).unwrap();
let just4_grandpa = TestJustification((0, auth3.clone()), vec![4]).encode();
let just4 = Some(Justifications(vec![(ID, just4_grandpa)]));
let just5_grandpa = TestJustification((0, auth3.clone()), vec![5]).encode();
let just5 = Some(Justifications(vec![(ID, just5_grandpa.clone())]));
let just7_grandpa = TestJustification((1, auth5.clone()), vec![7]).encode();
let just7 = Some(Justifications(vec![(ID, just7_grandpa.clone())]));
blockchain.insert(header(4).hash(), header(4), just4, None, NewBlockState::Final).unwrap();
blockchain.insert(header(5).hash(), header(5), just5.clone(), None, NewBlockState::Final).unwrap();
blockchain.insert(header(6).hash(), header(6), None, None, NewBlockState::Final).unwrap();
blockchain.insert(header(7).hash(), header(7), Some(vec![(ID, just7.clone())]), None, NewBlockState::Final).unwrap();
blockchain.insert(header(7).hash(), header(7), just7, None, NewBlockState::Final).unwrap();

// when querying for finality of 6, we assume that the #3 is the last block known to the requester
// => since we only have justification for #7, we provide #7
Expand Down Expand Up @@ -864,14 +875,14 @@ pub(crate) mod tests {
// first fragment provides justification for #5 && authorities set that starts acting from #5
FinalityProofFragment {
block: header(5).hash(),
justification: just5,
justification: just5_grandpa,
unknown_headers: Vec::new(),
authorities_proof: Some(StorageProof::new(vec![vec![50]])),
},
// last fragment provides justification for #7 && unknown#7
FinalityProofFragment {
block: header(7).hash(),
justification: just7.clone(),
justification: just7_grandpa.clone(),
unknown_headers: vec![header(7)],
authorities_proof: Some(StorageProof::new(vec![vec![70]])),
},
Expand Down Expand Up @@ -1024,7 +1035,8 @@ pub(crate) mod tests {
// finality proof at all
let blockchain = test_blockchain();
let just4 = TestJustification((0, vec![(AuthorityId::from_slice(&[42u8; 32]), 1u64)]), vec![4]).encode();
blockchain.insert(header(4).hash(), header(4), Some(vec![(ID, just4)]), None, NewBlockState::Final).unwrap();
let just4 = Some(Justifications(vec![(ID, just4)]));
blockchain.insert(header(4).hash(), header(4), just4, None, NewBlockState::Final).unwrap();

let proof_of_4 = prove_finality::<_, _, TestJustification>(
&blockchain,
Expand Down
2 changes: 1 addition & 1 deletion client/finality-grandpa/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ where
initial_sync: bool,
) -> Result<(), ConsensusError> {
let grandpa_justification =
match justification.into_iter().find(|j| j.0 == GRANDPA_ENGINE_ID) {
match justification.0.into_iter().find(|j| j.0 == GRANDPA_ENGINE_ID) {
Some((_, grandpa_justification)) => grandpa_justification,
None => {
return Err(ConsensusError::ClientImport(
Expand Down
6 changes: 3 additions & 3 deletions client/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sp_consensus::{
};
use std::{collections::{HashMap, HashSet}, pin::Pin};
use parity_scale_codec::Decode;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, HashFor};
use sp_runtime::{Justifications, traits::{Block as BlockT, Header as HeaderT, HashFor}};
use sp_runtime::generic::{BlockId, DigestItem};
use sp_core::H256;
use sp_keystore::{SyncCryptoStorePtr, SyncCryptoStore};
Expand Down Expand Up @@ -909,7 +909,7 @@ fn test_bad_justification() {
let block = || {
let block = block.clone();
let mut import = BlockImportParams::new(BlockOrigin::File, block.header);
import.justification = Some(Vec::new());
import.justification = Some(Justifications(Vec::new()));
import.body = Some(block.extrinsics);
import.fork_choice = Some(ForkChoiceStrategy::LongestChain);

Expand Down Expand Up @@ -1625,7 +1625,7 @@ fn imports_justification_for_regular_blocks_on_import() {

// we import the block with justification attached
let mut import = BlockImportParams::new(BlockOrigin::File, block.header);
import.justification = Some(vec![(GRANDPA_ENGINE_ID, justification.encode())]);
import.justification = Some(Justifications(vec![(GRANDPA_ENGINE_ID, justification.encode())]));
import.body = Some(block.extrinsics);
import.fork_choice = Some(ForkChoiceStrategy::LongestChain);

Expand Down
9 changes: 5 additions & 4 deletions client/network/src/block_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ where
} else {
None
};
let is_empty_justification = justification.as_ref().map(|j| j.is_empty()).unwrap_or(false);
let is_empty_justification = justification.as_ref().map(|j| j.0.is_empty()).unwrap_or(false);

let body = if get_body {
match self.chain.block_body(&BlockId::Hash(hash))? {
Expand All @@ -423,8 +423,9 @@ where
};

// WIP(JON): Need to encode the whole set of Justifications
let a = justification.unwrap_or_default();
let a = justification.unwrap_or(sp_runtime::Justifications(Vec::new()));
let justification = a
.0
.first()
.map(|y| y.1.clone());

Expand Down Expand Up @@ -659,10 +660,10 @@ where
// let id = sp_finality_grandpa::GRANDPA_ENGINE_ID;
const GRANDPA_ENGINE_ID: [u8; 4] = *b"FRNK";
let just = vec![(GRANDPA_ENGINE_ID, block_data.justification)];
Some(just)
Some(sp_runtime::Justifications(just))
// Some(block_data.justification)
} else if block_data.is_empty_justification {
Some(Vec::new())
Some(sp_runtime::Justifications(Vec::new()))
} else {
None
},
Expand Down
22 changes: 12 additions & 10 deletions client/network/test/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use futures::{Future, executor::block_on};
use super::*;
use sp_consensus::block_validation::Validation;
use substrate_test_runtime::Header;
use sp_runtime::Justifications;

fn test_ancestor_search_when_common_is(n: usize) {
sp_tracing::try_init_simple();
Expand Down Expand Up @@ -252,9 +253,9 @@ fn sync_justifications() {
assert_eq!(net.peer(1).client().justification(&BlockId::Number(10)).unwrap(), None);

// we finalize block #10, #15 and #20 for peer 0 with a justification
net.peer(0).client().finalize_block(BlockId::Number(10), Some(Vec::new()), true).unwrap();
net.peer(0).client().finalize_block(BlockId::Number(15), Some(Vec::new()), true).unwrap();
net.peer(0).client().finalize_block(BlockId::Number(20), Some(Vec::new()), true).unwrap();
net.peer(0).client().finalize_block(BlockId::Number(10), Some(Justifications(Vec::new())), true).unwrap();
net.peer(0).client().finalize_block(BlockId::Number(15), Some(Justifications(Vec::new())), true).unwrap();
net.peer(0).client().finalize_block(BlockId::Number(20), Some(Justifications(Vec::new())), true).unwrap();

let h1 = net.peer(1).client().header(&BlockId::Number(10)).unwrap().unwrap();
let h2 = net.peer(1).client().header(&BlockId::Number(15)).unwrap().unwrap();
Expand All @@ -269,10 +270,10 @@ fn sync_justifications() {
net.poll(cx);

for height in (10..21).step_by(5) {
if net.peer(0).client().justification(&BlockId::Number(height)).unwrap() != Some(Vec::new()) {
if net.peer(0).client().justification(&BlockId::Number(height)).unwrap() != Some(Justifications(Vec::new())) {
return Poll::Pending;
}
if net.peer(1).client().justification(&BlockId::Number(height)).unwrap() != Some(Vec::new()) {
if net.peer(1).client().justification(&BlockId::Number(height)).unwrap() != Some(Justifications(Vec::new())) {
return Poll::Pending;
}
}
Expand All @@ -295,16 +296,16 @@ fn sync_justifications_across_forks() {
// for both and finalize the small fork instead.
net.block_until_sync();

net.peer(0).client().finalize_block(BlockId::Hash(f1_best), Some(Vec::new()), true).unwrap();
net.peer(0).client().finalize_block(BlockId::Hash(f1_best), Some(Justifications(Vec::new())), true).unwrap();

net.peer(1).request_justification(&f1_best, 10);
net.peer(1).request_justification(&f2_best, 11);

block_on(futures::future::poll_fn::<(), _>(|cx| {
net.poll(cx);

if net.peer(0).client().justification(&BlockId::Number(10)).unwrap() == Some(Vec::new()) &&
net.peer(1).client().justification(&BlockId::Number(10)).unwrap() == Some(Vec::new())
if net.peer(0).client().justification(&BlockId::Number(10)).unwrap() == Some(Justifications(Vec::new())) &&
net.peer(1).client().justification(&BlockId::Number(10)).unwrap() == Some(Justifications(Vec::new()))
{
Poll::Ready(())
} else {
Expand Down Expand Up @@ -696,8 +697,9 @@ fn can_sync_to_peers_with_wrong_common_block() {
net.block_until_connected();

// both peers re-org to the same fork without notifying each other
net.peer(0).client().finalize_block(BlockId::Hash(fork_hash), Some(Vec::new()), true).unwrap();
net.peer(1).client().finalize_block(BlockId::Hash(fork_hash), Some(Vec::new()), true).unwrap();
let just = Some(Justifications(Vec::new()));
net.peer(0).client().finalize_block(BlockId::Hash(fork_hash), just.clone(), true).unwrap();
net.peer(1).client().finalize_block(BlockId::Hash(fork_hash), just, true).unwrap();
let final_hash = net.peer(0).push_blocks(1, false);

net.block_until_sync();
Expand Down
3 changes: 2 additions & 1 deletion client/service/test/src/client/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use std::sync::Arc;
use sp_runtime::{
traits::{BlakeTwo256, HashFor, NumberFor},
generic::BlockId, traits::{Block as _, Header as HeaderT}, Digest,
Justifications,
};
use std::collections::HashMap;
use parking_lot::Mutex;
Expand Down Expand Up @@ -378,7 +379,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(Default::default()),
).unwrap();
}

Expand Down
6 changes: 3 additions & 3 deletions client/service/test/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use sp_consensus::{
use sp_finality_grandpa::GRANDPA_ENGINE_ID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a TEST_ENGINE_ID here instead of adding a dependency on sp_finality_grandpa.

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;
Expand Down Expand Up @@ -1022,7 +1022,7 @@ fn import_with_justification() {
client.import(BlockOrigin::Own, a2.clone()).unwrap();

// A2 -> A3
let justification = vec![(GRANDPA_ENGINE_ID, vec![1, 2, 3])];
let justification = Justifications(vec![(GRANDPA_ENGINE_ID, vec![1, 2, 3])]);
let a3 = client.new_block_at(
&BlockId::Hash(a2.hash()),
Default::default(),
Expand Down Expand Up @@ -1094,7 +1094,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![(GRANDPA_ENGINE_ID, vec![1, 2, 3])];
let justification = Justifications(vec![(GRANDPA_ENGINE_ID, vec![1, 2, 3])]);
client.import_justified(BlockOrigin::Own, b1.clone(), justification).unwrap();

assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ mod tests {
libp2p::PeerId::random(),
hash,
1,
Vec::new(),
sp_runtime::Justifications(Vec::new()),
)))
.unwrap();

Expand Down
5 changes: 3 additions & 2 deletions primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ pub use either::Either;
/// bypasses this problem.
pub type EncodedJustification = Vec<u8>;
/// Collection of Justifications, since we might have more than one stored per block.
// WIP(JON): Consider making `Justifications` strongly typed.
pub type Justifications = Vec<(ConsensusEngineId, EncodedJustification)>;
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct Justifications(pub Vec<(ConsensusEngineId, EncodedJustification)>);

use traits::{Verify, Lazy};

Expand Down