Test checkpoints on mainnet and testnet

This commit is contained in:
teor 2021-03-02 17:11:08 +10:00
parent b8cc3bfb23
commit e1002ce2ce
2 changed files with 51 additions and 38 deletions

View File

@ -215,63 +215,54 @@ async fn multi_item_checkpoint_list() -> Result<(), Report> {
#[tokio::test] #[tokio::test]
async fn continuous_blockchain_no_restart() -> Result<(), Report> { async fn continuous_blockchain_no_restart() -> Result<(), Report> {
continuous_blockchain(None).await?; continuous_blockchain(None, Mainnet).await?;
continuous_blockchain(None, Testnet).await?;
Ok(()) Ok(())
} }
#[tokio::test] #[tokio::test]
async fn continuous_blockchain_restart() -> Result<(), Report> { async fn continuous_blockchain_restart() -> Result<(), Report> {
for height in 0..=10 { for height in 0..=10 {
continuous_blockchain(Some(block::Height(height))).await?; continuous_blockchain(Some(block::Height(height)), Mainnet).await?;
}
for height in 0..=10 {
continuous_blockchain(Some(block::Height(height)), Testnet).await?;
} }
Ok(()) Ok(())
} }
/// Test a continuous blockchain, restarting verification at `restart_height`. /// Test a continuous blockchain on `network`, restarting verification at `restart_height`.
#[spandoc::spandoc] #[spandoc::spandoc]
async fn continuous_blockchain(restart_height: Option<block::Height>) -> Result<(), Report> { async fn continuous_blockchain(
restart_height: Option<block::Height>,
network: Network,
) -> Result<(), Report> {
zebra_test::init(); zebra_test::init();
// A continuous blockchain // A continuous blockchain
let mut blockchain = Vec::new(); let blockchain = match network {
for b in &[ Mainnet => zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS.iter(),
&zebra_test::vectors::BLOCK_MAINNET_GENESIS_BYTES[..], Testnet => zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS.iter(),
&zebra_test::vectors::BLOCK_MAINNET_1_BYTES[..], };
&zebra_test::vectors::BLOCK_MAINNET_2_BYTES[..], let blockchain: Vec<_> = blockchain
&zebra_test::vectors::BLOCK_MAINNET_3_BYTES[..], .map(|(height, b)| {
&zebra_test::vectors::BLOCK_MAINNET_4_BYTES[..], let block = Arc::<Block>::zcash_deserialize(*b).unwrap();
&zebra_test::vectors::BLOCK_MAINNET_5_BYTES[..], let hash = block.hash();
&zebra_test::vectors::BLOCK_MAINNET_6_BYTES[..], let coinbase_height = block.coinbase_height().unwrap();
&zebra_test::vectors::BLOCK_MAINNET_7_BYTES[..], assert_eq!(*height, coinbase_height.0);
&zebra_test::vectors::BLOCK_MAINNET_8_BYTES[..], (block, coinbase_height, hash)
&zebra_test::vectors::BLOCK_MAINNET_9_BYTES[..], })
&zebra_test::vectors::BLOCK_MAINNET_10_BYTES[..], .collect();
] {
let block = Arc::<Block>::zcash_deserialize(*b)?;
let hash = block.hash();
blockchain.push((block.clone(), block.coinbase_height().unwrap(), hash));
}
let blockchain_len = blockchain.len(); let blockchain_len = blockchain.len();
// Parse only some blocks as checkpoints // Use some of the blocks as checkpoints
let mut checkpoints = Vec::new(); let checkpoint_list = vec![&blockchain[0], &blockchain[5], &blockchain[9]];
for b in &[ let checkpoint_list: BTreeMap<block::Height, block::Hash> = checkpoint_list
&zebra_test::vectors::BLOCK_MAINNET_GENESIS_BYTES[..],
&zebra_test::vectors::BLOCK_MAINNET_5_BYTES[..],
&zebra_test::vectors::BLOCK_MAINNET_9_BYTES[..],
] {
let block = Arc::<Block>::zcash_deserialize(*b)?;
let hash = block.hash();
checkpoints.push((block.clone(), block.coinbase_height().unwrap(), hash));
}
// The checkpoint list will contain only block 0, 5 and 9
let checkpoint_list: BTreeMap<block::Height, block::Hash> = checkpoints
.iter() .iter()
.map(|(_block, height, hash)| (*height, *hash)) .map(|(_block, height, hash)| (*height, *hash))
.collect(); .collect();
/// SPANDOC: Verify blocks, restarting at {?restart_height} /// SPANDOC: Verify blocks, restarting at {?restart_height} {?network}
{ {
let initial_tip = restart_height.map(|block::Height(height)| { let initial_tip = restart_height.map(|block::Height(height)| {
(blockchain[height as usize].1, blockchain[height as usize].2) (blockchain[height as usize].1, blockchain[height as usize].2)
@ -401,7 +392,7 @@ async fn continuous_blockchain(restart_height: Option<block::Height>) -> Result<
); );
} }
/// SPANDOC: wait on spawned verification tasks for restart height {?restart_height} /// SPANDOC: wait on spawned verification tasks for restart height {?restart_height} {?network}
while let Some(result) = handles.next().await { while let Some(result) = handles.next().await {
result??.map_err(|e| eyre!(e))?; result??.map_err(|e| eyre!(e))?;
} }

View File

@ -14,6 +14,28 @@ lazy_static! {
.map(|(_height, block)| *block) .map(|(_height, block)| *block)
.collect(); .collect();
/// Continuous mainnet blocks, indexed by height
///
/// Contains the continuous blockchain from genesis onwards.
/// Stops at the first gap in the chain.
pub static ref CONTINUOUS_MAINNET_BLOCKS: BTreeMap<u32, &'static [u8]> = MAINNET_BLOCKS
.iter()
.enumerate()
.take_while(|(i, (height, _block))| *i == **height as usize)
.map(|(_i, (height, block))| (*height, *block))
.collect();
/// Continuous testnet blocks, indexed by height
///
/// Contains the continuous blockchain from genesis onwards.
/// Stops at the first gap in the chain.
pub static ref CONTINUOUS_TESTNET_BLOCKS: BTreeMap<u32, &'static [u8]> = TESTNET_BLOCKS
.iter()
.enumerate()
.take_while(|(i, (height, _block))| *i == **height as usize)
.map(|(_i, (height, block))| (*height, *block))
.collect();
// Update these lists of blocks when you add new block test vectors to // Update these lists of blocks when you add new block test vectors to
// this file // this file
// //