|
|
|
@@ -2573,8 +2573,7 @@ pub(crate) mod tests {
|
|
|
|
|
use sp_blockchain::{lowest_common_ancestor, tree_route};
|
|
|
|
|
use sp_core::H256;
|
|
|
|
|
use sp_runtime::{
|
|
|
|
|
generic::UncheckedExtrinsic,
|
|
|
|
|
testing::{Block as RawBlock, Header, MockCallU64},
|
|
|
|
|
testing::{Block as RawBlock, ExtrinsicWrapper, Header},
|
|
|
|
|
traits::{BlakeTwo256, Hash},
|
|
|
|
|
ConsensusEngineId, StateVersion,
|
|
|
|
|
};
|
|
|
|
@@ -2582,8 +2581,7 @@ pub(crate) mod tests {
|
|
|
|
|
const CONS0_ENGINE_ID: ConsensusEngineId = *b"CON0";
|
|
|
|
|
const CONS1_ENGINE_ID: ConsensusEngineId = *b"CON1";
|
|
|
|
|
|
|
|
|
|
type UncheckedXt = UncheckedExtrinsic<u64, MockCallU64, (), ()>;
|
|
|
|
|
pub(crate) type Block = RawBlock<UncheckedXt>;
|
|
|
|
|
pub(crate) type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
|
|
|
|
|
|
|
|
|
pub fn insert_header(
|
|
|
|
|
backend: &Backend<Block>,
|
|
|
|
@@ -2602,7 +2600,7 @@ pub(crate) mod tests {
|
|
|
|
|
parent_hash: H256,
|
|
|
|
|
_changes: Option<Vec<(Vec<u8>, Vec<u8>)>>,
|
|
|
|
|
extrinsics_root: H256,
|
|
|
|
|
body: Vec<UncheckedXt>,
|
|
|
|
|
body: Vec<ExtrinsicWrapper<u64>>,
|
|
|
|
|
transaction_index: Option<Vec<IndexOperation>>,
|
|
|
|
|
) -> Result<H256, sp_blockchain::Error> {
|
|
|
|
|
use sp_runtime::testing::Digest;
|
|
|
|
@@ -3416,7 +3414,7 @@ pub(crate) mod tests {
|
|
|
|
|
prev_hash,
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(i.into(), ())],
|
|
|
|
|
vec![i.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3438,20 +3436,11 @@ pub(crate) mod tests {
|
|
|
|
|
assert_eq!(None, bc.body(blocks[0]).unwrap());
|
|
|
|
|
assert_eq!(None, bc.body(blocks[1]).unwrap());
|
|
|
|
|
assert_eq!(None, bc.body(blocks[2]).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
|
|
|
|
|
bc.body(blocks[3]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
|
|
|
|
|
bc.body(blocks[4]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![3.into()]), bc.body(blocks[3]).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![4.into()]), bc.body(blocks[4]).unwrap());
|
|
|
|
|
} else {
|
|
|
|
|
for i in 0..5 {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction((i as u64).into(), ())]),
|
|
|
|
|
bc.body(blocks[i]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![(i as u64).into()]), bc.body(blocks[i]).unwrap());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -3475,7 +3464,7 @@ pub(crate) mod tests {
|
|
|
|
|
prev_hash,
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(i.into(), ())],
|
|
|
|
|
vec![i.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3484,26 +3473,16 @@ pub(crate) mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// insert a fork at block 2
|
|
|
|
|
let fork_hash_root = insert_block(
|
|
|
|
|
&backend,
|
|
|
|
|
2,
|
|
|
|
|
blocks[1],
|
|
|
|
|
None,
|
|
|
|
|
H256::random(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(2.into(), ())],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let fork_hash_root =
|
|
|
|
|
insert_block(&backend, 2, blocks[1], None, H256::random(), vec![2.into()], None)
|
|
|
|
|
.unwrap();
|
|
|
|
|
insert_block(
|
|
|
|
|
&backend,
|
|
|
|
|
3,
|
|
|
|
|
fork_hash_root,
|
|
|
|
|
None,
|
|
|
|
|
H256::random(),
|
|
|
|
|
vec![
|
|
|
|
|
UncheckedXt::new_transaction(3.into(), ()),
|
|
|
|
|
UncheckedXt::new_transaction(11.into(), ()),
|
|
|
|
|
],
|
|
|
|
|
vec![3.into(), 11.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3513,10 +3492,7 @@ pub(crate) mod tests {
|
|
|
|
|
backend.commit_operation(op).unwrap();
|
|
|
|
|
|
|
|
|
|
let bc = backend.blockchain();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
|
|
|
|
|
bc.body(fork_hash_root).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![2.into()]), bc.body(fork_hash_root).unwrap());
|
|
|
|
|
|
|
|
|
|
for i in 1..5 {
|
|
|
|
|
let mut op = backend.begin_operation().unwrap();
|
|
|
|
@@ -3530,28 +3506,16 @@ pub(crate) mod tests {
|
|
|
|
|
assert_eq!(None, bc.body(blocks[1]).unwrap());
|
|
|
|
|
assert_eq!(None, bc.body(blocks[2]).unwrap());
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
|
|
|
|
|
bc.body(blocks[3]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
|
|
|
|
|
bc.body(blocks[4]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![3.into()]), bc.body(blocks[3]).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![4.into()]), bc.body(blocks[4]).unwrap());
|
|
|
|
|
} else {
|
|
|
|
|
for i in 0..5 {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction((i as u64).into(), ())]),
|
|
|
|
|
bc.body(blocks[i]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![(i as u64).into()]), bc.body(blocks[i]).unwrap());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if matches!(pruning, BlocksPruning::KeepAll) {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
|
|
|
|
|
bc.body(fork_hash_root).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![2.into()]), bc.body(fork_hash_root).unwrap());
|
|
|
|
|
} else {
|
|
|
|
|
assert_eq!(None, bc.body(fork_hash_root).unwrap());
|
|
|
|
|
}
|
|
|
|
@@ -3572,16 +3536,8 @@ pub(crate) mod tests {
|
|
|
|
|
let backend = Backend::<Block>::new_test_with_tx_storage(BlocksPruning::Some(10), 10);
|
|
|
|
|
|
|
|
|
|
let make_block = |index, parent, val: u64| {
|
|
|
|
|
insert_block(
|
|
|
|
|
&backend,
|
|
|
|
|
index,
|
|
|
|
|
parent,
|
|
|
|
|
None,
|
|
|
|
|
H256::random(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(val.into(), ())],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap()
|
|
|
|
|
insert_block(&backend, index, parent, None, H256::random(), vec![val.into()], None)
|
|
|
|
|
.unwrap()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let block_0 = make_block(0, Default::default(), 0x00);
|
|
|
|
@@ -3609,30 +3565,18 @@ pub(crate) mod tests {
|
|
|
|
|
let bc = backend.blockchain();
|
|
|
|
|
assert_eq!(None, bc.body(block_1b).unwrap());
|
|
|
|
|
assert_eq!(None, bc.body(block_2b).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(0x00.into(), ())]),
|
|
|
|
|
bc.body(block_0).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(0x1a.into(), ())]),
|
|
|
|
|
bc.body(block_1a).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(0x2a.into(), ())]),
|
|
|
|
|
bc.body(block_2a).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(0x3a.into(), ())]),
|
|
|
|
|
bc.body(block_3a).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![0x00.into()]), bc.body(block_0).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![0x1a.into()]), bc.body(block_1a).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![0x2a.into()]), bc.body(block_2a).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![0x3a.into()]), bc.body(block_3a).unwrap());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn indexed_data_block_body() {
|
|
|
|
|
let backend = Backend::<Block>::new_test_with_tx_storage(BlocksPruning::Some(1), 10);
|
|
|
|
|
|
|
|
|
|
let x0 = UncheckedXt::new_transaction(0.into(), ()).encode();
|
|
|
|
|
let x1 = UncheckedXt::new_transaction(1.into(), ()).encode();
|
|
|
|
|
let x0 = ExtrinsicWrapper::from(0u64).encode();
|
|
|
|
|
let x1 = ExtrinsicWrapper::from(1u64).encode();
|
|
|
|
|
let x0_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x0[1..]);
|
|
|
|
|
let x1_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x1[1..]);
|
|
|
|
|
let index = vec![
|
|
|
|
@@ -3653,10 +3597,7 @@ pub(crate) mod tests {
|
|
|
|
|
Default::default(),
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![
|
|
|
|
|
UncheckedXt::new_transaction(0.into(), ()),
|
|
|
|
|
UncheckedXt::new_transaction(1.into(), ()),
|
|
|
|
|
],
|
|
|
|
|
vec![0u64.into(), 1u64.into()],
|
|
|
|
|
Some(index),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3678,9 +3619,8 @@ pub(crate) mod tests {
|
|
|
|
|
fn index_invalid_size() {
|
|
|
|
|
let backend = Backend::<Block>::new_test_with_tx_storage(BlocksPruning::Some(1), 10);
|
|
|
|
|
|
|
|
|
|
let x0 = UncheckedXt::new_transaction(0.into(), ()).encode();
|
|
|
|
|
let x1 = UncheckedXt::new_transaction(1.into(), ()).encode();
|
|
|
|
|
|
|
|
|
|
let x0 = ExtrinsicWrapper::from(0u64).encode();
|
|
|
|
|
let x1 = ExtrinsicWrapper::from(1u64).encode();
|
|
|
|
|
let x0_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x0[..]);
|
|
|
|
|
let x1_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x1[..]);
|
|
|
|
|
let index = vec![
|
|
|
|
@@ -3701,10 +3641,7 @@ pub(crate) mod tests {
|
|
|
|
|
Default::default(),
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![
|
|
|
|
|
UncheckedXt::new_transaction(0.into(), ()),
|
|
|
|
|
UncheckedXt::new_transaction(1.into(), ()),
|
|
|
|
|
],
|
|
|
|
|
vec![0u64.into(), 1u64.into()],
|
|
|
|
|
Some(index),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3718,7 +3655,7 @@ pub(crate) mod tests {
|
|
|
|
|
let backend = Backend::<Block>::new_test_with_tx_storage(BlocksPruning::Some(2), 10);
|
|
|
|
|
let mut blocks = Vec::new();
|
|
|
|
|
let mut prev_hash = Default::default();
|
|
|
|
|
let x1 = UncheckedXt::new_transaction(0.into(), ()).encode();
|
|
|
|
|
let x1 = ExtrinsicWrapper::from(0u64).encode();
|
|
|
|
|
let x1_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x1[1..]);
|
|
|
|
|
for i in 0..10 {
|
|
|
|
|
let mut index = Vec::new();
|
|
|
|
@@ -3738,7 +3675,7 @@ pub(crate) mod tests {
|
|
|
|
|
prev_hash,
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(i.into(), ())],
|
|
|
|
|
vec![i.into()],
|
|
|
|
|
Some(index),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3772,7 +3709,7 @@ pub(crate) mod tests {
|
|
|
|
|
prev_hash,
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(i.into(), ())],
|
|
|
|
|
vec![i.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3787,7 +3724,7 @@ pub(crate) mod tests {
|
|
|
|
|
blocks[1],
|
|
|
|
|
None,
|
|
|
|
|
sp_core::H256::random(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(i.into(), ())],
|
|
|
|
|
vec![i.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -3801,7 +3738,7 @@ pub(crate) mod tests {
|
|
|
|
|
blocks[0],
|
|
|
|
|
None,
|
|
|
|
|
sp_core::H256::random(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(42.into(), ())],
|
|
|
|
|
vec![42.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -4274,7 +4211,7 @@ pub(crate) mod tests {
|
|
|
|
|
prev_hash,
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(i.into(), ())],
|
|
|
|
|
vec![i.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -4289,10 +4226,7 @@ pub(crate) mod tests {
|
|
|
|
|
|
|
|
|
|
// Check that we can properly access values when there is reference count
|
|
|
|
|
// but no value.
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(1.into(), ())]),
|
|
|
|
|
bc.body(blocks[1]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![1.into()]), bc.body(blocks[1]).unwrap());
|
|
|
|
|
|
|
|
|
|
// Block 1 gets pinned three times
|
|
|
|
|
backend.pin_block(blocks[1]).unwrap();
|
|
|
|
@@ -4309,42 +4243,27 @@ pub(crate) mod tests {
|
|
|
|
|
|
|
|
|
|
// Block 0, 1, 2, 3 are pinned, so all values should be cached.
|
|
|
|
|
// Block 4 is inside the pruning window, its value is in db.
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(0.into(), ())]),
|
|
|
|
|
bc.body(blocks[0]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![0.into()]), bc.body(blocks[0]).unwrap());
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(1.into(), ())]),
|
|
|
|
|
bc.body(blocks[1]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![1.into()]), bc.body(blocks[1]).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(Justifications::from(build_justification(1))),
|
|
|
|
|
bc.justifications(blocks[1]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
|
|
|
|
|
bc.body(blocks[2]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![2.into()]), bc.body(blocks[2]).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(Justifications::from(build_justification(2))),
|
|
|
|
|
bc.justifications(blocks[2]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
|
|
|
|
|
bc.body(blocks[3]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![3.into()]), bc.body(blocks[3]).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(Justifications::from(build_justification(3))),
|
|
|
|
|
bc.justifications(blocks[3]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
|
|
|
|
|
bc.body(blocks[4]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![4.into()]), bc.body(blocks[4]).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(Justifications::from(build_justification(4))),
|
|
|
|
|
bc.justifications(blocks[4]).unwrap()
|
|
|
|
@@ -4375,10 +4294,7 @@ pub(crate) mod tests {
|
|
|
|
|
assert!(bc.justifications(blocks[1]).unwrap().is_none());
|
|
|
|
|
|
|
|
|
|
// Block 4 is inside the pruning window and still kept
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
|
|
|
|
|
bc.body(blocks[4]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![4.into()]), bc.body(blocks[4]).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(Justifications::from(build_justification(4))),
|
|
|
|
|
bc.justifications(blocks[4]).unwrap()
|
|
|
|
@@ -4386,16 +4302,9 @@ pub(crate) mod tests {
|
|
|
|
|
|
|
|
|
|
// Block tree:
|
|
|
|
|
// 0 -> 1 -> 2 -> 3 -> 4 -> 5
|
|
|
|
|
let hash = insert_block(
|
|
|
|
|
&backend,
|
|
|
|
|
5,
|
|
|
|
|
prev_hash,
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(5.into(), ())],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let hash =
|
|
|
|
|
insert_block(&backend, 5, prev_hash, None, Default::default(), vec![5.into()], None)
|
|
|
|
|
.unwrap();
|
|
|
|
|
blocks.push(hash);
|
|
|
|
|
|
|
|
|
|
backend.pin_block(blocks[4]).unwrap();
|
|
|
|
@@ -4410,18 +4319,12 @@ pub(crate) mod tests {
|
|
|
|
|
assert!(bc.body(blocks[2]).unwrap().is_none());
|
|
|
|
|
assert!(bc.body(blocks[3]).unwrap().is_none());
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
|
|
|
|
|
bc.body(blocks[4]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![4.into()]), bc.body(blocks[4]).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(Justifications::from(build_justification(4))),
|
|
|
|
|
bc.justifications(blocks[4]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(5.into(), ())]),
|
|
|
|
|
bc.body(blocks[5]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![5.into()]), bc.body(blocks[5]).unwrap());
|
|
|
|
|
assert!(bc.header(blocks[5]).ok().flatten().is_some());
|
|
|
|
|
|
|
|
|
|
backend.unpin_block(blocks[4]);
|
|
|
|
@@ -4431,16 +4334,9 @@ pub(crate) mod tests {
|
|
|
|
|
// Append a justification to block 5.
|
|
|
|
|
backend.append_justification(blocks[5], ([0, 0, 0, 1], vec![42])).unwrap();
|
|
|
|
|
|
|
|
|
|
let hash = insert_block(
|
|
|
|
|
&backend,
|
|
|
|
|
6,
|
|
|
|
|
blocks[5],
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(6.into(), ())],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let hash =
|
|
|
|
|
insert_block(&backend, 6, blocks[5], None, Default::default(), vec![6.into()], None)
|
|
|
|
|
.unwrap();
|
|
|
|
|
blocks.push(hash);
|
|
|
|
|
|
|
|
|
|
// Pin block 5 so it gets loaded into the cache on prune
|
|
|
|
@@ -4453,10 +4349,7 @@ pub(crate) mod tests {
|
|
|
|
|
op.mark_finalized(blocks[6], None).unwrap();
|
|
|
|
|
backend.commit_operation(op).unwrap();
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(5.into(), ())]),
|
|
|
|
|
bc.body(blocks[5]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![5.into()]), bc.body(blocks[5]).unwrap());
|
|
|
|
|
assert!(bc.header(blocks[5]).ok().flatten().is_some());
|
|
|
|
|
let mut expected = Justifications::from(build_justification(5));
|
|
|
|
|
expected.append(([0, 0, 0, 1], vec![42]));
|
|
|
|
@@ -4478,7 +4371,7 @@ pub(crate) mod tests {
|
|
|
|
|
prev_hash,
|
|
|
|
|
None,
|
|
|
|
|
Default::default(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(i.into(), ())],
|
|
|
|
|
vec![i.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -4494,26 +4387,16 @@ pub(crate) mod tests {
|
|
|
|
|
// Block tree:
|
|
|
|
|
// 0 -> 1 -> 2 -> 3 -> 4
|
|
|
|
|
// \ -> 2 -> 3
|
|
|
|
|
let fork_hash_root = insert_block(
|
|
|
|
|
&backend,
|
|
|
|
|
2,
|
|
|
|
|
blocks[1],
|
|
|
|
|
None,
|
|
|
|
|
H256::random(),
|
|
|
|
|
vec![UncheckedXt::new_transaction(2.into(), ())],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let fork_hash_root =
|
|
|
|
|
insert_block(&backend, 2, blocks[1], None, H256::random(), vec![2.into()], None)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let fork_hash_3 = insert_block(
|
|
|
|
|
&backend,
|
|
|
|
|
3,
|
|
|
|
|
fork_hash_root,
|
|
|
|
|
None,
|
|
|
|
|
H256::random(),
|
|
|
|
|
vec![
|
|
|
|
|
UncheckedXt::new_transaction(3.into(), ()),
|
|
|
|
|
UncheckedXt::new_transaction(11.into(), ()),
|
|
|
|
|
],
|
|
|
|
|
vec![3.into(), 11.into()],
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
@@ -4534,35 +4417,14 @@ pub(crate) mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let bc = backend.blockchain();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(0.into(), ())]),
|
|
|
|
|
bc.body(blocks[0]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(1.into(), ())]),
|
|
|
|
|
bc.body(blocks[1]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(2.into(), ())]),
|
|
|
|
|
bc.body(blocks[2]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(3.into(), ())]),
|
|
|
|
|
bc.body(blocks[3]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![UncheckedXt::new_transaction(4.into(), ())]),
|
|
|
|
|
bc.body(blocks[4]).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![0.into()]), bc.body(blocks[0]).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![1.into()]), bc.body(blocks[1]).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![2.into()]), bc.body(blocks[2]).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![3.into()]), bc.body(blocks[3]).unwrap());
|
|
|
|
|
assert_eq!(Some(vec![4.into()]), bc.body(blocks[4]).unwrap());
|
|
|
|
|
// Check the fork hashes.
|
|
|
|
|
assert_eq!(None, bc.body(fork_hash_root).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
Some(vec![
|
|
|
|
|
UncheckedXt::new_transaction(3.into(), ()),
|
|
|
|
|
UncheckedXt::new_transaction(11.into(), ())
|
|
|
|
|
]),
|
|
|
|
|
bc.body(fork_hash_3).unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(Some(vec![3.into(), 11.into()]), bc.body(fork_hash_3).unwrap());
|
|
|
|
|
|
|
|
|
|
// Unpin all blocks, except the forked one.
|
|
|
|
|
for block in &blocks {
|
|
|
|
|