mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor(provider): random_block and random_block_range functions (#10563)
This commit is contained in:
@ -183,15 +183,13 @@ impl BlockBuffer {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use crate::BlockBuffer;
|
use crate::BlockBuffer;
|
||||||
use reth_primitives::{BlockHash, BlockNumHash, SealedBlockWithSenders};
|
use reth_primitives::{BlockHash, BlockNumHash, SealedBlockWithSenders};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{self, random_block, BlockParams, Rng};
|
||||||
generators,
|
|
||||||
generators::{random_block, Rng},
|
|
||||||
};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// Create random block with specified number and parent hash.
|
/// Create random block with specified number and parent hash.
|
||||||
fn create_block<R: Rng>(rng: &mut R, number: u64, parent: BlockHash) -> SealedBlockWithSenders {
|
fn create_block<R: Rng>(rng: &mut R, number: u64, parent: BlockHash) -> SealedBlockWithSenders {
|
||||||
let block = random_block(rng, number, Some(parent), None, None, None, None);
|
let block =
|
||||||
|
random_block(rng, number, BlockParams { parent: Some(parent), ..Default::default() });
|
||||||
block.seal_with_senders().unwrap()
|
block.seal_with_senders().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2175,6 +2175,7 @@ mod tests {
|
|||||||
|
|
||||||
mod fork_choice_updated {
|
mod fork_choice_updated {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use generators::BlockParams;
|
||||||
use reth_db::{tables, test_utils::create_test_static_files_dir};
|
use reth_db::{tables, test_utils::create_test_static_files_dir};
|
||||||
use reth_db_api::transaction::DbTxMut;
|
use reth_db_api::transaction::DbTxMut;
|
||||||
use reth_primitives::U256;
|
use reth_primitives::U256;
|
||||||
@ -2230,8 +2231,20 @@ mod tests {
|
|||||||
})]))
|
})]))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
|
let genesis = random_block(
|
||||||
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
&mut rng,
|
||||||
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
|
let block1 = random_block(
|
||||||
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(genesis.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
||||||
|
|
||||||
insert_blocks(
|
insert_blocks(
|
||||||
@ -2289,8 +2302,16 @@ mod tests {
|
|||||||
.disable_blockchain_tree_sync()
|
.disable_blockchain_tree_sync()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
|
let genesis = random_block(
|
||||||
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
&mut rng,
|
||||||
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
|
let block1 = random_block(
|
||||||
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams { parent: Some(genesis.hash()), ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
||||||
|
|
||||||
@ -2304,9 +2325,15 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut engine_rx = spawn_consensus_engine(consensus_engine);
|
let mut engine_rx = spawn_consensus_engine(consensus_engine);
|
||||||
|
let next_head = random_block(
|
||||||
let next_head =
|
&mut rng,
|
||||||
random_block(&mut rng, 2, Some(block1.hash()), None, Some(0), None, None);
|
2,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(block1.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
let next_forkchoice_state = ForkchoiceState {
|
let next_forkchoice_state = ForkchoiceState {
|
||||||
head_block_hash: next_head.hash(),
|
head_block_hash: next_head.hash(),
|
||||||
finalized_block_hash: block1.hash(),
|
finalized_block_hash: block1.hash(),
|
||||||
@ -2358,8 +2385,20 @@ mod tests {
|
|||||||
.disable_blockchain_tree_sync()
|
.disable_blockchain_tree_sync()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
|
let genesis = random_block(
|
||||||
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
&mut rng,
|
||||||
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
|
let block1 = random_block(
|
||||||
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(genesis.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
||||||
|
|
||||||
@ -2405,19 +2444,44 @@ mod tests {
|
|||||||
]))
|
]))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
|
let genesis = random_block(
|
||||||
let mut block1 =
|
&mut rng,
|
||||||
random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
|
let mut block1 = random_block(
|
||||||
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(genesis.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
block1.header.set_difficulty(U256::from(1));
|
block1.header.set_difficulty(U256::from(1));
|
||||||
|
|
||||||
// a second pre-merge block
|
// a second pre-merge block
|
||||||
let mut block2 =
|
let mut block2 = random_block(
|
||||||
random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(genesis.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
block2.header.set_difficulty(U256::from(1));
|
block2.header.set_difficulty(U256::from(1));
|
||||||
|
|
||||||
// a transition block
|
// a transition block
|
||||||
let mut block3 =
|
let mut block3 = random_block(
|
||||||
random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(genesis.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
block3.header.set_difficulty(U256::from(1));
|
block3.header.set_difficulty(U256::from(1));
|
||||||
|
|
||||||
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
||||||
@ -2465,8 +2529,20 @@ mod tests {
|
|||||||
]))
|
]))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
|
let genesis = random_block(
|
||||||
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
&mut rng,
|
||||||
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
|
let block1 = random_block(
|
||||||
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(genesis.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let (_temp_dir, temp_dir_path) = create_test_static_files_dir();
|
let (_temp_dir, temp_dir_path) = create_test_static_files_dir();
|
||||||
|
|
||||||
@ -2500,6 +2576,7 @@ mod tests {
|
|||||||
mod new_payload {
|
mod new_payload {
|
||||||
use super::*;
|
use super::*;
|
||||||
use alloy_genesis::Genesis;
|
use alloy_genesis::Genesis;
|
||||||
|
use generators::BlockParams;
|
||||||
use reth_db::test_utils::create_test_static_files_dir;
|
use reth_db::test_utils::create_test_static_files_dir;
|
||||||
use reth_primitives::{EthereumHardfork, U256};
|
use reth_primitives::{EthereumHardfork, U256};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
@ -2529,7 +2606,11 @@ mod tests {
|
|||||||
// Send new payload
|
// Send new payload
|
||||||
let res = env
|
let res = env
|
||||||
.send_new_payload(
|
.send_new_payload(
|
||||||
block_to_payload_v1(random_block(&mut rng, 0, None, None, Some(0), None, None)),
|
block_to_payload_v1(random_block(
|
||||||
|
&mut rng,
|
||||||
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
)),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@ -2540,7 +2621,11 @@ mod tests {
|
|||||||
// Send new payload
|
// Send new payload
|
||||||
let res = env
|
let res = env
|
||||||
.send_new_payload(
|
.send_new_payload(
|
||||||
block_to_payload_v1(random_block(&mut rng, 1, None, None, Some(0), None, None)),
|
block_to_payload_v1(random_block(
|
||||||
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
)),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@ -2569,9 +2654,29 @@ mod tests {
|
|||||||
})]))
|
})]))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
|
let genesis = random_block(
|
||||||
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
|
&mut rng,
|
||||||
let block2 = random_block(&mut rng, 2, Some(block1.hash()), None, Some(0), None, None);
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
|
let block1 = random_block(
|
||||||
|
&mut rng,
|
||||||
|
1,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(genesis.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let block2 = random_block(
|
||||||
|
&mut rng,
|
||||||
|
2,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(block1.hash()),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
||||||
insert_blocks(
|
insert_blocks(
|
||||||
@ -2642,11 +2747,11 @@ mod tests {
|
|||||||
let block1 = random_block(
|
let block1 = random_block(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
1,
|
1,
|
||||||
Some(chain_spec.genesis_hash()),
|
BlockParams {
|
||||||
None,
|
parent: Some(chain_spec.genesis_hash()),
|
||||||
Some(0),
|
ommers_count: Some(0),
|
||||||
None,
|
..Default::default()
|
||||||
None,
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: add transactions that transfer from the alloc accounts, generating the new
|
// TODO: add transactions that transfer from the alloc accounts, generating the new
|
||||||
@ -2696,8 +2801,11 @@ mod tests {
|
|||||||
done: true,
|
done: true,
|
||||||
})]))
|
})]))
|
||||||
.build();
|
.build();
|
||||||
|
let genesis = random_block(
|
||||||
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
|
&mut rng,
|
||||||
|
0,
|
||||||
|
BlockParams { ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
let (_static_dir, static_dir_path) = create_test_static_files_dir();
|
||||||
|
|
||||||
@ -2726,7 +2834,11 @@ mod tests {
|
|||||||
|
|
||||||
// Send new payload
|
// Send new payload
|
||||||
let parent = rng.gen();
|
let parent = rng.gen();
|
||||||
let block = random_block(&mut rng, 2, Some(parent), None, Some(0), None, None);
|
let block = random_block(
|
||||||
|
&mut rng,
|
||||||
|
2,
|
||||||
|
BlockParams { parent: Some(parent), ommers_count: Some(0), ..Default::default() },
|
||||||
|
);
|
||||||
let res = env.send_new_payload(block_to_payload_v1(block), None).await;
|
let res = env.send_new_payload(block_to_payload_v1(block), None).await;
|
||||||
let expected_result = PayloadStatus::from_status(PayloadStatusEnum::Syncing);
|
let expected_result = PayloadStatus::from_status(PayloadStatusEnum::Syncing);
|
||||||
assert_matches!(res, Ok(result) => assert_eq!(result, expected_result));
|
assert_matches!(res, Ok(result) => assert_eq!(result, expected_result));
|
||||||
|
|||||||
@ -607,7 +607,7 @@ mod tests {
|
|||||||
use reth_db::test_utils::{create_test_rw_db, create_test_static_files_dir};
|
use reth_db::test_utils::{create_test_rw_db, create_test_static_files_dir};
|
||||||
use reth_primitives::{BlockBody, B256};
|
use reth_primitives::{BlockBody, B256};
|
||||||
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
|
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
|
||||||
use reth_testing_utils::{generators, generators::random_block_range};
|
use reth_testing_utils::generators::{self, random_block_range, BlockRangeParams};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// Check that the blocks are emitted in order of block number, not in order of
|
// Check that the blocks are emitted in order of block number, not in order of
|
||||||
@ -650,7 +650,11 @@ mod tests {
|
|||||||
// Generate some random blocks
|
// Generate some random blocks
|
||||||
let db = create_test_rw_db();
|
let db = create_test_rw_db();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let blocks = random_block_range(&mut rng, 0..=199, B256::ZERO, 1..2, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=199,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 1..2, ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
let headers = blocks.iter().map(|block| block.header.clone()).collect::<Vec<_>>();
|
let headers = blocks.iter().map(|block| block.header.clone()).collect::<Vec<_>>();
|
||||||
let bodies = blocks
|
let bodies = blocks
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
use crate::{bodies::test_utils::create_raw_bodies, file_codec::BlockFileCodec};
|
use crate::{bodies::test_utils::create_raw_bodies, file_codec::BlockFileCodec};
|
||||||
use futures::SinkExt;
|
use futures::SinkExt;
|
||||||
use reth_primitives::{BlockBody, SealedHeader, B256};
|
use reth_primitives::{BlockBody, SealedHeader, B256};
|
||||||
use reth_testing_utils::{generators, generators::random_block_range};
|
use reth_testing_utils::generators::{self, random_block_range, BlockRangeParams};
|
||||||
use std::{collections::HashMap, io::SeekFrom, ops::RangeInclusive};
|
use std::{collections::HashMap, io::SeekFrom, ops::RangeInclusive};
|
||||||
use tokio::{fs::File, io::AsyncSeekExt};
|
use tokio::{fs::File, io::AsyncSeekExt};
|
||||||
use tokio_util::codec::FramedWrite;
|
use tokio_util::codec::FramedWrite;
|
||||||
@ -21,7 +21,11 @@ pub(crate) fn generate_bodies(
|
|||||||
range: RangeInclusive<u64>,
|
range: RangeInclusive<u64>,
|
||||||
) -> (Vec<SealedHeader>, HashMap<B256, BlockBody>) {
|
) -> (Vec<SealedHeader>, HashMap<B256, BlockBody>) {
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let blocks = random_block_range(&mut rng, range, B256::ZERO, 0..2, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
range,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..2, ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
let headers = blocks.iter().map(|block| block.header.clone()).collect();
|
let headers = blocks.iter().map(|block| block.header.clone()).collect();
|
||||||
let bodies = blocks
|
let bodies = blocks
|
||||||
|
|||||||
@ -88,9 +88,8 @@ mod tests {
|
|||||||
PruneCheckpoint, PruneInterruptReason, PruneLimiter, PruneMode, PruneProgress, PruneSegment,
|
PruneCheckpoint, PruneInterruptReason, PruneLimiter, PruneMode, PruneProgress, PruneSegment,
|
||||||
};
|
};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_receipt, BlockRangeParams,
|
||||||
generators::{random_block_range, random_receipt},
|
|
||||||
};
|
};
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
|
|
||||||
@ -99,7 +98,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
1..=10,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 2..3, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
|
|
||||||
let mut receipts = Vec::new();
|
let mut receipts = Vec::new();
|
||||||
|
|||||||
@ -97,7 +97,7 @@ mod tests {
|
|||||||
PruneSegment, SegmentOutput,
|
PruneSegment, SegmentOutput,
|
||||||
};
|
};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{generators, generators::random_block_range};
|
use reth_testing_utils::generators::{self, random_block_range, BlockRangeParams};
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -105,7 +105,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 1..=100, B256::ZERO, 2..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
1..=100,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 2..3, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
|
|
||||||
let transactions = blocks.iter().flat_map(|block| &block.body).collect::<Vec<_>>();
|
let transactions = blocks.iter().flat_map(|block| &block.body).collect::<Vec<_>>();
|
||||||
|
|||||||
@ -140,9 +140,8 @@ mod tests {
|
|||||||
PruneCheckpoint, PruneInterruptReason, PruneLimiter, PruneMode, PruneProgress, PruneSegment,
|
PruneCheckpoint, PruneInterruptReason, PruneLimiter, PruneMode, PruneProgress, PruneSegment,
|
||||||
};
|
};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_changeset_range, random_eoa_accounts, BlockRangeParams,
|
||||||
generators::{random_block_range, random_changeset_range, random_eoa_accounts},
|
|
||||||
};
|
};
|
||||||
use std::{collections::BTreeMap, ops::AddAssign};
|
use std::{collections::BTreeMap, ops::AddAssign};
|
||||||
|
|
||||||
@ -151,7 +150,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 1..=5000, B256::ZERO, 0..1, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
1..=5000,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..1, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
|
|
||||||
let accounts = random_eoa_accounts(&mut rng, 2).into_iter().collect::<BTreeMap<_, _>>();
|
let accounts = random_eoa_accounts(&mut rng, 2).into_iter().collect::<BTreeMap<_, _>>();
|
||||||
|
|||||||
@ -227,9 +227,8 @@ mod tests {
|
|||||||
use reth_provider::{PruneCheckpointReader, TransactionsProvider};
|
use reth_provider::{PruneCheckpointReader, TransactionsProvider};
|
||||||
use reth_prune_types::{PruneLimiter, PruneMode, PruneSegment, ReceiptsLogPruneConfig};
|
use reth_prune_types::{PruneLimiter, PruneMode, PruneSegment, ReceiptsLogPruneConfig};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_eoa_account, random_log, random_receipt, BlockRangeParams,
|
||||||
generators::{random_block_range, random_eoa_account, random_log, random_receipt},
|
|
||||||
};
|
};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
@ -242,9 +241,21 @@ mod tests {
|
|||||||
|
|
||||||
let tip = 20000;
|
let tip = 20000;
|
||||||
let blocks = [
|
let blocks = [
|
||||||
random_block_range(&mut rng, 0..=100, B256::ZERO, 1..5, None, None),
|
random_block_range(
|
||||||
random_block_range(&mut rng, (100 + 1)..=(tip - 100), B256::ZERO, 0..1, None, None),
|
&mut rng,
|
||||||
random_block_range(&mut rng, (tip - 100 + 1)..=tip, B256::ZERO, 1..5, None, None),
|
0..=100,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 1..5, ..Default::default() },
|
||||||
|
),
|
||||||
|
random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
(100 + 1)..=(tip - 100),
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..1, ..Default::default() },
|
||||||
|
),
|
||||||
|
random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
(tip - 100 + 1)..=tip,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 1..5, ..Default::default() },
|
||||||
|
),
|
||||||
]
|
]
|
||||||
.concat();
|
.concat();
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
|
|||||||
@ -93,7 +93,7 @@ mod tests {
|
|||||||
use reth_provider::PruneCheckpointReader;
|
use reth_provider::PruneCheckpointReader;
|
||||||
use reth_prune_types::{PruneCheckpoint, PruneLimiter, PruneMode, PruneProgress, PruneSegment};
|
use reth_prune_types::{PruneCheckpoint, PruneLimiter, PruneMode, PruneProgress, PruneSegment};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{generators, generators::random_block_range};
|
use reth_testing_utils::generators::{self, random_block_range, BlockRangeParams};
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -101,7 +101,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
1..=10,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 2..3, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
|
|
||||||
let mut transaction_senders = Vec::new();
|
let mut transaction_senders = Vec::new();
|
||||||
|
|||||||
@ -146,9 +146,8 @@ mod tests {
|
|||||||
use reth_provider::PruneCheckpointReader;
|
use reth_provider::PruneCheckpointReader;
|
||||||
use reth_prune_types::{PruneCheckpoint, PruneLimiter, PruneMode, PruneProgress, PruneSegment};
|
use reth_prune_types::{PruneCheckpoint, PruneLimiter, PruneMode, PruneProgress, PruneSegment};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_changeset_range, random_eoa_accounts, BlockRangeParams,
|
||||||
generators::{random_block_range, random_changeset_range, random_eoa_accounts},
|
|
||||||
};
|
};
|
||||||
use std::{collections::BTreeMap, ops::AddAssign};
|
use std::{collections::BTreeMap, ops::AddAssign};
|
||||||
|
|
||||||
@ -157,7 +156,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 0..=5000, B256::ZERO, 0..1, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=5000,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..1, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
|
|
||||||
let accounts = random_eoa_accounts(&mut rng, 2).into_iter().collect::<BTreeMap<_, _>>();
|
let accounts = random_eoa_accounts(&mut rng, 2).into_iter().collect::<BTreeMap<_, _>>();
|
||||||
|
|||||||
@ -122,7 +122,7 @@ mod tests {
|
|||||||
PruneCheckpoint, PruneInterruptReason, PruneLimiter, PruneMode, PruneProgress, PruneSegment,
|
PruneCheckpoint, PruneInterruptReason, PruneLimiter, PruneMode, PruneProgress, PruneSegment,
|
||||||
};
|
};
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_testing_utils::{generators, generators::random_block_range};
|
use reth_testing_utils::generators::{self, random_block_range, BlockRangeParams};
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -130,7 +130,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
1..=10,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 2..3, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
|
|
||||||
let mut tx_hash_numbers = Vec::new();
|
let mut tx_hash_numbers = Vec::new();
|
||||||
|
|||||||
@ -925,7 +925,7 @@ mod tests {
|
|||||||
|
|
||||||
use reth_chainspec::MAINNET;
|
use reth_chainspec::MAINNET;
|
||||||
use reth_payload_builder::test_utils::spawn_test_payload_service;
|
use reth_payload_builder::test_utils::spawn_test_payload_service;
|
||||||
use reth_primitives::{SealedBlock, B256};
|
use reth_primitives::SealedBlock;
|
||||||
use reth_provider::test_utils::MockEthProvider;
|
use reth_provider::test_utils::MockEthProvider;
|
||||||
use reth_rpc_types::engine::{ClientCode, ClientVersionV1};
|
use reth_rpc_types::engine::{ClientCode, ClientVersionV1};
|
||||||
use reth_rpc_types_compat::engine::payload::execution_payload_from_sealed_block;
|
use reth_rpc_types_compat::engine::payload::execution_payload_from_sealed_block;
|
||||||
@ -995,7 +995,7 @@ mod tests {
|
|||||||
// tests covering `engine_getPayloadBodiesByRange` and `engine_getPayloadBodiesByHash`
|
// tests covering `engine_getPayloadBodiesByRange` and `engine_getPayloadBodiesByHash`
|
||||||
mod get_payload_bodies {
|
mod get_payload_bodies {
|
||||||
use super::*;
|
use super::*;
|
||||||
use reth_testing_utils::{generators, generators::random_block_range};
|
use reth_testing_utils::generators::{self, random_block_range, BlockRangeParams};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn invalid_params() {
|
async fn invalid_params() {
|
||||||
@ -1033,10 +1033,7 @@ mod tests {
|
|||||||
let blocks = random_block_range(
|
let blocks = random_block_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
start..=start + count - 1,
|
start..=start + count - 1,
|
||||||
B256::default(),
|
BlockRangeParams { tx_count: 0..2, ..Default::default() },
|
||||||
0..2,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
handle.provider.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal())));
|
handle.provider.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal())));
|
||||||
|
|
||||||
@ -1059,10 +1056,7 @@ mod tests {
|
|||||||
let blocks = random_block_range(
|
let blocks = random_block_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
start..=start + count - 1,
|
start..=start + count - 1,
|
||||||
B256::default(),
|
BlockRangeParams { tx_count: 0..2, ..Default::default() },
|
||||||
0..2,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Insert only blocks in ranges 1-25 and 50-75
|
// Insert only blocks in ranges 1-25 and 50-75
|
||||||
@ -1122,7 +1116,7 @@ mod tests {
|
|||||||
mod exchange_transition_configuration {
|
mod exchange_transition_configuration {
|
||||||
use super::*;
|
use super::*;
|
||||||
use reth_primitives::U256;
|
use reth_primitives::U256;
|
||||||
use reth_testing_utils::generators;
|
use reth_testing_utils::generators::{self, BlockParams};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn terminal_td_mismatch() {
|
async fn terminal_td_mismatch() {
|
||||||
@ -1155,9 +1149,9 @@ mod tests {
|
|||||||
|
|
||||||
let terminal_block_number = 1000;
|
let terminal_block_number = 1000;
|
||||||
let consensus_terminal_block =
|
let consensus_terminal_block =
|
||||||
random_block(&mut rng, terminal_block_number, None, None, None, None, None);
|
random_block(&mut rng, terminal_block_number, BlockParams::default());
|
||||||
let execution_terminal_block =
|
let execution_terminal_block =
|
||||||
random_block(&mut rng, terminal_block_number, None, None, None, None, None);
|
random_block(&mut rng, terminal_block_number, BlockParams::default());
|
||||||
|
|
||||||
let transition_config = TransitionConfiguration {
|
let transition_config = TransitionConfiguration {
|
||||||
terminal_total_difficulty: handle
|
terminal_total_difficulty: handle
|
||||||
@ -1198,15 +1192,8 @@ mod tests {
|
|||||||
let (handle, api) = setup_engine_api();
|
let (handle, api) = setup_engine_api();
|
||||||
|
|
||||||
let terminal_block_number = 1000;
|
let terminal_block_number = 1000;
|
||||||
let terminal_block = random_block(
|
let terminal_block =
|
||||||
&mut generators::rng(),
|
random_block(&mut generators::rng(), terminal_block_number, BlockParams::default());
|
||||||
terminal_block_number,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
let transition_config = TransitionConfiguration {
|
let transition_config = TransitionConfiguration {
|
||||||
terminal_total_difficulty: handle
|
terminal_total_difficulty: handle
|
||||||
|
|||||||
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
use alloy_rlp::{Decodable, Error as RlpError};
|
use alloy_rlp::{Decodable, Error as RlpError};
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use reth_primitives::{
|
use reth_primitives::{proofs, Block, Bytes, SealedBlock, TransactionSigned, Withdrawals, U256};
|
||||||
proofs, Block, Bytes, SealedBlock, TransactionSigned, Withdrawals, B256, U256,
|
|
||||||
};
|
|
||||||
use reth_rpc_types::engine::{
|
use reth_rpc_types::engine::{
|
||||||
ExecutionPayload, ExecutionPayloadBodyV1, ExecutionPayloadV1, PayloadError,
|
ExecutionPayload, ExecutionPayloadBodyV1, ExecutionPayloadV1, PayloadError,
|
||||||
};
|
};
|
||||||
@ -12,7 +10,9 @@ use reth_rpc_types_compat::engine::payload::{
|
|||||||
block_to_payload, block_to_payload_v1, convert_to_payload_body_v1, try_into_sealed_block,
|
block_to_payload, block_to_payload_v1, convert_to_payload_body_v1, try_into_sealed_block,
|
||||||
try_payload_v1_to_block,
|
try_payload_v1_to_block,
|
||||||
};
|
};
|
||||||
use reth_testing_utils::generators::{self, random_block, random_block_range, random_header, Rng};
|
use reth_testing_utils::generators::{
|
||||||
|
self, random_block, random_block_range, random_header, BlockParams, BlockRangeParams, Rng,
|
||||||
|
};
|
||||||
|
|
||||||
fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> ExecutionPayload {
|
fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> ExecutionPayload {
|
||||||
let unsealed = src.unseal();
|
let unsealed = src.unseal();
|
||||||
@ -32,7 +32,11 @@ fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> Executi
|
|||||||
#[test]
|
#[test]
|
||||||
fn payload_body_roundtrip() {
|
fn payload_body_roundtrip() {
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
for block in random_block_range(&mut rng, 0..=99, B256::default(), 0..2, None, None) {
|
for block in random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=99,
|
||||||
|
BlockRangeParams { tx_count: 0..2, ..Default::default() },
|
||||||
|
) {
|
||||||
let unsealed = block.clone().unseal();
|
let unsealed = block.clone().unseal();
|
||||||
let payload_body: ExecutionPayloadBodyV1 = convert_to_payload_body_v1(unsealed);
|
let payload_body: ExecutionPayloadBodyV1 = convert_to_payload_body_v1(unsealed);
|
||||||
|
|
||||||
@ -53,7 +57,16 @@ fn payload_body_roundtrip() {
|
|||||||
fn payload_validation() {
|
fn payload_validation() {
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let parent = rng.gen();
|
let parent = rng.gen();
|
||||||
let block = random_block(&mut rng, 100, Some(parent), Some(3), Some(0), None, None);
|
let block = random_block(
|
||||||
|
&mut rng,
|
||||||
|
100,
|
||||||
|
BlockParams {
|
||||||
|
parent: Some(parent),
|
||||||
|
tx_count: Some(3),
|
||||||
|
ommers_count: Some(0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Valid extra data
|
// Valid extra data
|
||||||
let block_with_valid_extra_data = transform_block(block.clone(), |mut b| {
|
let block_with_valid_extra_data = transform_block(block.clone(), |mut b| {
|
||||||
|
|||||||
@ -11,12 +11,9 @@ use reth_stages::{
|
|||||||
stages::{AccountHashingStage, StorageHashingStage},
|
stages::{AccountHashingStage, StorageHashingStage},
|
||||||
test_utils::{StorageKind, TestStageDB},
|
test_utils::{StorageKind, TestStageDB},
|
||||||
};
|
};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_changeset_range, random_contract_account_range,
|
||||||
generators::{
|
random_eoa_accounts, BlockRangeParams,
|
||||||
random_block_range, random_changeset_range, random_contract_account_range,
|
|
||||||
random_eoa_accounts,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use reth_trie::StateRoot;
|
use reth_trie::StateRoot;
|
||||||
use std::{collections::BTreeMap, fs, path::Path, sync::Arc};
|
use std::{collections::BTreeMap, fs, path::Path, sync::Arc};
|
||||||
@ -116,8 +113,15 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut blocks =
|
let mut blocks = random_block_range(
|
||||||
random_block_range(&mut rng, 0..=num_blocks, B256::ZERO, txs_range, None, None);
|
&mut rng,
|
||||||
|
0..=num_blocks,
|
||||||
|
BlockRangeParams {
|
||||||
|
parent: Some(B256::ZERO),
|
||||||
|
tx_count: txs_range,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let (transitions, start_state) = random_changeset_range(
|
let (transitions, start_state) = random_changeset_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
|
|||||||
@ -640,9 +640,8 @@ mod tests {
|
|||||||
StaticFileProviderFactory, TransactionsProvider,
|
StaticFileProviderFactory, TransactionsProvider,
|
||||||
};
|
};
|
||||||
use reth_stages_api::{ExecInput, ExecOutput, UnwindInput};
|
use reth_stages_api::{ExecInput, ExecOutput, UnwindInput};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_signed_tx, BlockRangeParams,
|
||||||
generators::{random_block_range, random_signed_tx},
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
@ -719,7 +718,15 @@ mod tests {
|
|||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
// Static files do not support gaps in headers, so we need to generate 0 to end
|
// Static files do not support gaps in headers, so we need to generate 0 to end
|
||||||
let blocks = random_block_range(&mut rng, 0..=end, GENESIS_HASH, 0..2, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=end,
|
||||||
|
BlockRangeParams {
|
||||||
|
parent: Some(GENESIS_HASH),
|
||||||
|
tx_count: 0..2,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
self.db.insert_headers_with_td(blocks.iter().map(|block| &block.header))?;
|
self.db.insert_headers_with_td(blocks.iter().map(|block| &block.header))?;
|
||||||
if let Some(progress) = blocks.get(start as usize) {
|
if let Some(progress) = blocks.get(start as usize) {
|
||||||
// Insert last progress data
|
// Insert last progress data
|
||||||
|
|||||||
@ -67,13 +67,16 @@ impl AccountHashingStage {
|
|||||||
use reth_provider::providers::StaticFileWriter;
|
use reth_provider::providers::StaticFileWriter;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::{
|
||||||
generators,
|
generators,
|
||||||
generators::{random_block_range, random_eoa_accounts},
|
generators::{random_block_range, random_eoa_accounts, BlockRangeParams},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks =
|
let blocks = random_block_range(
|
||||||
random_block_range(&mut rng, opts.blocks.clone(), B256::ZERO, opts.txs, None, None);
|
&mut rng,
|
||||||
|
opts.blocks.clone(),
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: opts.txs, ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
for block in blocks {
|
for block in blocks {
|
||||||
provider.insert_historical_block(block.try_seal_with_senders().unwrap()).unwrap();
|
provider.insert_historical_block(block.try_seal_with_senders().unwrap()).unwrap();
|
||||||
|
|||||||
@ -223,9 +223,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use reth_primitives::{Address, SealedBlock, U256};
|
use reth_primitives::{Address, SealedBlock, U256};
|
||||||
use reth_provider::providers::StaticFileWriter;
|
use reth_provider::providers::StaticFileWriter;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_contract_account_range, BlockRangeParams,
|
||||||
generators::{random_block_range, random_contract_account_range},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
stage_test_suite_ext!(StorageHashingTestRunner, storage_hashing);
|
stage_test_suite_ext!(StorageHashingTestRunner, storage_hashing);
|
||||||
@ -341,8 +340,11 @@ mod tests {
|
|||||||
let n_accounts = 31;
|
let n_accounts = 31;
|
||||||
let mut accounts = random_contract_account_range(&mut rng, &mut (0..n_accounts));
|
let mut accounts = random_contract_account_range(&mut rng, &mut (0..n_accounts));
|
||||||
|
|
||||||
let blocks =
|
let blocks = random_block_range(
|
||||||
random_block_range(&mut rng, stage_progress..=end, B256::ZERO, 0..3, None, None);
|
&mut rng,
|
||||||
|
stage_progress..=end,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..3, ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
self.db.insert_headers(blocks.iter().map(|block| &block.header))?;
|
self.db.insert_headers(blocks.iter().map(|block| &block.header))?;
|
||||||
|
|
||||||
|
|||||||
@ -158,9 +158,9 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use reth_primitives::{address, BlockNumber, B256};
|
use reth_primitives::{address, BlockNumber, B256};
|
||||||
use reth_provider::providers::StaticFileWriter;
|
use reth_provider::providers::StaticFileWriter;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_changeset_range, random_contract_account_range,
|
||||||
generators::{random_block_range, random_changeset_range, random_contract_account_range},
|
BlockRangeParams,
|
||||||
};
|
};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
@ -538,7 +538,11 @@ mod tests {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<BTreeMap<_, _>>();
|
.collect::<BTreeMap<_, _>>();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
start..=end,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..3, ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
let (changesets, _) = random_changeset_range(
|
let (changesets, _) = random_changeset_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
|
|||||||
@ -164,9 +164,9 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use reth_primitives::{address, b256, Address, BlockNumber, StorageEntry, B256, U256};
|
use reth_primitives::{address, b256, Address, BlockNumber, StorageEntry, B256, U256};
|
||||||
use reth_provider::providers::StaticFileWriter;
|
use reth_provider::providers::StaticFileWriter;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_changeset_range, random_contract_account_range,
|
||||||
generators::{random_block_range, random_changeset_range, random_contract_account_range},
|
BlockRangeParams,
|
||||||
};
|
};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
@ -560,7 +560,11 @@ mod tests {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<BTreeMap<_, _>>();
|
.collect::<BTreeMap<_, _>>();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
start..=end,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..3, ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
let (changesets, _) = random_changeset_range(
|
let (changesets, _) = random_changeset_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
|
|||||||
@ -370,11 +370,9 @@ mod tests {
|
|||||||
use reth_primitives::{keccak256, SealedBlock, StaticFileSegment, StorageEntry, U256};
|
use reth_primitives::{keccak256, SealedBlock, StaticFileSegment, StorageEntry, U256};
|
||||||
use reth_provider::{providers::StaticFileWriter, StaticFileProviderFactory};
|
use reth_provider::{providers::StaticFileWriter, StaticFileProviderFactory};
|
||||||
use reth_stages_api::StageUnitCheckpoint;
|
use reth_stages_api::StageUnitCheckpoint;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block, random_block_range, random_changeset_range,
|
||||||
generators::{
|
random_contract_account_range, BlockParams, BlockRangeParams,
|
||||||
random_block, random_block_range, random_changeset_range, random_contract_account_range,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use reth_trie::test_utils::{state_root, state_root_prehashed};
|
use reth_trie::test_utils::{state_root, state_root_prehashed};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
@ -499,10 +497,11 @@ mod tests {
|
|||||||
preblocks.append(&mut random_block_range(
|
preblocks.append(&mut random_block_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
0..=stage_progress - 1,
|
0..=stage_progress - 1,
|
||||||
B256::ZERO,
|
BlockRangeParams {
|
||||||
0..1,
|
parent: Some(B256::ZERO),
|
||||||
None,
|
tx_count: 0..1,
|
||||||
None,
|
..Default::default()
|
||||||
|
},
|
||||||
));
|
));
|
||||||
self.db.insert_blocks(preblocks.iter(), StorageKind::Static)?;
|
self.db.insert_blocks(preblocks.iter(), StorageKind::Static)?;
|
||||||
}
|
}
|
||||||
@ -519,11 +518,7 @@ mod tests {
|
|||||||
let SealedBlock { header, body, ommers, withdrawals, requests } = random_block(
|
let SealedBlock { header, body, ommers, withdrawals, requests } = random_block(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
stage_progress,
|
stage_progress,
|
||||||
preblocks.last().map(|b| b.hash()),
|
BlockParams { parent: preblocks.last().map(|b| b.hash()), ..Default::default() },
|
||||||
Some(0),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let mut header = header.unseal();
|
let mut header = header.unseal();
|
||||||
|
|
||||||
@ -538,7 +533,11 @@ mod tests {
|
|||||||
|
|
||||||
let head_hash = sealed_head.hash();
|
let head_hash = sealed_head.hash();
|
||||||
let mut blocks = vec![sealed_head];
|
let mut blocks = vec![sealed_head];
|
||||||
blocks.extend(random_block_range(&mut rng, start..=end, head_hash, 0..3, None, None));
|
blocks.extend(random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
start..=end,
|
||||||
|
BlockRangeParams { parent: Some(head_hash), tx_count: 0..3, ..Default::default() },
|
||||||
|
));
|
||||||
let last_block = blocks.last().cloned().unwrap();
|
let last_block = blocks.last().cloned().unwrap();
|
||||||
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,9 @@ mod tests {
|
|||||||
use reth_stages_api::{
|
use reth_stages_api::{
|
||||||
ExecInput, ExecutionStageThresholds, PipelineTarget, Stage, StageCheckpoint, StageId,
|
ExecInput, ExecutionStageThresholds, PipelineTarget, Stage, StageCheckpoint, StageId,
|
||||||
};
|
};
|
||||||
use reth_testing_utils::generators::{self, random_block, random_block_range, random_receipt};
|
use reth_testing_utils::generators::{
|
||||||
|
self, random_block, random_block_range, random_receipt, BlockRangeParams,
|
||||||
|
};
|
||||||
use std::{io::Write, sync::Arc};
|
use std::{io::Write, sync::Arc};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -94,8 +96,11 @@ mod tests {
|
|||||||
let mut head = block.hash();
|
let mut head = block.hash();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
for block_number in 2..=tip {
|
for block_number in 2..=tip {
|
||||||
let nblock =
|
let nblock = random_block(
|
||||||
random_block(&mut rng, block_number, Some(head), Some(0), Some(0), None, None);
|
&mut rng,
|
||||||
|
block_number,
|
||||||
|
generators::BlockParams { parent: Some(head), ..Default::default() },
|
||||||
|
);
|
||||||
head = nblock.hash();
|
head = nblock.hash();
|
||||||
provider_rw.insert_historical_block(nblock.try_seal_with_senders().unwrap()).unwrap();
|
provider_rw.insert_historical_block(nblock.try_seal_with_senders().unwrap()).unwrap();
|
||||||
}
|
}
|
||||||
@ -254,7 +259,11 @@ mod tests {
|
|||||||
let genesis_hash = B256::ZERO;
|
let genesis_hash = B256::ZERO;
|
||||||
let tip = (num_blocks - 1) as u64;
|
let tip = (num_blocks - 1) as u64;
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 0..=tip, genesis_hash, 2..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=tip,
|
||||||
|
BlockRangeParams { parent: Some(genesis_hash), tx_count: 2..3, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
||||||
|
|
||||||
let mut receipts = Vec::new();
|
let mut receipts = Vec::new();
|
||||||
|
|||||||
@ -165,7 +165,7 @@ mod tests {
|
|||||||
providers::StaticFileWriter, TransactionsProvider, TransactionsProviderExt,
|
providers::StaticFileWriter, TransactionsProvider, TransactionsProviderExt,
|
||||||
};
|
};
|
||||||
use reth_prune::PruneMode;
|
use reth_prune::PruneMode;
|
||||||
use reth_testing_utils::generators::{self, random_block_range};
|
use reth_testing_utils::generators::{self, random_block_range, BlockRangeParams};
|
||||||
|
|
||||||
stage_test_suite_ext!(PruneTestRunner, prune);
|
stage_test_suite_ext!(PruneTestRunner, prune);
|
||||||
|
|
||||||
@ -200,10 +200,7 @@ mod tests {
|
|||||||
let blocks = random_block_range(
|
let blocks = random_block_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
input.checkpoint().block_number..=input.target(),
|
input.checkpoint().block_number..=input.target(),
|
||||||
B256::ZERO,
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 1..3, ..Default::default() },
|
||||||
1..3,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
||||||
self.db.insert_transaction_senders(
|
self.db.insert_transaction_senders(
|
||||||
|
|||||||
@ -289,9 +289,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use reth_prune_types::{PruneCheckpoint, PruneMode};
|
use reth_prune_types::{PruneCheckpoint, PruneMode};
|
||||||
use reth_stages_api::StageUnitCheckpoint;
|
use reth_stages_api::StageUnitCheckpoint;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block, random_block_range, BlockParams, BlockRangeParams,
|
||||||
generators::{random_block, random_block_range},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -322,11 +321,10 @@ mod tests {
|
|||||||
random_block(
|
random_block(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
number,
|
number,
|
||||||
None,
|
BlockParams {
|
||||||
Some((number == non_empty_block_number) as u8),
|
tx_count: Some((number == non_empty_block_number) as u8),
|
||||||
None,
|
..Default::default()
|
||||||
None,
|
},
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -368,10 +366,7 @@ mod tests {
|
|||||||
let seed = random_block_range(
|
let seed = random_block_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
stage_progress + 1..=previous_stage,
|
stage_progress + 1..=previous_stage,
|
||||||
B256::ZERO,
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..4, ..Default::default() },
|
||||||
0..4,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
); // set tx count range high enough to hit the threshold
|
); // set tx count range high enough to hit the threshold
|
||||||
runner
|
runner
|
||||||
.db
|
.db
|
||||||
@ -442,7 +437,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 0..=100, B256::ZERO, 0..10, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=100,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..10, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Static).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Static).expect("insert blocks");
|
||||||
|
|
||||||
let max_pruned_block = 30;
|
let max_pruned_block = 30;
|
||||||
@ -555,8 +554,11 @@ mod tests {
|
|||||||
let stage_progress = input.checkpoint().block_number;
|
let stage_progress = input.checkpoint().block_number;
|
||||||
let end = input.target();
|
let end = input.target();
|
||||||
|
|
||||||
let blocks =
|
let blocks = random_block_range(
|
||||||
random_block_range(&mut rng, stage_progress..=end, B256::ZERO, 0..2, None, None);
|
&mut rng,
|
||||||
|
stage_progress..=end,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..2, ..Default::default() },
|
||||||
|
);
|
||||||
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
||||||
Ok(blocks)
|
Ok(blocks)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -245,9 +245,8 @@ mod tests {
|
|||||||
use reth_primitives::{BlockNumber, SealedBlock, B256};
|
use reth_primitives::{BlockNumber, SealedBlock, B256};
|
||||||
use reth_provider::{providers::StaticFileWriter, StaticFileProviderFactory};
|
use reth_provider::{providers::StaticFileWriter, StaticFileProviderFactory};
|
||||||
use reth_stages_api::StageUnitCheckpoint;
|
use reth_stages_api::StageUnitCheckpoint;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block, random_block_range, BlockParams, BlockRangeParams,
|
||||||
generators::{random_block, random_block_range},
|
|
||||||
};
|
};
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
|
|
||||||
@ -273,11 +272,10 @@ mod tests {
|
|||||||
random_block(
|
random_block(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
number,
|
number,
|
||||||
None,
|
BlockParams {
|
||||||
Some((number == non_empty_block_number) as u8),
|
tx_count: Some((number == non_empty_block_number) as u8),
|
||||||
None,
|
..Default::default()
|
||||||
None,
|
},
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -323,10 +321,7 @@ mod tests {
|
|||||||
let seed = random_block_range(
|
let seed = random_block_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
stage_progress + 1..=previous_stage,
|
stage_progress + 1..=previous_stage,
|
||||||
B256::ZERO,
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..2, ..Default::default() },
|
||||||
0..2,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
runner
|
runner
|
||||||
.db
|
.db
|
||||||
@ -361,7 +356,11 @@ mod tests {
|
|||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 0..=100, B256::ZERO, 0..10, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=100,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..10, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Static).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Static).expect("insert blocks");
|
||||||
|
|
||||||
let max_pruned_block = 30;
|
let max_pruned_block = 30;
|
||||||
@ -490,10 +489,7 @@ mod tests {
|
|||||||
let blocks = random_block_range(
|
let blocks = random_block_range(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
stage_progress + 1..=end,
|
stage_progress + 1..=end,
|
||||||
B256::ZERO,
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..2, ..Default::default() },
|
||||||
0..2,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;
|
||||||
Ok(blocks)
|
Ok(blocks)
|
||||||
|
|||||||
@ -265,9 +265,8 @@ mod tests {
|
|||||||
use reth_prune_types::PruneModes;
|
use reth_prune_types::PruneModes;
|
||||||
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
use reth_stages::test_utils::{StorageKind, TestStageDB};
|
||||||
use reth_static_file_types::{HighestStaticFiles, StaticFileSegment};
|
use reth_static_file_types::{HighestStaticFiles, StaticFileSegment};
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{
|
||||||
generators,
|
self, random_block_range, random_receipt, BlockRangeParams,
|
||||||
generators::{random_block_range, random_receipt},
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
sync::{mpsc::channel, Arc},
|
sync::{mpsc::channel, Arc},
|
||||||
@ -279,7 +278,11 @@ mod tests {
|
|||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let db = TestStageDB::default();
|
let db = TestStageDB::default();
|
||||||
|
|
||||||
let blocks = random_block_range(&mut rng, 0..=3, B256::ZERO, 2..3, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=3,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 2..3, ..Default::default() },
|
||||||
|
);
|
||||||
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
|
||||||
// Unwind headers from static_files and manually insert them into the database, so we're
|
// Unwind headers from static_files and manually insert them into the database, so we're
|
||||||
// able to check that static_file_producer works
|
// able to check that static_file_producer works
|
||||||
|
|||||||
@ -1468,7 +1468,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use reth_testing_utils::generators::{
|
use reth_testing_utils::generators::{
|
||||||
self, random_block, random_block_range, random_changeset_range, random_eoa_accounts,
|
self, random_block, random_block_range, random_changeset_range, random_eoa_accounts,
|
||||||
random_receipt, random_signed_tx,
|
random_receipt, random_signed_tx, BlockParams, BlockRangeParams,
|
||||||
};
|
};
|
||||||
use revm::db::BundleState;
|
use revm::db::BundleState;
|
||||||
|
|
||||||
@ -1485,10 +1485,12 @@ mod tests {
|
|||||||
let blocks = random_block_range(
|
let blocks = random_block_range(
|
||||||
rng,
|
rng,
|
||||||
0..=block_range,
|
0..=block_range,
|
||||||
B256::ZERO,
|
BlockRangeParams {
|
||||||
0..1,
|
parent: Some(B256::ZERO),
|
||||||
requests_count,
|
tx_count: 0..1,
|
||||||
withdrawals_count,
|
requests_count,
|
||||||
|
withdrawals_count,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
let (database_blocks, in_memory_blocks) = blocks.split_at(database_blocks);
|
let (database_blocks, in_memory_blocks) = blocks.split_at(database_blocks);
|
||||||
(database_blocks.to_vec(), in_memory_blocks.to_vec())
|
(database_blocks.to_vec(), in_memory_blocks.to_vec())
|
||||||
@ -1500,8 +1502,7 @@ mod tests {
|
|||||||
chain_spec: Arc<ChainSpec>,
|
chain_spec: Arc<ChainSpec>,
|
||||||
database_blocks: usize,
|
database_blocks: usize,
|
||||||
in_memory_blocks: usize,
|
in_memory_blocks: usize,
|
||||||
requests_count: Option<Range<u8>>,
|
block_range_params: BlockRangeParams,
|
||||||
withdrawals_count: Option<Range<u8>>,
|
|
||||||
) -> eyre::Result<(
|
) -> eyre::Result<(
|
||||||
BlockchainProvider2<Arc<TempDatabase<DatabaseEnv>>>,
|
BlockchainProvider2<Arc<TempDatabase<DatabaseEnv>>>,
|
||||||
Vec<SealedBlock>,
|
Vec<SealedBlock>,
|
||||||
@ -1512,8 +1513,8 @@ mod tests {
|
|||||||
rng,
|
rng,
|
||||||
database_blocks,
|
database_blocks,
|
||||||
in_memory_blocks,
|
in_memory_blocks,
|
||||||
requests_count,
|
block_range_params.requests_count,
|
||||||
withdrawals_count,
|
block_range_params.withdrawals_count,
|
||||||
);
|
);
|
||||||
let receipts: Vec<Vec<_>> = database_blocks
|
let receipts: Vec<Vec<_>> = database_blocks
|
||||||
.iter()
|
.iter()
|
||||||
@ -1585,8 +1586,7 @@ mod tests {
|
|||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
database_blocks: usize,
|
database_blocks: usize,
|
||||||
in_memory_blocks: usize,
|
in_memory_blocks: usize,
|
||||||
requests_count: Option<Range<u8>>,
|
block_range_params: BlockRangeParams,
|
||||||
withdrawals_count: Option<Range<u8>>,
|
|
||||||
) -> eyre::Result<(
|
) -> eyre::Result<(
|
||||||
BlockchainProvider2<Arc<TempDatabase<DatabaseEnv>>>,
|
BlockchainProvider2<Arc<TempDatabase<DatabaseEnv>>>,
|
||||||
Vec<SealedBlock>,
|
Vec<SealedBlock>,
|
||||||
@ -1598,8 +1598,7 @@ mod tests {
|
|||||||
MAINNET.clone(),
|
MAINNET.clone(),
|
||||||
database_blocks,
|
database_blocks,
|
||||||
in_memory_blocks,
|
in_memory_blocks,
|
||||||
requests_count,
|
block_range_params,
|
||||||
withdrawals_count,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1610,7 +1609,11 @@ mod tests {
|
|||||||
let factory = create_test_provider_factory();
|
let factory = create_test_provider_factory();
|
||||||
|
|
||||||
// Generate 10 random blocks and split into database and in-memory blocks
|
// Generate 10 random blocks and split into database and in-memory blocks
|
||||||
let blocks = random_block_range(&mut rng, 0..=10, B256::ZERO, 0..1, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=10,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..1, ..Default::default() },
|
||||||
|
);
|
||||||
let (database_blocks, in_memory_blocks) = blocks.split_at(5);
|
let (database_blocks, in_memory_blocks) = blocks.split_at(5);
|
||||||
|
|
||||||
// Insert first 5 blocks into the database
|
// Insert first 5 blocks into the database
|
||||||
@ -1704,7 +1707,11 @@ mod tests {
|
|||||||
let factory = create_test_provider_factory();
|
let factory = create_test_provider_factory();
|
||||||
|
|
||||||
// Generate 10 random blocks and split into database and in-memory blocks
|
// Generate 10 random blocks and split into database and in-memory blocks
|
||||||
let blocks = random_block_range(&mut rng, 0..=10, B256::ZERO, 0..1, None, None);
|
let blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=10,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..1, ..Default::default() },
|
||||||
|
);
|
||||||
let (database_blocks, in_memory_blocks) = blocks.split_at(5);
|
let (database_blocks, in_memory_blocks) = blocks.split_at(5);
|
||||||
|
|
||||||
// Insert first 5 blocks into the database
|
// Insert first 5 blocks into the database
|
||||||
@ -1772,13 +1779,16 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Generate a random block
|
// Generate a random block
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let block = random_block(&mut rng, 0, Some(B256::ZERO), None, None, None, None);
|
let block = random_block(
|
||||||
|
&mut rng,
|
||||||
|
0,
|
||||||
|
BlockParams { parent: Some(B256::ZERO), ..Default::default() },
|
||||||
|
);
|
||||||
|
|
||||||
// Set the block as pending
|
// Set the block as pending
|
||||||
provider.canonical_in_memory_state.set_pending_block(ExecutedBlock {
|
provider.canonical_in_memory_state.set_pending_block(ExecutedBlock {
|
||||||
@ -1813,8 +1823,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let first_in_mem_block = in_memory_blocks.first().unwrap();
|
let first_in_mem_block = in_memory_blocks.first().unwrap();
|
||||||
@ -1850,7 +1859,11 @@ mod tests {
|
|||||||
let factory = create_test_provider_factory();
|
let factory = create_test_provider_factory();
|
||||||
|
|
||||||
// Generate 10 random blocks and split them into database and in-memory blocks
|
// Generate 10 random blocks and split them into database and in-memory blocks
|
||||||
let mut blocks = random_block_range(&mut rng, 0..=10, B256::ZERO, 0..1, None, None);
|
let mut blocks = random_block_range(
|
||||||
|
&mut rng,
|
||||||
|
0..=10,
|
||||||
|
BlockRangeParams { parent: Some(B256::ZERO), tx_count: 0..1, ..Default::default() },
|
||||||
|
);
|
||||||
let (database_blocks, in_memory_blocks) = blocks.split_at_mut(5);
|
let (database_blocks, in_memory_blocks) = blocks.split_at_mut(5);
|
||||||
|
|
||||||
// Take the first in-memory block and add 7 ommers to it
|
// Take the first in-memory block and add 7 ommers to it
|
||||||
@ -1931,8 +1944,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first in-memory block
|
// Get the first in-memory block
|
||||||
@ -1956,8 +1968,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first in-memory block
|
// Get the first in-memory block
|
||||||
@ -1987,8 +1998,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first database block
|
// Get the first database block
|
||||||
@ -2012,8 +2022,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first database block
|
// Get the first database block
|
||||||
@ -2040,8 +2049,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Generate a random hash (non-existent block)
|
// Generate a random hash (non-existent block)
|
||||||
@ -2072,8 +2080,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first in-memory block
|
// Get the first in-memory block
|
||||||
@ -2101,8 +2108,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first in-memory block
|
// Get the first in-memory block
|
||||||
@ -2129,8 +2135,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first database block
|
// Get the first database block
|
||||||
@ -2158,8 +2163,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the first database block
|
// Get the first database block
|
||||||
@ -2187,8 +2191,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Generate a random hash (non-existent block)
|
// Generate a random hash (non-existent block)
|
||||||
@ -2219,8 +2222,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the range of in-memory blocks
|
// Get the range of in-memory blocks
|
||||||
@ -2247,8 +2249,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
0, // No blocks in memory
|
0, // No blocks in memory
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the range of database blocks
|
// Get the range of database blocks
|
||||||
@ -2276,8 +2277,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
mid_point,
|
mid_point,
|
||||||
TEST_BLOCKS_COUNT - mid_point,
|
TEST_BLOCKS_COUNT - mid_point,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the range of blocks across memory and database
|
// Get the range of blocks across memory and database
|
||||||
@ -2306,8 +2306,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Generate a non-existent range
|
// Generate a non-existent range
|
||||||
@ -2324,8 +2323,12 @@ mod tests {
|
|||||||
fn test_block_range_partial_overlap() -> eyre::Result<()> {
|
fn test_block_range_partial_overlap() -> eyre::Result<()> {
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let mid_point = TEST_BLOCKS_COUNT / 2;
|
let mid_point = TEST_BLOCKS_COUNT / 2;
|
||||||
let (provider, database_blocks, in_memory_blocks, _) =
|
let (provider, database_blocks, in_memory_blocks, _) = provider_with_random_blocks(
|
||||||
provider_with_random_blocks(&mut rng, mid_point, mid_point, None, None)?;
|
&mut rng,
|
||||||
|
mid_point,
|
||||||
|
mid_point,
|
||||||
|
BlockRangeParams::default(),
|
||||||
|
)?;
|
||||||
|
|
||||||
// Get the range of blocks across memory and database
|
// Get the range of blocks across memory and database
|
||||||
let start_block_number = database_blocks.last().unwrap().number;
|
let start_block_number = database_blocks.last().unwrap().number;
|
||||||
@ -2349,8 +2352,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
mid_point,
|
mid_point,
|
||||||
TEST_BLOCKS_COUNT - mid_point,
|
TEST_BLOCKS_COUNT - mid_point,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the range of blocks across memory and database
|
// Get the range of blocks across memory and database
|
||||||
@ -2390,8 +2392,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the range of in-memory blocks
|
// Get the range of in-memory blocks
|
||||||
@ -2426,8 +2427,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_block_with_senders_range_only_in_database() -> eyre::Result<()> {
|
fn test_block_with_senders_range_only_in_database() -> eyre::Result<()> {
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let (provider, database_blocks, _, _) =
|
let (provider, database_blocks, _, _) = provider_with_random_blocks(
|
||||||
provider_with_random_blocks(&mut rng, TEST_BLOCKS_COUNT, 0, None, None)?;
|
&mut rng,
|
||||||
|
TEST_BLOCKS_COUNT,
|
||||||
|
0,
|
||||||
|
BlockRangeParams::default(),
|
||||||
|
)?;
|
||||||
|
|
||||||
// Get the range of database blocks
|
// Get the range of database blocks
|
||||||
let start_block_number = database_blocks.first().unwrap().number;
|
let start_block_number = database_blocks.first().unwrap().number;
|
||||||
@ -2465,8 +2470,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Assuming this range does not exist
|
// Assuming this range does not exist
|
||||||
@ -2490,8 +2494,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
mid_point,
|
mid_point,
|
||||||
TEST_BLOCKS_COUNT - mid_point,
|
TEST_BLOCKS_COUNT - mid_point,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the range of blocks across memory and database
|
// Get the range of blocks across memory and database
|
||||||
@ -2537,8 +2540,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the range of in-memory blocks
|
// Get the range of in-memory blocks
|
||||||
@ -2579,8 +2581,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_sealed_block_with_senders_range_only_in_database() -> eyre::Result<()> {
|
fn test_sealed_block_with_senders_range_only_in_database() -> eyre::Result<()> {
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let (provider, database_blocks, _, _) =
|
let (provider, database_blocks, _, _) = provider_with_random_blocks(
|
||||||
provider_with_random_blocks(&mut rng, TEST_BLOCKS_COUNT, 0, None, None)?;
|
&mut rng,
|
||||||
|
TEST_BLOCKS_COUNT,
|
||||||
|
0,
|
||||||
|
BlockRangeParams::default(),
|
||||||
|
)?;
|
||||||
|
|
||||||
// Get the range of database blocks
|
// Get the range of database blocks
|
||||||
let start_block_number = database_blocks.first().unwrap().number;
|
let start_block_number = database_blocks.first().unwrap().number;
|
||||||
@ -2624,8 +2630,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Assuming this range does not exist
|
// Assuming this range does not exist
|
||||||
@ -2648,8 +2653,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -2677,8 +2681,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -2794,8 +2797,7 @@ mod tests {
|
|||||||
chain_spec.clone(),
|
chain_spec.clone(),
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams { withdrawals_count: Some(1..3), ..Default::default() },
|
||||||
Some(1..3),
|
|
||||||
)?;
|
)?;
|
||||||
let blocks = [database_blocks, in_memory_blocks].concat();
|
let blocks = [database_blocks, in_memory_blocks].concat();
|
||||||
|
|
||||||
@ -2845,8 +2847,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
assert_eq!(provider.best_block_number()?, in_memory_blocks.last().unwrap().number);
|
assert_eq!(provider.best_block_number()?, in_memory_blocks.last().unwrap().number);
|
||||||
@ -2867,8 +2868,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -2907,8 +2907,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -2965,8 +2964,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -3024,8 +3022,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -3065,8 +3062,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -3106,8 +3102,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -3263,8 +3258,7 @@ mod tests {
|
|||||||
chain_spec.clone(),
|
chain_spec.clone(),
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
Some(1..2),
|
BlockRangeParams { requests_count: Some(1..2), ..Default::default() },
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let database_block = database_blocks.first().unwrap().clone();
|
let database_block = database_blocks.first().unwrap().clone();
|
||||||
@ -3292,8 +3286,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let before = Instant::now();
|
let before = Instant::now();
|
||||||
@ -3323,8 +3316,7 @@ mod tests {
|
|||||||
&mut rng,
|
&mut rng,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
TEST_BLOCKS_COUNT,
|
TEST_BLOCKS_COUNT,
|
||||||
None,
|
BlockRangeParams::default(),
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Set the pending block in memory
|
// Set the pending block in memory
|
||||||
|
|||||||
@ -622,10 +622,7 @@ mod tests {
|
|||||||
use reth_primitives::{StaticFileSegment, TxNumber, B256, U256};
|
use reth_primitives::{StaticFileSegment, TxNumber, B256, U256};
|
||||||
use reth_prune_types::{PruneMode, PruneModes};
|
use reth_prune_types::{PruneMode, PruneModes};
|
||||||
use reth_storage_errors::provider::ProviderError;
|
use reth_storage_errors::provider::ProviderError;
|
||||||
use reth_testing_utils::{
|
use reth_testing_utils::generators::{self, random_block, random_header, BlockParams};
|
||||||
generators,
|
|
||||||
generators::{random_block, random_header},
|
|
||||||
};
|
|
||||||
use std::{ops::RangeInclusive, sync::Arc};
|
use std::{ops::RangeInclusive, sync::Arc};
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
@ -713,7 +710,8 @@ mod tests {
|
|||||||
let factory = create_test_provider_factory();
|
let factory = create_test_provider_factory();
|
||||||
|
|
||||||
let mut rng = generators::rng();
|
let mut rng = generators::rng();
|
||||||
let block = random_block(&mut rng, 0, None, Some(3), None, None, None);
|
let block =
|
||||||
|
random_block(&mut rng, 0, BlockParams { tx_count: Some(3), ..Default::default() });
|
||||||
|
|
||||||
let tx_ranges: Vec<RangeInclusive<TxNumber>> = vec![0..=0, 1..=1, 2..=2, 0..=1, 1..=2];
|
let tx_ranges: Vec<RangeInclusive<TxNumber>> = vec![0..=0, 1..=1, 2..=2, 0..=1, 1..=2];
|
||||||
for range in tx_ranges {
|
for range in tx_ranges {
|
||||||
|
|||||||
@ -20,6 +20,36 @@ use std::{
|
|||||||
ops::{Range, RangeInclusive},
|
ops::{Range, RangeInclusive},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Used to pass arguments for random block generation function in tests
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct BlockParams {
|
||||||
|
/// The parent hash of the block.
|
||||||
|
pub parent: Option<B256>,
|
||||||
|
/// The number of transactions in the block.
|
||||||
|
pub tx_count: Option<u8>,
|
||||||
|
/// The number of ommers (uncles) in the block.
|
||||||
|
pub ommers_count: Option<u8>,
|
||||||
|
/// The number of requests in the block.
|
||||||
|
pub requests_count: Option<u8>,
|
||||||
|
/// The number of withdrawals in the block.
|
||||||
|
pub withdrawals_count: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Used to pass arguments for random block generation function in tests
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct BlockRangeParams {
|
||||||
|
/// The parent hash of the block.
|
||||||
|
pub parent: Option<B256>,
|
||||||
|
/// The range of transactions in the block.
|
||||||
|
/// If set, a random count between the range will be used.
|
||||||
|
/// If not set, a random number of transactions will be used.
|
||||||
|
pub tx_count: Range<u8>,
|
||||||
|
/// The number of requests in the block.
|
||||||
|
pub requests_count: Option<Range<u8>>,
|
||||||
|
/// The number of withdrawals in the block.
|
||||||
|
pub withdrawals_count: Option<Range<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a random number generator that can be seeded using the `SEED` environment variable.
|
/// Returns a random number generator that can be seeded using the `SEED` environment variable.
|
||||||
///
|
///
|
||||||
/// If `SEED` is not set, a random seed is used.
|
/// If `SEED` is not set, a random seed is used.
|
||||||
@ -131,35 +161,29 @@ pub fn generate_keys<R: Rng>(rng: &mut R, count: usize) -> Vec<Keypair> {
|
|||||||
/// transactions in the block.
|
/// transactions in the block.
|
||||||
///
|
///
|
||||||
/// The ommer headers are not assumed to be valid.
|
/// The ommer headers are not assumed to be valid.
|
||||||
pub fn random_block<R: Rng>(
|
pub fn random_block<R: Rng>(rng: &mut R, number: u64, block_params: BlockParams) -> SealedBlock {
|
||||||
rng: &mut R,
|
|
||||||
number: u64,
|
|
||||||
parent: Option<B256>,
|
|
||||||
tx_count: Option<u8>,
|
|
||||||
ommers_count: Option<u8>,
|
|
||||||
requests_count: Option<u8>,
|
|
||||||
withdrawals_count: Option<u8>,
|
|
||||||
) -> SealedBlock {
|
|
||||||
// Generate transactions
|
// Generate transactions
|
||||||
let tx_count = tx_count.unwrap_or_else(|| rng.gen::<u8>());
|
let tx_count = block_params.tx_count.unwrap_or_else(|| rng.gen::<u8>());
|
||||||
let transactions: Vec<TransactionSigned> =
|
let transactions: Vec<TransactionSigned> =
|
||||||
(0..tx_count).map(|_| random_signed_tx(rng)).collect();
|
(0..tx_count).map(|_| random_signed_tx(rng)).collect();
|
||||||
let total_gas = transactions.iter().fold(0, |sum, tx| sum + tx.transaction.gas_limit());
|
let total_gas = transactions.iter().fold(0, |sum, tx| sum + tx.transaction.gas_limit());
|
||||||
|
|
||||||
// Generate ommers
|
// Generate ommers
|
||||||
let ommers_count = ommers_count.unwrap_or_else(|| rng.gen_range(0..2));
|
let ommers_count = block_params.ommers_count.unwrap_or_else(|| rng.gen_range(0..2));
|
||||||
let ommers =
|
let ommers = (0..ommers_count)
|
||||||
(0..ommers_count).map(|_| random_header(rng, number, parent).unseal()).collect::<Vec<_>>();
|
.map(|_| random_header(rng, number, block_params.parent).unseal())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// Calculate roots
|
// Calculate roots
|
||||||
let transactions_root = proofs::calculate_transaction_root(&transactions);
|
let transactions_root = proofs::calculate_transaction_root(&transactions);
|
||||||
let ommers_hash = proofs::calculate_ommers_root(&ommers);
|
let ommers_hash = proofs::calculate_ommers_root(&ommers);
|
||||||
|
|
||||||
let requests =
|
let requests = block_params
|
||||||
requests_count.map(|count| (0..count).map(|_| random_request(rng)).collect::<Vec<_>>());
|
.requests_count
|
||||||
|
.map(|count| (0..count).map(|_| random_request(rng)).collect::<Vec<_>>());
|
||||||
let requests_root = requests.as_ref().map(|requests| proofs::calculate_requests_root(requests));
|
let requests_root = requests.as_ref().map(|requests| proofs::calculate_requests_root(requests));
|
||||||
|
|
||||||
let withdrawals = withdrawals_count.map(|count| {
|
let withdrawals = block_params.withdrawals_count.map(|count| {
|
||||||
(0..count)
|
(0..count)
|
||||||
.map(|i| Withdrawal {
|
.map(|i| Withdrawal {
|
||||||
amount: rng.gen(),
|
amount: rng.gen(),
|
||||||
@ -173,7 +197,7 @@ pub fn random_block<R: Rng>(
|
|||||||
|
|
||||||
SealedBlock {
|
SealedBlock {
|
||||||
header: Header {
|
header: Header {
|
||||||
parent_hash: parent.unwrap_or_default(),
|
parent_hash: block_params.parent.unwrap_or_default(),
|
||||||
number,
|
number,
|
||||||
gas_used: total_gas,
|
gas_used: total_gas,
|
||||||
gas_limit: total_gas,
|
gas_limit: total_gas,
|
||||||
@ -201,25 +225,29 @@ pub fn random_block<R: Rng>(
|
|||||||
pub fn random_block_range<R: Rng>(
|
pub fn random_block_range<R: Rng>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
block_numbers: RangeInclusive<BlockNumber>,
|
block_numbers: RangeInclusive<BlockNumber>,
|
||||||
head: B256,
|
block_range_params: BlockRangeParams,
|
||||||
tx_count: Range<u8>,
|
|
||||||
requests_count: Option<Range<u8>>,
|
|
||||||
withdrawals_count: Option<Range<u8>>,
|
|
||||||
) -> Vec<SealedBlock> {
|
) -> Vec<SealedBlock> {
|
||||||
let mut blocks =
|
let mut blocks =
|
||||||
Vec::with_capacity(block_numbers.end().saturating_sub(*block_numbers.start()) as usize);
|
Vec::with_capacity(block_numbers.end().saturating_sub(*block_numbers.start()) as usize);
|
||||||
for idx in block_numbers {
|
for idx in block_numbers {
|
||||||
let tx_count = tx_count.clone().sample_single(rng);
|
let tx_count = block_range_params.tx_count.clone().sample_single(rng);
|
||||||
let requests_count = requests_count.clone().map(|r| r.sample_single(rng));
|
let requests_count =
|
||||||
let withdrawals_count = withdrawals_count.clone().map(|r| r.sample_single(rng));
|
block_range_params.requests_count.clone().map(|r| r.sample_single(rng));
|
||||||
|
let withdrawals_count =
|
||||||
|
block_range_params.withdrawals_count.clone().map(|r| r.sample_single(rng));
|
||||||
|
let parent = block_range_params.parent.unwrap_or_default();
|
||||||
blocks.push(random_block(
|
blocks.push(random_block(
|
||||||
rng,
|
rng,
|
||||||
idx,
|
idx,
|
||||||
Some(blocks.last().map(|block: &SealedBlock| block.header.hash()).unwrap_or(head)),
|
BlockParams {
|
||||||
Some(tx_count),
|
parent: Some(
|
||||||
None,
|
blocks.last().map(|block: &SealedBlock| block.header.hash()).unwrap_or(parent),
|
||||||
requests_count,
|
),
|
||||||
withdrawals_count,
|
tx_count: Some(tx_count),
|
||||||
|
ommers_count: None,
|
||||||
|
requests_count,
|
||||||
|
withdrawals_count,
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
blocks
|
blocks
|
||||||
|
|||||||
Reference in New Issue
Block a user