mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: add BlockWriter and BlockExecutionWriter (#3384)
This commit is contained in:
@ -6,7 +6,8 @@ use crate::{
|
||||
};
|
||||
use reth_db::mdbx::test_utils::create_test_rw_db;
|
||||
use reth_primitives::{BlockBody, SealedBlock};
|
||||
use reth_provider::ProviderFactory;
|
||||
use reth_provider::{BlockWriter, ProviderFactory};
|
||||
use reth_rlp::Decodable;
|
||||
use reth_stages::{stages::ExecutionStage, ExecInput, Stage};
|
||||
use std::{collections::BTreeMap, ffi::OsStr, fs, path::Path, sync::Arc};
|
||||
|
||||
@ -79,8 +80,7 @@ impl Case for BlockchainTestCase {
|
||||
let mut provider = factory.provider_rw().unwrap();
|
||||
|
||||
// Insert test state
|
||||
reth_provider::insert_canonical_block(
|
||||
provider.tx_ref(),
|
||||
provider.insert_block(
|
||||
SealedBlock::new(case.genesis_block_header.clone().into(), BlockBody::default()),
|
||||
None,
|
||||
)?;
|
||||
@ -88,7 +88,9 @@ impl Case for BlockchainTestCase {
|
||||
|
||||
let mut last_block = None;
|
||||
for block in case.blocks.iter() {
|
||||
last_block = Some(block.write_to_db(provider.tx_ref())?);
|
||||
let decoded = SealedBlock::decode(&mut block.rlp.as_ref())?;
|
||||
last_block = Some(decoded.number);
|
||||
provider.insert_block(decoded, None)?;
|
||||
}
|
||||
|
||||
// Call execution stage
|
||||
|
||||
@ -7,11 +7,10 @@ use reth_db::{
|
||||
transaction::{DbTx, DbTxMut},
|
||||
};
|
||||
use reth_primitives::{
|
||||
keccak256, Account as RethAccount, Address, BigEndianHash, BlockNumber, Bloom, Bytecode, Bytes,
|
||||
ChainSpec, ChainSpecBuilder, Header as RethHeader, JsonU256, SealedBlock, SealedHeader,
|
||||
StorageEntry, Withdrawal, H160, H256, H64, U256,
|
||||
keccak256, Account as RethAccount, Address, BigEndianHash, Bloom, Bytecode, Bytes, ChainSpec,
|
||||
ChainSpecBuilder, Header as RethHeader, JsonU256, SealedHeader, StorageEntry, Withdrawal, H160,
|
||||
H256, H64, U256,
|
||||
};
|
||||
use reth_rlp::Decodable;
|
||||
use serde::{self, Deserialize};
|
||||
use std::{collections::BTreeMap, ops::Deref};
|
||||
|
||||
@ -138,19 +137,6 @@ pub struct Block {
|
||||
pub withdrawals: Option<Vec<Withdrawal>>,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
/// Write the block to the database.
|
||||
pub fn write_to_db<'a, Tx>(&self, tx: &'a Tx) -> Result<BlockNumber, Error>
|
||||
where
|
||||
Tx: DbTx<'a> + DbTxMut<'a>,
|
||||
{
|
||||
let decoded = SealedBlock::decode(&mut self.rlp.as_ref())?;
|
||||
let block_number = decoded.number;
|
||||
reth_provider::insert_canonical_block(tx, decoded, None)?;
|
||||
Ok(block_number)
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction sequence in block
|
||||
#[derive(Debug, PartialEq, Eq, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
||||
Reference in New Issue
Block a user