mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: make block field private (#13628)
This commit is contained in:
@ -882,7 +882,7 @@ mod tests {
|
||||
let receipts: Vec<Vec<_>> = database_blocks
|
||||
.iter()
|
||||
.chain(in_memory_blocks.iter())
|
||||
.map(|block| block.body.transactions.iter())
|
||||
.map(|block| block.body().transactions.iter())
|
||||
.map(|tx| tx.map(|tx| random_receipt(rng, tx, Some(2))).collect())
|
||||
.collect();
|
||||
|
||||
@ -1253,11 +1253,11 @@ mod tests {
|
||||
// First in memory block ommers should be found
|
||||
assert_eq!(
|
||||
provider.ommers(first_in_mem_block.number.into())?,
|
||||
Some(first_in_mem_block.body.ommers.clone())
|
||||
Some(first_in_mem_block.body().ommers.clone())
|
||||
);
|
||||
assert_eq!(
|
||||
provider.ommers(first_in_mem_block.hash().into())?,
|
||||
Some(first_in_mem_block.body.ommers.clone())
|
||||
Some(first_in_mem_block.body().ommers.clone())
|
||||
);
|
||||
|
||||
// A random hash should return None as the block number is not found
|
||||
@ -1468,7 +1468,7 @@ mod tests {
|
||||
shainghai_timestamp
|
||||
)?
|
||||
.unwrap(),
|
||||
block.body.withdrawals.unwrap(),
|
||||
block.body().withdrawals.clone().unwrap(),
|
||||
"Expected withdrawals_by_block to return correct withdrawals"
|
||||
);
|
||||
}
|
||||
@ -1478,7 +1478,7 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
Some(provider.latest_withdrawal()?.unwrap()),
|
||||
canonical_block.body.withdrawals.clone().unwrap().pop(),
|
||||
canonical_block.body().withdrawals.clone().unwrap().pop(),
|
||||
"Expected latest withdrawal to be equal to last withdrawal entry in canonical block"
|
||||
);
|
||||
|
||||
@ -1675,11 +1675,11 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
provider.ommers_by_id(block_number.into()).unwrap().unwrap_or_default(),
|
||||
database_block.body.ommers
|
||||
database_block.body().ommers
|
||||
);
|
||||
assert_eq!(
|
||||
provider.ommers_by_id(block_hash.into()).unwrap().unwrap_or_default(),
|
||||
database_block.body.ommers
|
||||
database_block.body().ommers
|
||||
);
|
||||
|
||||
let block_number = in_memory_block.number;
|
||||
@ -1687,11 +1687,11 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
provider.ommers_by_id(block_number.into()).unwrap().unwrap_or_default(),
|
||||
in_memory_block.body.ommers
|
||||
in_memory_block.body().ommers
|
||||
);
|
||||
assert_eq!(
|
||||
provider.ommers_by_id(block_hash.into()).unwrap().unwrap_or_default(),
|
||||
in_memory_block.body.ommers
|
||||
in_memory_block.body().ommers
|
||||
);
|
||||
|
||||
Ok(())
|
||||
@ -2168,9 +2168,9 @@ mod tests {
|
||||
$(
|
||||
// Since data moves for each tried method, need to recalculate everything
|
||||
let db_tx_count =
|
||||
database_blocks.iter().map(|b| b.body.transactions.len()).sum::<usize>() as u64;
|
||||
database_blocks.iter().map(|b| b.body().transactions.len()).sum::<usize>() as u64;
|
||||
let in_mem_tx_count =
|
||||
in_memory_blocks.iter().map(|b| b.body.transactions.len()).sum::<usize>() as u64;
|
||||
in_memory_blocks.iter().map(|b| b.body().transactions.len()).sum::<usize>() as u64;
|
||||
|
||||
let db_range = 0..=(db_tx_count - 1);
|
||||
let in_mem_range = db_tx_count..=(in_mem_tx_count + db_range.end());
|
||||
@ -2249,7 +2249,7 @@ mod tests {
|
||||
.senders()
|
||||
.unwrap()),
|
||||
(transactions_by_tx_range, |block: &SealedBlock, _: &Vec<Vec<Receipt>>| block
|
||||
.body
|
||||
.body()
|
||||
.transactions
|
||||
.clone()),
|
||||
(receipts_by_tx_range, |block: &SealedBlock, receipts: &Vec<Vec<Receipt>>| receipts
|
||||
@ -2348,7 +2348,7 @@ mod tests {
|
||||
(sealed_block_with_senders_range, |block: &SealedBlock| block
|
||||
.clone()
|
||||
.with_senders_unchecked(vec![])),
|
||||
(transactions_by_block_range, |block: &SealedBlock| block.body.transactions.clone()),
|
||||
(transactions_by_block_range, |block: &SealedBlock| block.body().transactions.clone()),
|
||||
]);
|
||||
|
||||
Ok(())
|
||||
@ -2405,13 +2405,13 @@ mod tests {
|
||||
let mut in_memory_blocks: std::collections::VecDeque<_> = in_memory_blocks.into();
|
||||
|
||||
$(
|
||||
let tx_hash = |block: &SealedBlock| block.body.transactions[0].hash();
|
||||
let tx_hash = |block: &SealedBlock| block.body().transactions[0].hash();
|
||||
let tx_num = |block: &SealedBlock| {
|
||||
database_blocks
|
||||
.iter()
|
||||
.chain(in_memory_blocks.iter())
|
||||
.take_while(|b| b.number < block.number)
|
||||
.map(|b| b.body.transactions.len())
|
||||
.map(|b| b.body().transactions.len())
|
||||
.sum::<usize>() as u64
|
||||
};
|
||||
|
||||
@ -2432,7 +2432,7 @@ mod tests {
|
||||
.iter()
|
||||
.chain(in_memory_blocks.iter())
|
||||
.take_while(|b| b.number < block.number)
|
||||
.map(|b| b.body.transactions.len())
|
||||
.map(|b| b.body().transactions.len())
|
||||
.sum::<usize>() as u64
|
||||
};
|
||||
|
||||
@ -2528,7 +2528,7 @@ mod tests {
|
||||
block.number,
|
||||
Some(StoredBlockBodyIndices {
|
||||
first_tx_num: tx_num,
|
||||
tx_count: block.body.transactions.len() as u64
|
||||
tx_count: block.body().transactions.len() as u64
|
||||
})
|
||||
),
|
||||
u64::MAX
|
||||
@ -2597,7 +2597,7 @@ mod tests {
|
||||
transaction_by_id,
|
||||
|block: &SealedBlock, tx_num: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
|
||||
tx_num,
|
||||
Some(block.body.transactions[test_tx_index].clone())
|
||||
Some(block.body().transactions[test_tx_index].clone())
|
||||
),
|
||||
u64::MAX
|
||||
),
|
||||
@ -2606,7 +2606,7 @@ mod tests {
|
||||
transaction_by_id_unhashed,
|
||||
|block: &SealedBlock, tx_num: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
|
||||
tx_num,
|
||||
Some(block.body.transactions[test_tx_index].clone())
|
||||
Some(block.body().transactions[test_tx_index].clone())
|
||||
),
|
||||
u64::MAX
|
||||
),
|
||||
@ -2615,7 +2615,7 @@ mod tests {
|
||||
transaction_by_hash,
|
||||
|block: &SealedBlock, _: TxNumber, tx_hash: B256, _: &Vec<Vec<Receipt>>| (
|
||||
tx_hash,
|
||||
Some(block.body.transactions[test_tx_index].clone())
|
||||
Some(block.body().transactions[test_tx_index].clone())
|
||||
),
|
||||
B256::random()
|
||||
),
|
||||
@ -2633,7 +2633,7 @@ mod tests {
|
||||
transactions_by_block,
|
||||
|block: &SealedBlock, _: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
|
||||
BlockHashOrNumber::Number(block.number),
|
||||
Some(block.body.transactions.clone())
|
||||
Some(block.body().transactions.clone())
|
||||
),
|
||||
BlockHashOrNumber::Number(u64::MAX)
|
||||
),
|
||||
@ -2642,7 +2642,7 @@ mod tests {
|
||||
transactions_by_block,
|
||||
|block: &SealedBlock, _: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
|
||||
BlockHashOrNumber::Hash(block.hash()),
|
||||
Some(block.body.transactions.clone())
|
||||
Some(block.body().transactions.clone())
|
||||
),
|
||||
BlockHashOrNumber::Number(u64::MAX)
|
||||
),
|
||||
@ -2651,7 +2651,7 @@ mod tests {
|
||||
transaction_sender,
|
||||
|block: &SealedBlock, tx_num: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
|
||||
tx_num,
|
||||
block.body.transactions[test_tx_index].recover_signer()
|
||||
block.body().transactions[test_tx_index].recover_signer()
|
||||
),
|
||||
u64::MAX
|
||||
),
|
||||
@ -2737,7 +2737,7 @@ mod tests {
|
||||
// This will persist block 1 AFTER a database is created. Moving it from memory to
|
||||
// storage.
|
||||
persist_block_after_db_tx_creation(provider.clone(), in_memory_blocks[0].number);
|
||||
let to_be_persisted_tx = in_memory_blocks[0].body.transactions[0].clone();
|
||||
let to_be_persisted_tx = in_memory_blocks[0].body().transactions[0].clone();
|
||||
|
||||
// Even though the block exists, given the order of provider queries done in the method
|
||||
// above, we do not see it.
|
||||
@ -2756,7 +2756,7 @@ mod tests {
|
||||
// This will persist block 1 AFTER a database is created. Moving it from memory to
|
||||
// storage.
|
||||
persist_block_after_db_tx_creation(provider.clone(), in_memory_blocks[1].number);
|
||||
let to_be_persisted_tx = in_memory_blocks[1].body.transactions[0].clone();
|
||||
let to_be_persisted_tx = in_memory_blocks[1].body().transactions[0].clone();
|
||||
|
||||
assert_eq!(
|
||||
correct_transaction_hash_fn(
|
||||
|
||||
@ -444,7 +444,7 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
|
||||
let (start, end) = self.convert_range_bounds(range, || {
|
||||
in_mem_chain
|
||||
.iter()
|
||||
.map(|b| b.block_ref().block().body.transactions().len() as u64)
|
||||
.map(|b| b.block_ref().block().body().transactions().len() as u64)
|
||||
.sum::<u64>() +
|
||||
last_block_body_index.last_tx_num()
|
||||
});
|
||||
@ -476,7 +476,7 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
|
||||
|
||||
// Iterate from the lowest block to the highest in-memory chain
|
||||
for block_state in in_mem_chain.iter().rev() {
|
||||
let block_tx_count = block_state.block_ref().block().body.transactions().len();
|
||||
let block_tx_count = block_state.block_ref().block().body().transactions().len();
|
||||
let remaining = (tx_range.end() - tx_range.start() + 1) as usize;
|
||||
|
||||
// If the transaction range start is equal or higher than the next block first
|
||||
@ -550,10 +550,10 @@ impl<N: ProviderNodeTypes> ConsistentProvider<N> {
|
||||
let executed_block = block_state.block_ref();
|
||||
let block = executed_block.block();
|
||||
|
||||
for tx_index in 0..block.body.transactions().len() {
|
||||
for tx_index in 0..block.body().transactions().len() {
|
||||
match id {
|
||||
HashOrNumber::Hash(tx_hash) => {
|
||||
if tx_hash == block.body.transactions()[tx_index].trie_hash() {
|
||||
if tx_hash == block.body().transactions()[tx_index].trie_hash() {
|
||||
return fetch_from_block_state(tx_index, in_memory_tx_num, block_state)
|
||||
}
|
||||
}
|
||||
@ -917,7 +917,7 @@ impl<N: ProviderNodeTypes> TransactionsProvider for ConsistentProvider<N> {
|
||||
id.into(),
|
||||
|provider| provider.transaction_by_id(id),
|
||||
|tx_index, _, block_state| {
|
||||
Ok(block_state.block_ref().block().body.transactions().get(tx_index).cloned())
|
||||
Ok(block_state.block_ref().block().body().transactions().get(tx_index).cloned())
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -930,7 +930,7 @@ impl<N: ProviderNodeTypes> TransactionsProvider for ConsistentProvider<N> {
|
||||
id.into(),
|
||||
|provider| provider.transaction_by_id_unhashed(id),
|
||||
|tx_index, _, block_state| {
|
||||
Ok(block_state.block_ref().block().body.transactions().get(tx_index).cloned())
|
||||
Ok(block_state.block_ref().block().body().transactions().get(tx_index).cloned())
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -971,7 +971,7 @@ impl<N: ProviderNodeTypes> TransactionsProvider for ConsistentProvider<N> {
|
||||
self.get_in_memory_or_storage_by_block(
|
||||
id,
|
||||
|provider| provider.transactions_by_block(id),
|
||||
|block_state| Ok(Some(block_state.block_ref().block().body.transactions().to_vec())),
|
||||
|block_state| Ok(Some(block_state.block_ref().block().body().transactions().to_vec())),
|
||||
)
|
||||
}
|
||||
|
||||
@ -982,7 +982,7 @@ impl<N: ProviderNodeTypes> TransactionsProvider for ConsistentProvider<N> {
|
||||
self.get_in_memory_or_storage_by_block_range_while(
|
||||
range,
|
||||
|db_provider, range, _| db_provider.transactions_by_block_range(range),
|
||||
|block_state, _| Some(block_state.block_ref().block().body.transactions().to_vec()),
|
||||
|block_state, _| Some(block_state.block_ref().block().body().transactions().to_vec()),
|
||||
|_| true,
|
||||
)
|
||||
}
|
||||
@ -995,7 +995,7 @@ impl<N: ProviderNodeTypes> TransactionsProvider for ConsistentProvider<N> {
|
||||
range,
|
||||
|db_provider, db_range| db_provider.transactions_by_tx_range(db_range),
|
||||
|index_range, block_state| {
|
||||
Ok(block_state.block_ref().block().body.transactions()[index_range].to_vec())
|
||||
Ok(block_state.block_ref().block().body().transactions()[index_range].to_vec())
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -1041,13 +1041,13 @@ impl<N: ProviderNodeTypes> ReceiptProvider for ConsistentProvider<N> {
|
||||
|
||||
// assuming 1:1 correspondence between transactions and receipts
|
||||
debug_assert_eq!(
|
||||
block.body.transactions().len(),
|
||||
block.body().transactions().len(),
|
||||
receipts.len(),
|
||||
"Mismatch between transaction and receipt count"
|
||||
);
|
||||
|
||||
if let Some(tx_index) =
|
||||
block.body.transactions().iter().position(|tx| tx.trie_hash() == hash)
|
||||
block.body().transactions().iter().position(|tx| tx.trie_hash() == hash)
|
||||
{
|
||||
// safe to use tx_index for receipts due to 1:1 correspondence
|
||||
return Ok(receipts.get(tx_index).cloned());
|
||||
@ -1128,7 +1128,7 @@ impl<N: ProviderNodeTypes> WithdrawalsProvider for ConsistentProvider<N> {
|
||||
self.get_in_memory_or_storage_by_block(
|
||||
id,
|
||||
|db_provider| db_provider.withdrawals_by_block(id, timestamp),
|
||||
|block_state| Ok(block_state.block_ref().block().body.withdrawals().cloned()),
|
||||
|block_state| Ok(block_state.block_ref().block().body().withdrawals().cloned()),
|
||||
)
|
||||
}
|
||||
|
||||
@ -1142,7 +1142,7 @@ impl<N: ProviderNodeTypes> WithdrawalsProvider for ConsistentProvider<N> {
|
||||
Ok(block_state
|
||||
.block_ref()
|
||||
.block()
|
||||
.body
|
||||
.body()
|
||||
.withdrawals()
|
||||
.cloned()
|
||||
.and_then(|mut w| w.pop()))
|
||||
@ -1161,7 +1161,7 @@ impl<N: ProviderNodeTypes> OmmersProvider for ConsistentProvider<N> {
|
||||
return Ok(Some(Vec::new()))
|
||||
}
|
||||
|
||||
Ok(block_state.block_ref().block().body.ommers().map(|o| o.to_vec()))
|
||||
Ok(block_state.block_ref().block().body().ommers().map(|o| o.to_vec()))
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -1189,7 +1189,7 @@ impl<N: ProviderNodeTypes> BlockBodyIndicesProvider for ConsistentProvider<N> {
|
||||
|
||||
// Iterate from the lowest block in memory until our target block
|
||||
for state in block_state.chain().collect::<Vec<_>>().into_iter().rev() {
|
||||
let block_tx_count = state.block_ref().block.body.transactions().len() as u64;
|
||||
let block_tx_count = state.block_ref().block.body().transactions().len() as u64;
|
||||
if state.block_ref().block().number() == number {
|
||||
stored_indices.tx_count = block_tx_count;
|
||||
} else {
|
||||
|
||||
@ -718,10 +718,10 @@ mod tests {
|
||||
);
|
||||
assert_matches!(
|
||||
provider.transaction_sender(0), Ok(Some(sender))
|
||||
if sender == block.body.transactions[0].recover_signer().unwrap()
|
||||
if sender == block.body().transactions[0].recover_signer().unwrap()
|
||||
);
|
||||
assert_matches!(
|
||||
provider.transaction_id(block.body.transactions[0].hash()),
|
||||
provider.transaction_id(block.body().transactions[0].hash()),
|
||||
Ok(Some(0))
|
||||
);
|
||||
}
|
||||
@ -741,7 +741,7 @@ mod tests {
|
||||
Ok(_)
|
||||
);
|
||||
assert_matches!(provider.transaction_sender(0), Ok(None));
|
||||
assert_matches!(provider.transaction_id(block.body.transactions[0].hash()), Ok(None));
|
||||
assert_matches!(provider.transaction_id(block.body().transactions[0].hash()), Ok(None));
|
||||
}
|
||||
}
|
||||
|
||||
@ -772,7 +772,7 @@ mod tests {
|
||||
.clone()
|
||||
.map(|tx_number| (
|
||||
tx_number,
|
||||
block.body.transactions[tx_number as usize].recover_signer().unwrap()
|
||||
block.body().transactions[tx_number as usize].recover_signer().unwrap()
|
||||
))
|
||||
.collect())
|
||||
);
|
||||
|
||||
@ -1255,7 +1255,7 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> BlockReader for DatabaseProvid
|
||||
transaction_kind,
|
||||
|block_number| self.sealed_header(block_number),
|
||||
|header, body, senders| {
|
||||
SealedBlock { header, body }
|
||||
SealedBlock::new(header, body)
|
||||
// Note: we're using unchecked here because we know the block contains valid txs
|
||||
// wrt to its height and can ignore the s value check so pre
|
||||
// EIP-2 txs are allowed
|
||||
@ -1297,7 +1297,7 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> BlockReader for DatabaseProvid
|
||||
range,
|
||||
|range| self.sealed_headers_range(range),
|
||||
|header, body, senders| {
|
||||
SealedBlockWithSenders::new(SealedBlock { header, body }, senders)
|
||||
SealedBlockWithSenders::new(SealedBlock::new(header, body), senders)
|
||||
.ok_or(ProviderError::SenderRecoveryError)
|
||||
},
|
||||
)
|
||||
@ -2806,11 +2806,11 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
|
||||
durations_recorder.record_relative(metrics::Action::GetNextTxNum);
|
||||
let first_tx_num = next_tx_num;
|
||||
|
||||
let tx_count = block.block.body.transactions().len() as u64;
|
||||
let tx_count = block.block.body().transactions().len() as u64;
|
||||
|
||||
// Ensures we have all the senders for the block's transactions.
|
||||
for (transaction, sender) in
|
||||
block.block.body.transactions().iter().zip(block.senders.iter())
|
||||
block.block.body().transactions().iter().zip(block.senders.iter())
|
||||
{
|
||||
let hash = transaction.tx_hash();
|
||||
|
||||
@ -2824,7 +2824,7 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypesForProvider + 'static> BlockWrite
|
||||
next_tx_num += 1;
|
||||
}
|
||||
|
||||
self.append_block_bodies(vec![(block_number, Some(block.block.body))], write_to)?;
|
||||
self.append_block_bodies(vec![(block_number, Some(block.block.into_body()))], write_to)?;
|
||||
|
||||
debug!(
|
||||
target: "providers::db",
|
||||
|
||||
@ -63,32 +63,39 @@ pub fn assert_genesis_block<DB: Database, N: NodeTypes>(
|
||||
// StageCheckpoints is not updated in tests
|
||||
}
|
||||
|
||||
pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| SealedBlock {
|
||||
header: SealedHeader::new(
|
||||
Header {
|
||||
parent_hash: hex!("c86e8cc0310ae7c531c758678ddbfd16fc51c8cef8cec650b032de9869e8b94f")
|
||||
pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| {
|
||||
SealedBlock::new(
|
||||
SealedHeader::new(
|
||||
Header {
|
||||
parent_hash: hex!(
|
||||
"c86e8cc0310ae7c531c758678ddbfd16fc51c8cef8cec650b032de9869e8b94f"
|
||||
)
|
||||
.into(),
|
||||
ommers_hash: EMPTY_OMMER_ROOT_HASH,
|
||||
beneficiary: hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").into(),
|
||||
state_root: hex!("50554882fbbda2c2fd93fdc466db9946ea262a67f7a76cc169e714f105ab583d")
|
||||
ommers_hash: EMPTY_OMMER_ROOT_HASH,
|
||||
beneficiary: hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").into(),
|
||||
state_root: hex!(
|
||||
"50554882fbbda2c2fd93fdc466db9946ea262a67f7a76cc169e714f105ab583d"
|
||||
)
|
||||
.into(),
|
||||
transactions_root: hex!(
|
||||
"0967f09ef1dfed20c0eacfaa94d5cd4002eda3242ac47eae68972d07b106d192"
|
||||
)
|
||||
.into(),
|
||||
receipts_root: hex!("e3c8b47fbfc94667ef4cceb17e5cc21e3b1eebd442cebb27f07562b33836290d")
|
||||
transactions_root: hex!(
|
||||
"0967f09ef1dfed20c0eacfaa94d5cd4002eda3242ac47eae68972d07b106d192"
|
||||
)
|
||||
.into(),
|
||||
difficulty: U256::from(131_072),
|
||||
number: 1,
|
||||
gas_limit: 1_000_000,
|
||||
gas_used: 14_352,
|
||||
timestamp: 1_000,
|
||||
..Default::default()
|
||||
},
|
||||
hex!("cf7b274520720b50e6a4c3e5c4d553101f44945396827705518ce17cb7219a42").into(),
|
||||
),
|
||||
body: BlockBody {
|
||||
transactions: vec![TransactionSigned::new(
|
||||
receipts_root: hex!(
|
||||
"e3c8b47fbfc94667ef4cceb17e5cc21e3b1eebd442cebb27f07562b33836290d"
|
||||
)
|
||||
.into(),
|
||||
difficulty: U256::from(131_072),
|
||||
number: 1,
|
||||
gas_limit: 1_000_000,
|
||||
gas_used: 14_352,
|
||||
timestamp: 1_000,
|
||||
..Default::default()
|
||||
},
|
||||
hex!("cf7b274520720b50e6a4c3e5c4d553101f44945396827705518ce17cb7219a42").into(),
|
||||
),
|
||||
BlockBody {
|
||||
transactions: vec![TransactionSigned::new(
|
||||
Transaction::Legacy(TxLegacy {
|
||||
gas_price: 10,
|
||||
gas_limit: 400_000,
|
||||
@ -108,8 +115,9 @@ pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| SealedBlo
|
||||
),
|
||||
b256!("3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397"),
|
||||
)],
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
/// Test chain with genesis, blocks, execution results
|
||||
@ -155,13 +163,13 @@ impl Default for BlockchainTestData {
|
||||
|
||||
/// Genesis block
|
||||
pub fn genesis() -> SealedBlock {
|
||||
SealedBlock {
|
||||
header: SealedHeader::new(
|
||||
SealedBlock::new(
|
||||
SealedHeader::new(
|
||||
Header { number: 0, difficulty: U256::from(1), ..Default::default() },
|
||||
B256::ZERO,
|
||||
),
|
||||
body: Default::default(),
|
||||
}
|
||||
Default::default(),
|
||||
)
|
||||
}
|
||||
|
||||
fn bundle_state_root(execution_outcome: &ExecutionOutcome) -> B256 {
|
||||
@ -224,13 +232,13 @@ fn block1(number: BlockNumber) -> (SealedBlockWithSenders, ExecutionOutcome) {
|
||||
b256!("5d035ccb3e75a9057452ff060b773b213ec1fc353426174068edfc3971a0b6bd")
|
||||
);
|
||||
|
||||
let mut block = TEST_BLOCK.clone();
|
||||
block.body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = block.header.clone().unseal();
|
||||
let (header, mut body) = TEST_BLOCK.clone().split_header_body();
|
||||
body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = header.unseal();
|
||||
header.number = number;
|
||||
header.state_root = state_root;
|
||||
header.parent_hash = B256::ZERO;
|
||||
block.header = SealedHeader::seal(header);
|
||||
let block = SealedBlock::new(SealedHeader::seal(header), body);
|
||||
|
||||
(SealedBlockWithSenders { block, senders: vec![Address::new([0x30; 20])] }, execution_outcome)
|
||||
}
|
||||
@ -286,15 +294,15 @@ fn block2(
|
||||
b256!("90101a13dd059fa5cca99ed93d1dc23657f63626c5b8f993a2ccbdf7446b64f8")
|
||||
);
|
||||
|
||||
let mut block = TEST_BLOCK.clone();
|
||||
let (header, mut body) = TEST_BLOCK.clone().split_header_body();
|
||||
|
||||
block.body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = block.header.clone().unseal();
|
||||
body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = header.unseal();
|
||||
header.number = number;
|
||||
header.state_root = state_root;
|
||||
// parent_hash points to block1 hash
|
||||
header.parent_hash = parent_hash;
|
||||
block.header = SealedHeader::seal(header);
|
||||
let block = SealedBlock::new(SealedHeader::seal(header), body);
|
||||
|
||||
(SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome)
|
||||
}
|
||||
@ -351,14 +359,14 @@ fn block3(
|
||||
extended.extend(execution_outcome.clone());
|
||||
let state_root = bundle_state_root(&extended);
|
||||
|
||||
let mut block = TEST_BLOCK.clone();
|
||||
block.body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = block.header.clone().unseal();
|
||||
let (header, mut body) = TEST_BLOCK.clone().split_header_body();
|
||||
body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = header.unseal();
|
||||
header.number = number;
|
||||
header.state_root = state_root;
|
||||
// parent_hash points to block1 hash
|
||||
header.parent_hash = parent_hash;
|
||||
block.header = SealedHeader::seal(header);
|
||||
let block = SealedBlock::new(SealedHeader::seal(header), body);
|
||||
|
||||
(SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome)
|
||||
}
|
||||
@ -440,14 +448,14 @@ fn block4(
|
||||
extended.extend(execution_outcome.clone());
|
||||
let state_root = bundle_state_root(&extended);
|
||||
|
||||
let mut block = TEST_BLOCK.clone();
|
||||
block.body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = block.header.clone().unseal();
|
||||
let (header, mut body) = TEST_BLOCK.clone().split_header_body();
|
||||
body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = header.unseal();
|
||||
header.number = number;
|
||||
header.state_root = state_root;
|
||||
// parent_hash points to block1 hash
|
||||
header.parent_hash = parent_hash;
|
||||
block.header = SealedHeader::seal(header);
|
||||
let block = SealedBlock::new(SealedHeader::seal(header), body);
|
||||
|
||||
(SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome)
|
||||
}
|
||||
@ -526,14 +534,14 @@ fn block5(
|
||||
extended.extend(execution_outcome.clone());
|
||||
let state_root = bundle_state_root(&extended);
|
||||
|
||||
let mut block = TEST_BLOCK.clone();
|
||||
block.body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = block.header.clone().unseal();
|
||||
let (header, mut body) = TEST_BLOCK.clone().split_header_body();
|
||||
body.withdrawals = Some(Withdrawals::new(vec![Withdrawal::default()]));
|
||||
let mut header = header.unseal();
|
||||
header.number = number;
|
||||
header.state_root = state_root;
|
||||
// parent_hash points to block1 hash
|
||||
header.parent_hash = parent_hash;
|
||||
block.header = SealedHeader::seal(header);
|
||||
let block = SealedBlock::new(SealedHeader::seal(header), body);
|
||||
|
||||
(SealedBlockWithSenders { block, senders: vec![Address::new([0x31; 20])] }, execution_outcome)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user