diff --git a/src/accessors/behavior_pool.rs b/src/accessors/behavior_pool.rs index 128bb2498afa826c30c5839ff9ac63a0aeb88d1a..b78dd733c1208607ff1ddde4c14b0a66c87f7033 100644 --- a/src/accessors/behavior_pool.rs +++ b/src/accessors/behavior_pool.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; -use std::sync::Mutex; +use std::{collections::HashMap, sync::Mutex}; use crate::models::behavior::BehaviorWithSignature; @@ -60,12 +59,13 @@ pub fn get_many_behaviors_and_remove_them( #[cfg(test)] mod test { - use crate::accessors::behavior_pool::{ - add_behavior_to_pool, get_and_remove_behavior_from_pool, - get_many_behaviors_and_remove_them, BEHAVIOR_POOL, + use crate::{ + accessors::behavior_pool::{ + add_behavior_to_pool, get_and_remove_behavior_from_pool, + get_many_behaviors_and_remove_them, BEHAVIOR_POOL, + }, + models::{behavior::BehaviorWithSignature}, }; - use crate::models::behavior::BehaviorWithSignature; - use crate::models::ChainId; #[test] fn insert_and_retrieve_behavior() { diff --git a/src/accessors/transaction_pool.rs b/src/accessors/transaction_pool.rs index f7c5d8823e4b8db30a04423088330cbdec97da4f..f42a6b50c6f8a1b8801cdb089ec24a97fde8ac6d 100644 --- a/src/accessors/transaction_pool.rs +++ b/src/accessors/transaction_pool.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; -use std::sync::Mutex; +use std::{collections::HashMap, sync::Mutex}; use hex_literal::hex; diff --git a/src/consensus/clique/mod.rs b/src/consensus/clique/mod.rs index c55f542a125c43c75234051af4e69ac9e5e7aee0..08ad96a5ce50277df5864c30a56e50866ab57a46 100644 --- a/src/consensus/clique/mod.rs +++ b/src/consensus/clique/mod.rs @@ -4,9 +4,9 @@ pub use state::CliqueState; use crate::{ consensus::{ - fork_choice_graph::ForkChoiceGraph, state::CliqueBlock, CliqueError, - Consensus, ConsensusEngineBase, ConsensusState, DuoError, FinalizationChange, - ForkChoiceMode, ValidationError, + fork_choice_graph::ForkChoiceGraph, state::CliqueBlock, CliqueError, Consensus, + ConsensusEngineBase, ConsensusState, DuoError, FinalizationChange, ForkChoiceMode, + ValidationError, }, kv::{ mdbx::{MdbxCursor, MdbxTransaction}, diff --git a/src/consensus/pob/difficulty.rs b/src/consensus/pob/difficulty.rs index b6583bed5c4c97ac894ba866830fb18097eaef30..469fe5f49b81222664deff94aafb4d22418ae549 100644 --- a/src/consensus/pob/difficulty.rs +++ b/src/consensus/pob/difficulty.rs @@ -62,7 +62,7 @@ pub fn compute_average_block_time_or_desired(previous_timestamps: Vec<u64>) -> u #[cfg(test)] mod tests { - use crate::{consensus::difficulty, models::behavior::Behavior, res::chainspec::ECOMOBICOIN}; + use crate::{models::behavior::Behavior, res::chainspec::ECOMOBICOIN}; use super::*; diff --git a/src/consensus/pob/miner.rs b/src/consensus/pob/miner.rs index 54aed0523e7608de90e697025fc5a7771b0d4a82..db6a9bdc9d29166c79c6b91cdfeb8744edf1b883 100644 --- a/src/consensus/pob/miner.rs +++ b/src/consensus/pob/miner.rs @@ -1,41 +1,26 @@ -use std::{ - error::Error, - sync::Arc, - time::{self, Instant}, -}; +use std::sync::Arc; use crate::{ accessors::{self}, - accessors::{chain, state}, - consensus::{ - engine_factory, pre_validate_behavior, pre_validate_transaction, Consensus, ConsensusState, - DuoError, Quantifiable, - }, + consensus::{pre_validate_behavior, pre_validate_transaction, Consensus, DuoError}, crypto::keccak256, - execution::{ - analysis_cache::AnalysisCache, - processor::ExecutionProcessor, - tracer::{NoopTracer, Tracer}, - }, - kv::{mdbx::MdbxTransaction, new_mem_chaindata, MdbxWithDirHandle}, + execution::{analysis_cache::AnalysisCache, processor::ExecutionProcessor, tracer::Tracer}, + kv::{mdbx::MdbxTransaction, MdbxWithDirHandle}, models::{ behavior::{Behavior, BehaviorWithSender, BehaviorWithSignature}, - Block, BlockBodyWithSenders, BlockExecutionSpec, BlockHeader, BlockNumber, ChainId, - ChainSpec, ExecutedBlock, MessageWithSender, MessageWithSignature, OpenBlock, Receipt, - TxType, + BlockBodyWithSenders, BlockExecutionSpec, BlockHeader, ChainId, ExecutedBlock, + MessageWithSender, MessageWithSignature, OpenBlock, }, - rpc::debug, - trie::root_hash, - Buffer, IntraBlockState, State, StateReader, + Buffer, }; use anyhow::format_err; use arrayvec::ArrayVec; -use async_trait::async_trait; + use bitvec::macros::internal::funty::Fundamental; use bytes::Bytes; -use ethereum_types::{Address, Bloom, H256, H64}; +use ethereum_types::{Address, H256}; use ethnum::U256; -use mdbx::{EnvironmentKind, RO, RW}; +use mdbx::{EnvironmentKind, RO}; use parking_lot::RwLock; use tracing::*; use vdf::InvalidIterations; @@ -47,11 +32,11 @@ use super::{ vdf::{compute_delay_parameter, vdf_from_delay}, MINER_FIXED_REWARD_PER_TRANSACTION, }; -use tracing::*; + // TODO move me to mod.rs once finished /// Configures the behaviour of the miner. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct MinerOptions { /// Dry run the VDF is true, replacing its output by zeroes. dry_run: bool, // TODO Replace me with a VDF trait and a Noop one for test purposes @@ -114,7 +99,7 @@ where &mut self, miner_behavior: BehaviorWithSignature, ) -> Result<ExecutedBlock, DuoError> { - let mut txn = self.db.begin().unwrap(); + let txn = self.db.begin().unwrap(); let parent_block_header = get_latest_parent_header(txn).unwrap(); @@ -145,7 +130,6 @@ where open_block: OpenBlock, parent_block_header: BlockHeader, ) -> Result<ExecutedBlock, DuoError> { - println!("MINE BLOCK"); let network_difficulty = open_block.get_header().difficulty.as_u64(); // Compute time delay for this open block and apply mining strategy (coming soon) @@ -167,7 +151,7 @@ where if !self.options.dry_run { proof = run_vdf( parent_block_header.parent_hash, - miner_behavior.behavior.clone(), + miner_behavior.behavior, network_difficulty, ) .unwrap(); @@ -199,8 +183,7 @@ where ) -> Result<OpenBlock, DuoError> { let ommers: ArrayVec<BlockHeader, 2> = Default::default(); - let mut txn = self.db.begin_mutable().unwrap(); - println!("TXN"); + let txn = self.db.begin_mutable().unwrap(); // TODO // Check if a block is already in preparation // TODO @@ -214,6 +197,7 @@ where &parent_block_header, self.params.read().author, self.params.read().extra_data.clone(), + ommers.to_vec(), ); // Update DIFFICULTY @@ -265,7 +249,7 @@ where } }) .collect(), - ommers: ommers.clone(), + ommers, }; let binding = open_block.get_header(); let processor = ExecutionProcessor::new( @@ -281,6 +265,8 @@ where let receipts_result = processor.execute_without_check_and_write_block(); // println!("Block preparation receipts: {:?}", receipts); open_block.set_receipts(receipts_result.unwrap()); + open_block.set_transactions(pending_txs); + open_block.set_behaviors(pending_bxs); Ok(open_block) } @@ -344,13 +330,13 @@ pub fn check_pending_tx_bx( check_block_txbx_ratio(pending_txs.clone(), pending_bxs.clone()).unwrap(); // Verify pending TXs - for tx in pending_txs.clone() { + for tx in pending_txs { pre_validate_transaction(&tx, canonical_chain_id, Some(U256::new(1))).unwrap(); // TODO reject invalid tx & notify pool? } // Verify pending BXs - for bx in pending_bxs.clone() { + for bx in pending_bxs { pre_validate_behavior(&bx, canonical_chain_id).unwrap(); // TODO reject invalid bx & notify pool? } @@ -387,7 +373,7 @@ pub fn check_min_tx_value_sent( /// Check block size /// TODO: no size defined yet pub fn check_block_size( - txs: Vec<MessageWithSignature>, + _txs: Vec<MessageWithSignature>, bxs: Vec<BehaviorWithSignature>, ) -> anyhow::Result<(), super::DuoError> { // Only limit bxs are txs are limited by txbx ratio @@ -419,19 +405,24 @@ pub fn check_block_txbx_ratio( #[cfg(test)] mod tests { use super::*; - use crate::accessors::*; - use crate::consensus::ValidationError; - use crate::kv::{new_mem_chaindata, tables, tables::*, traits::*}; - use crate::models::behavior::BehaviorSignature; - use crate::models::*; + use crate::{ + accessors::*, + consensus::engine_factory, + execution::tracer::NoopTracer, + kv::{new_mem_chaindata, tables, traits::*}, + models::{behavior::BehaviorSignature, *}, + }; use bytes::Bytes; use bytes_literal::bytes; + use ethereum_types::BloomInput; use hex_literal::hex; use mdbx::WriteMap; - use std::{borrow::Cow, cmp, collections::BTreeMap, io::Read, sync::Arc, time}; + use std::{io::Read, sync::Arc}; const CHAIN_ID: ChainId = ChainId(63); + const behavior_input_example: Bytes = bytes!("01020304b87502f872041a8459682f008459682f0d8252089461815774383099e24810ab832a5b2a5425c154d58829a2241af62c000080c001a059e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafda0016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469"); + #[test] #[ignore] fn run_vdf_should_work() { @@ -482,20 +473,21 @@ mod tests { ) .unwrap(), }; - let hash1 = H256::random(); - chain::storage_body::write(&txn, 0, &block1).unwrap(); - txn.set(tables::CanonicalHeader, 0.into(), hash1).unwrap(); - let mut header = BlockHeader::default(); - header.timestamp = time::SystemTime::now() - .duration_since(time::UNIX_EPOCH) - .unwrap_or_default() - .as_secs(); - header.difficulty = U256::new(10); - header.number = BlockNumber(0); - header.parent_hash = H256::random(); - txn.set(tables::Header, 0.into(), header.clone()).unwrap(); + let mut parent_block_header = BlockHeader::default(); + parent_block_header.timestamp = 1679068855; + parent_block_header.difficulty = U256::new(10); + parent_block_header.number = BlockNumber(0); + parent_block_header.parent_hash = H256::zero(); + txn.set(tables::Header, 0.into(), parent_block_header.clone()) + .unwrap(); chain::tx::write(&txn, block1.base_tx_id, &[tx1_1]).unwrap(); - + chain::storage_body::write(&txn, 0, &block1).unwrap(); + txn.set( + tables::CanonicalHeader, + 0.into(), + parent_block_header.hash(), + ) + .unwrap(); txn.commit().unwrap(); // Create chain spec & miner @@ -521,13 +513,12 @@ mod tests { ); // Create fake miner behavior - let input = bytes!("01020304b87502f872041a8459682f008459682f0d8252089461815774383099e24810ab832a5b2a5425c154d58829a2241af62c000080c001a059e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafda0016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469"); let miner_behavior = BehaviorWithSignature { behavior: Behavior { chain_id: ChainId(63), timestamp: 1672534861, - quantity: 100_000u64 << 53 / 6500, - input, + quantity: (100_000u64 << 53) / 6500, + input: behavior_input_example, }, signature: BehaviorSignature::new( true, @@ -543,8 +534,232 @@ mod tests { // ASSERT assert!(mined_block_result.is_ok()); let mined_block = mined_block_result.unwrap(); - assert_eq!(mined_block.header.number.0, header.number.0 + 1); - // TODO add tests + assert_eq!( + mined_block.header.number.0, + parent_block_header.number.0 + 1 + ); + // TODO uncomment tests once pending txs and bxs are fetched. + // assert_eq!(parent_block_header.hash(), mined_block.header.parent_hash); + assert_eq!(Address::zero(), mined_block.header.beneficiary); + assert_eq!(Bytes::new(), mined_block.header.extra_data); + // assert_ne!(H256::zero(), mined_block.header.transactions_root); + // assert_ne!(0, mined_block.header.transactions_number); + // assert_ne!(H256::zero(), mined_block.header.behaviors_root); + // assert_ne!(0, mined_block.header.behavior_total_quantity); + // assert_ne!(Bloom::zero(), mined_block.header.behaviors_bloom); + // assert_ne!(Bloom::zero(), mined_block.header.logs_bloom); + // assert_ne!(H256::zero(), mined_block.header.receipts_root); + assert_ne!(0, mined_block.header.timestamp); + assert_ne!(U256::ZERO, mined_block.header.difficulty); + // + // assert_ne!(Address::zero(), executed_block.header.beneficiary); + // assert_ne!(0, mined_block.header.vdf_difficulty); + // assert_ne!([0 as u8; 32], mined_block.header.vdf_proof_challenge); + // Proof with zeroes as dry run enabled + // assert_ne!([0 as u8; 516], executed_block.header.vdf_proof_result); + // assert_ne!(H256::zero(), executed_block.header.state_root); + } + + #[test] + fn prepare_block_should_work() { + // ARRANGE + // Create db + let db = Arc::new(new_mem_chaindata().unwrap()); + // let db_test = Arc::clone(&db); + // let mut txn = db_test.begin_mutable().unwrap(); + let mut s = String::new(); + std::fs::File::open("./src/res/chainspec/ecomobicoin.ron") + .unwrap() + .read_to_string(&mut s); + let chain_spec: ChainSpec = TableDecode::decode(s.as_bytes()).unwrap(); + + let mut analysis_cache = AnalysisCache::default(); + let mut tracer = NoopTracer; + + let block_spec = chain_spec.collect_block_spec(BlockNumber(0)); + let mut engine = engine_factory(None, chain_spec.clone(), None).unwrap(); + + let mut miner = Miner::<WriteMap>::new( + MinerOptions { dry_run: false }, + &mut tracer, + &mut analysis_cache, + engine, + &block_spec, + db.clone(), + ); + let pending_txs = vec![]; + let pending_bxs = vec![]; + let mut parent_block_header = BlockHeader::default(); + parent_block_header.difficulty = U256::ONE; + + // ACT + let result = miner.prepare_block( + pending_txs, + pending_bxs, + chain_spec.params.chain_id, + parent_block_header.clone(), + ); + // ASSERT + assert!(result.is_ok()); + let open_block = result.unwrap(); + assert_eq!(1, open_block.get_number().0); + let open_block_header = open_block.get_header().clone(); + assert_eq!(parent_block_header.hash(), open_block_header.parent_hash); + assert_eq!(Address::zero(), open_block_header.beneficiary); + assert_eq!(Bytes::new(), open_block_header.extra_data); + assert_ne!(0, open_block_header.difficulty); + assert_ne!(0, open_block_header.timestamp); + } + + #[test] + fn mine_block_should_work() { + // ARRANGE + let pob_m = BehaviorWithSignature { + behavior: Behavior { + chain_id: ChainId(63), + timestamp: 1672534861, + quantity: (100_000u64 << 53) / 6500, + input: behavior_input_example, + }, + signature: BehaviorSignature::new( + true, + // TODO replace with correct signature + hex!("70bcb39ac6f540498c3adfdf3a23ecce5cf7b4f75b0674c157da02350edf8ed4"), + hex!("40e997c09def486888c34e77565cce82b348d0035e2ea36bf125252f7895ff3c"), + ) + .unwrap(), + }; + let mut parent_block_header = BlockHeader::default(); + parent_block_header.number = BlockNumber(1337); + parent_block_header.timestamp = 1; + parent_block_header.beneficiary = Address::random(); + parent_block_header.parent_hash = H256::random(); + + let mut open_block = OpenBlock::default(); + // https://etherscan.io/block/13143465 + let transactions = vec![ + MessageWithSignature { + message: Message::EIP1559 { + chain_id: CHAIN_ID, + nonce: 20369, + max_priority_fee_per_gas: 0x50a3d0b5d_u64.into(), + max_fee_per_gas: 0x23a9e38cf8_u64.into(), + gas_limit: 1_200_000, + action: TransactionAction::Call(hex!("a57bd00134b2850b2a1c55860c9e9ea100fdd6cf").into()), + value: U256::ZERO, + input: hex!("1cff79cd000000000000000000000000aa2ec16d77cfc057fb9c516282fef9da9de1e987000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001844f0c7c0a00000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000056178a0d5f301baf6cf3e1cd53d9863437345bf9000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000a2a15d09519be00000000000000000000000000000000000000000000000daadf45a4bb347757560000000000000000000000000000000000000000000000000003453af3f6dd960000000000000000000000000000000000000003f994c7f39b6af041a3c553270000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000061303192000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec().into(), + access_list: vec![], + }, + signature: MessageSignature::new(false, hex!("9a8548ba3759730fe25be0412c0b183ec975d15da2f12653d5f0a2016ca01f27"), hex!("6d93f2176bfda918c06365e507c6c66a16d30b9e76d2d8e5a7f2802e3bcc6593")).unwrap(), + } + ]; + open_block.set_transactions(transactions); + let behaviors = vec![BehaviorWithSignature { + behavior: Behavior { + chain_id: CHAIN_ID, + timestamp: 1672534861, // 2023/01/01 01:01:01 + quantity: 10_000, + input: hex!( + "a0712d680000000000000000000000000000000000000000000000000000000000000002" + ) + .to_vec() + .into(), + }, + signature: BehaviorSignature::new( + true, + // TODO replace with correct signature + hex!("70bcb39ac6f540498c3adfdf3a23ecce5cf7b4f75b0674c157da02350edf8ed4"), + hex!("40e997c09def486888c34e77565cce82b348d0035e2ea36bf125252f7895ff3c"), + ) + .unwrap(), + }]; + open_block.set_behaviors(behaviors.clone()); + let receipts = vec![ + // Behavior receipt + Receipt { + tx_type: TxType::Behavior, + success: true, + cumulative_gas_used: 0, + bloom: Bloom::from(BloomInput::Hash(behaviors[0].hash().as_fixed_bytes())), + logs: vec![], + }, + Receipt { + tx_type: TxType::EIP1559, + success: true, + cumulative_gas_used: 1, + bloom: Bloom::from(BloomInput::Hash(&[1 as u8; 32])), + logs: vec![], + }, + ]; + open_block.set_receipts(receipts); + open_block.set_difficulty(U256::ONE); + open_block.set_timestamp(1); + // Create db + let db = Arc::new(new_mem_chaindata().unwrap()); + // Create chain spec & miner + let mut s = String::new(); + std::fs::File::open("./src/res/chainspec/ecomobicoin.ron") + .unwrap() + .read_to_string(&mut s); + let chain_spec: ChainSpec = TableDecode::decode(s.as_bytes()).unwrap(); + + let mut analysis_cache = AnalysisCache::default(); + let mut tracer = NoopTracer; + + let block_spec = chain_spec.collect_block_spec(BlockNumber(0)); + let mut engine = engine_factory(None, chain_spec, None).unwrap(); + + let mut miner = Miner::<WriteMap>::new( + MinerOptions { dry_run: true }, + &mut tracer, + &mut analysis_cache, + engine, + &block_spec, + db.clone(), + ); + + // ACT + let result = miner.mine_block(pob_m, open_block, parent_block_header); + // ASSERT + assert!(result.is_ok()); + let executed_block = result.unwrap(); + + assert_ne!(H256::zero(), executed_block.header.transactions_root); + assert_ne!(0, executed_block.header.transactions_number); + assert_ne!(H256::zero(), executed_block.header.behaviors_root); + assert_ne!(0, executed_block.header.behavior_total_quantity); + assert_ne!(Bloom::zero(), executed_block.header.behaviors_bloom); + assert_ne!(Bloom::zero(), executed_block.header.logs_bloom); + assert_ne!(H256::zero(), executed_block.header.receipts_root); + // Done in prepare + // assert_ne!(0, executed_block.header.timestamp); + // assert_ne!(U256::ZERO, executed_block.header.difficulty); + // + // assert_ne!(Address::zero(), executed_block.header.beneficiary); + assert_ne!(0, executed_block.header.vdf_difficulty); + assert_ne!([0 as u8; 32], executed_block.header.vdf_proof_challenge); + // Proof with zeroes as dry run enabled + // assert_ne!([0 as u8; 516], executed_block.header.vdf_proof_result); + // assert_ne!(H256::zero(), executed_block.header.state_root); + } + + #[test] + fn prepare_work_should_work() { + // ARRANGE + let parent_hash = H256::from(hex!( + "0e3828d13eed24036941eb5f7fd65de57aad1184342f2244130d2941554342ba" + )); + let pob_m = Behavior { + chain_id: ChainId(63), + timestamp: 1672534861, + quantity: (100_000u64 << 53) / 6500, + input: behavior_input_example, + }; + let network_difficulty = 1_000; + // ACT + let result = prepare_work(parent_hash, pob_m, network_difficulty); + // ASSERT + assert_eq!(5597000, result); } #[test] diff --git a/src/consensus/pob/vdf.rs b/src/consensus/pob/vdf.rs index df9710fd7d738a80d2670225a5df7d1523d83d66..8cff835724fd03d3a1b7bb070524a85289749d25 100644 --- a/src/consensus/pob/vdf.rs +++ b/src/consensus/pob/vdf.rs @@ -18,7 +18,7 @@ pub fn compute_delay_parameter(network_difficulty: u64, hash: H256, quantity: u6 /// Launch a VDF from a delay parameter in seconds and challenge. pub fn vdf_from_delay(hash: &HashOutput, delay: u64) -> Result<Vec<u8>, InvalidIterations> { - vdf(&hash, delay * PIETRZAK_DIFFICULTY_PER_SEC) + vdf(hash, delay * PIETRZAK_DIFFICULTY_PER_SEC) } /// Launch a VDF and returns its output. @@ -52,9 +52,9 @@ type HashOutput = [u8]; #[cfg(test)] mod tests { - use bitvec::macros::internal::funty::Fundamental; + use hex_literal::hex; - use sha3::{Digest, Sha3_256}; + use super::*; diff --git a/src/execution/mod.rs b/src/execution/mod.rs index ce312ff1b77451320a1e8b21a6e0e8bbd55df950..09e2c7156625b67f37e95e014affb0d2207c6d90 100644 --- a/src/execution/mod.rs +++ b/src/execution/mod.rs @@ -44,7 +44,7 @@ mod tests { use hex_literal::hex; use crate::{ - consensus::{BlockHeaderOrSender, Pob, MINER_FIXED_REWARD_PER_TRANSACTION}, + consensus::{MINER_FIXED_REWARD_PER_TRANSACTION}, crypto::keccak256, models::behavior::{Behavior, BehaviorWithSender}, res::chainspec::ECOMOBICOIN, diff --git a/src/models/behavior.rs b/src/models/behavior.rs index dabdad2daf0924148e63fe275f5aed5e09f6f62e..3f7f2e29528796649aeedaddbf4202275aee99ee 100644 --- a/src/models/behavior.rs +++ b/src/models/behavior.rs @@ -545,7 +545,7 @@ mod tests { let mut encoded = BytesMut::new(); signed_behavior.encode(&mut encoded); - println!("Raw behavior: {:?}", hex::encode(&encoded)); + // println!("Raw behavior: {:?}", hex::encode(&encoded)); let decoded = BehaviorWithSignature::decode(&mut &*encoded).unwrap(); assert_eq!(signed_behavior, decoded); diff --git a/src/models/block.rs b/src/models/block.rs index 649c706b39d6a20f49731ee3afa36d682a48ecc4..e7d960211ed53d9aff2c0d9f7633ad70faac3a97 100644 --- a/src/models/block.rs +++ b/src/models/block.rs @@ -112,7 +112,14 @@ impl Default for OpenBlock { } impl OpenBlock { - pub fn new(parent: &BlockHeader, author: Address, extra_data: Bytes) -> Self { + pub fn new( + parent: &BlockHeader, + author: Address, + extra_data: Bytes, + // txs: Vec<MessageWithSignature>, + // bxs: Vec<BehaviorWithSignature>, + ommers: Vec<BlockHeader>, + ) -> Self { let number = parent.number.0 + 1; let mut r = OpenBlock { @@ -124,6 +131,9 @@ impl OpenBlock { r.block.header.beneficiary = author; r.block.header.extra_data = extra_data; // ... + // r.block.transactions = txs; + // r.block.behaviors = bxs; + r.block.ommers = ommers; r } @@ -153,6 +163,14 @@ impl OpenBlock { self.block.header.difficulty = difficulty; } + pub fn set_transactions(&mut self, transactions: Vec<MessageWithSignature>) { + self.block.transactions = transactions; + } + + pub fn set_behaviors(&mut self, behaviors: Vec<BehaviorWithSignature>) { + self.block.behaviors = behaviors; + } + pub fn set_receipts(&mut self, receipts: Vec<Receipt>) { self.block.receipts = receipts; } @@ -727,7 +745,7 @@ mod tests { let mut out = BytesMut::new(); blockbody.encode(&mut out); let hex_out = hex::encode(out); - println!("Block body raw out: {:?}", hex_out); + // println!("Block body raw out: {:?}", hex_out); } #[test] diff --git a/src/models/log.rs b/src/models/log.rs index 21e072b30d2c1b141bc503459bc14b79070a266c..a48138451561b20c3cf27b0b159fb9198bb1bb6a 100644 --- a/src/models/log.rs +++ b/src/models/log.rs @@ -1,7 +1,6 @@ use super::*; use bytes::Bytes; - #[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable)] pub struct Log { pub address: Address, diff --git a/src/p2p/node/node.rs b/src/p2p/node/node.rs index 1097f477590ed3f6955b5eb021640e5811783c9f..7db9dc891d546502655bc9a07f25f84381f9c38e 100644 --- a/src/p2p/node/node.rs +++ b/src/p2p/node/node.rs @@ -25,10 +25,12 @@ use tokio_stream::StreamExt; use tonic::transport::Channel; use tracing::*; -use crate::accessors::behavior_pool::add_behavior_to_pool; -use crate::models::behavior::{Behavior, BehaviorWithSignature}; use crate::{ - models::{BlockNumber, ChainConfig, MessageWithSignature, H256}, + accessors::behavior_pool::add_behavior_to_pool, + models::{ + behavior::{BehaviorWithSignature}, + BlockNumber, ChainConfig, MessageWithSignature, H256, + }, p2p::types::*, }; diff --git a/src/p2p/types/message.rs b/src/p2p/types/message.rs index a78191c23cd20a1b3d4d39ad1ffdeac1a64f6de6..e9397ec7f040f20a40d555a2681e3f04b45813cb 100644 --- a/src/p2p/types/message.rs +++ b/src/p2p/types/message.rs @@ -5,9 +5,11 @@ use ethereum_interfaces::sentry as grpc_sentry; use fastrlp::*; use rand::Rng; -use crate::models::behavior::BehaviorWithSignature; use crate::{ - models::{behavior::Behavior, BlockBody, MessageWithSignature, H256}, + models::{ + behavior::{BehaviorWithSignature}, + BlockBody, MessageWithSignature, H256, + }, p2p::types::*, sentry::devp2p::PeerId, }; diff --git a/src/stages/mining.rs b/src/stages/mining.rs deleted file mode 100644 index 1c2e2b33ecacdb8981d76ac9c56d1fdb60bcb0d7..0000000000000000000000000000000000000000 --- a/src/stages/mining.rs +++ /dev/null @@ -1,599 +0,0 @@ -use crate::{ - accessors::{self}, - accessors::{chain, state}, - consensus::{ - difficulty::{ - compute_average_block_time_or_desired, get_network_difficulty, TIME_PERIOD_IN_BLOCKS, - }, - engine_factory, - miner::{check_block_size, check_block_txbx_ratio, check_min_tx_value_sent, run_vdf}, - pre_validate_behavior, pre_validate_transaction, Consensus, ConsensusState, DuoError, - Quantifiable, - }, - execution::{analysis_cache::AnalysisCache, processor::ExecutionProcessor, tracer::NoopTracer}, - kv::{ - mdbx::*, - tables::{self}, - }, - models::{ - behavior::{Behavior, BehaviorWithSender, BehaviorWithSignature}, - Block, *, - }, - stagedsync::stage::*, - trie::root_hash, - Buffer, StageId, -}; -use anyhow::format_err; -use arrayvec::ArrayVec; -use async_trait::async_trait; -use bitvec::macros::internal::funty::Fundamental; -use bytes::Bytes; -use std::time::{self, Instant}; -use tracing::*; - -pub const MINING: StageId = StageId("Mining"); - -/// Conditions to launch Mining stage: -/// - have a valid PoBm (miner's behavior) -/// - have a miner API ready -#[derive(Debug)] -pub struct Mining { - pub miner_behavior: Behavior, -} - -impl Mining { - /// Prepare a block to be mine from pending txs & bxs - /// Inspired from https://github.com/openethereum/openethereum/blob/main/crates/ethcore/src/miner/miner.rs#L449 - pub fn prepare_block<'tx, 'db, E: EnvironmentKind>( - &mut self, - txn: &'tx mut MdbxTransaction<'db, RW, E>, - pending_txs: Vec<MessageWithSignature>, - pending_bxs: Vec<BehaviorWithSignature>, - canonical_chain_id: ChainId, - beneficiary: Address, - previous_header: BlockHeader, - new_network_difficulty: U256, - ) -> Block { - // Acquire sealing lock to avoid multiple block preparation - // Create an open_block - - let block_number = previous_header.number.0 + 1; - - // Get pending txs - // let pending_txs = vec![]; - // TODO reject invalid txs - check_min_tx_value_sent(pending_txs.clone()).unwrap(); - - // Get pending bxs - // let pending_bxs: Vec<BehaviorWithSignature> = vec![]; - - check_block_size(pending_txs.clone(), pending_bxs.clone()).unwrap(); - check_block_txbx_ratio(pending_txs.clone(), pending_bxs.clone()).unwrap(); - - // Verify TXs verify_for_pending_block() - for tx in pending_txs.clone() { - pre_validate_transaction(&tx, canonical_chain_id, Some(U256::new(1))).unwrap(); - // TODO reject invalid tx & notify pool? - } - - // Verify BXs - for bx in pending_bxs.clone() { - pre_validate_behavior(&bx, canonical_chain_id).unwrap(); - // TODO reject invalid bx & notify pool? - } - // TODO - let ommers: ArrayVec<BlockHeader, 2> = Default::default(); - // TODO from authoring params - let extra_data = Bytes::default(); - - let transactions_root = root_hash(&pending_txs); - let transactions_number = pending_txs.len().as_u64(); - let behaviors_root = root_hash(&pending_bxs); - let behavior_total_quantity = pending_bxs - .clone() - .into_iter() - .fold(0u64, |sum: u64, b: BehaviorWithSignature| { - sum + (b.quantify()) - }); - let timestamp = time::SystemTime::now() - .duration_since(time::UNIX_EPOCH) - .unwrap_or_default() - .as_secs(); - let ommers_hash = Block::ommers_hash(&ommers); - - // TODO Exec data - let behaviors_bloom = Bloom::zero(); - let logs_bloom = Bloom::zero(); - let receipts_root = H256::zero(); - let state_root = previous_header.state_root; - - // EXECUTE BLOCK - // Prepare the execution context. - let mut buffer = Buffer::new(&txn, Some(BlockNumber(block_number - 1))); - let chain_spec = chain::chain_config::read(&txn) - .unwrap() - .ok_or_else(|| format_err!("no chainspec found")) - .unwrap(); - let block_spec = chain_spec.collect_block_spec(block_number); - - let block_execution_spec = chain_spec.collect_block_spec(block_number); - let mut engine = engine_factory(None, chain_spec, None).unwrap(); - let mut analysis_cache = AnalysisCache::default(); - let mut tracer = NoopTracer; - - // Create not partial header - let open_header = BlockHeader { - parent_hash: previous_header.hash(), - beneficiary, - state_root, - extra_data, - logs_bloom, - behaviors_bloom, - difficulty: new_network_difficulty, - number: BlockNumber(block_number), - timestamp, - gas_limit: 0x1c9c380_u64, - gas_used: 0x0_u64, - base_fee_per_gas: Some(0x18aac2ec3d_u64.into()), - behavior_total_quantity, - transactions_number, - receipts_root, - ommers_hash, - transactions_root, - behaviors_root, - // TODO - vdf_proof_challenge: [0; 32], - vdf_difficulty: 0, - vdf_proof_result: [0; 516], - // TODO REMOVE ME ? - nonce: H64::zero(), - mix_hash: H256::zero(), - }; - - // Create tmp block body - let block_body = BlockBodyWithSenders { - transactions: pending_txs - .clone() - .into_iter() - .map(|tx| { - let sender = tx.recover_sender().unwrap(); - - MessageWithSender { - message: tx.message, - sender, - } - }) - .collect(), - behaviors: pending_bxs - .clone() - .into_iter() - .map(|bx| { - let sender = bx.recover_sender().unwrap(); - - BehaviorWithSender { - behavior: bx.behavior, - sender, - } - }) - .collect(), - ommers: ommers.clone(), - }; - - // => Do a mining processor - - let mut processor = ExecutionProcessor::new( - &mut buffer, - &mut tracer, - &mut analysis_cache, - &mut *engine, - &open_header, - &block_body, - &block_execution_spec, - ); - // Execute block without header checks - let receipts_result = - processor - .execute_without_check_and_write_block() - .map_err(|e| match e { - DuoError::Validation(error) => StageError::Validation { - block: BlockNumber(block_number), - error, - }, - DuoError::Internal(e) => StageError::Internal( - e.context(format!("Failed to execute block #{}", block_number)), - ), - }); - // println!("Block preparation receipts: {:?}", receipts); - - let receipts = receipts_result.unwrap(); - - // --- UPDATE HEADER (close_and_lock()) --- - // borrowed from `src/execution/processor.rs` method `execute_and_check_block()` - let receipts_root = root_hash(&receipts); - let gas_used = receipts.last().map(|r| r.cumulative_gas_used).unwrap_or(0); - let _base_fee_per_gas: Option<U256> = Some(0x18aac2ec3d_u64.into()); - let behaviors_bloom = receipts - .iter() - .filter(|r| r.tx_type == TxType::Behavior) - .fold(Bloom::zero(), |bloom, r| bloom | r.bloom); - let logs_bloom = receipts - .iter() - .filter(|r| r.tx_type != TxType::Behavior) - .fold(Bloom::zero(), |bloom, r| bloom | r.bloom); - - // https://blog.ethereum.org/2015/06/26/state-tree-pruning - // let _state_root = processor.state().logs().to_vec(); - // commit & get root from state :) - // processor.state().write_to_state(BlockNumber(block_number)); - - // header.compute_hash(); - - // Open block with empty vdf result - Block::new( - PartialHeader::from(open_header), // TODO - pending_txs.clone(), - pending_bxs.clone(), - ommers, - [0; 32], - [0; 516], - 0, - ) - } -} - -#[async_trait] -impl<'db, E> Stage<'db, E> for Mining -where - E: EnvironmentKind, -{ - fn id(&self) -> crate::StageId { - MINING - } - - async fn execute<'tx>( - &mut self, - tx: &'tx mut MdbxTransaction<'db, RW, E>, - input: StageInput, - ) -> Result<ExecOutput, StageError> - where - 'db: 'tx, - { - let _prev_stage = input - .previous_stage - .map(|(_, b)| b) - .unwrap_or(BlockNumber(0)); - - let prev_progress = input.stage_progress.unwrap_or_default(); - let starting_block = prev_progress + 1; - // let max_block = std::cmp::min(input - // .previous_stage.ok_or_else(|| format_err!("Execution stage cannot be executed first, but no previous stage progress specified"))?.1, self.max_block.unwrap_or(BlockNumber(u64::MAX))); - - // --- - - let chain_config = tx - .get(tables::Config, ())? - .ok_or_else(|| format_err!("No chain specification set"))?; - - let mut consensus_engine = engine_factory(None, chain_config.clone(), None)?; - consensus_engine.set_state(ConsensusState::recover(tx, &chain_config, starting_block)?); - - // let mut buffer = Buffer::new(tx, None); - // let mut analysis_cache = AnalysisCache::default(); - - let mut block_number = starting_block; - // let mut gas_since_start = 0; - // let mut gas_since_last_message = 0; - // let mut gas_since_history_commit = 0; - // let batch_started_at = Instant::now(); - // let first_started_at_gas = tx - // .get( - // tables::TotalGas, - // input.first_started_at.1.unwrap_or(BlockNumber(0)), - // )? - // .unwrap(); - let last_message = Instant::now(); - // let mut printed_at_least_once = false; - - // TODO forge new block & header - - let block_hash = accessors::chain::canonical_hash::read(tx, block_number)? - .ok_or_else(|| format_err!("No canonical hash found for block {}", block_number))?; - let header = accessors::chain::header::read(tx, block_number)? - .ok_or_else(|| format_err!("Header not found: {}/{:?}", block_number, block_hash))?; - // let block = accessors::chain::block_body::read_with_senders(tx, block_number)?.ok_or_else( - // || format_err!("Block body not found: {}/{:?}", block_number, block_hash), - // )?; - - // let block_spec = chain_config.collect_block_spec(block_number); - - if !consensus_engine.is_state_valid(&header) { - consensus_engine.set_state(ConsensusState::recover(tx, &chain_config, block_number)?); - } - - // --- DIFFICULTY --- - let mut previous_timestamps = vec![]; - for n in - (block_number.checked_sub(TIME_PERIOD_IN_BLOCKS).unwrap_or(0))..block_number.as_u64() - { - let header = accessors::chain::header::read(tx, n)?; - match header { - Some(header) => previous_timestamps.push(header.timestamp), - None => warn!("No header found for block number {}", n), - } - } - - let difficulty = get_network_difficulty( - header.difficulty, - compute_average_block_time_or_desired(previous_timestamps), - ); - - // Self::prepare_block( - // &mut self, - // tx, - // ChainId(63), - // Address::default(), - // header.clone(), - // difficulty, - // ); - - // --- VDF --- - let result = run_vdf( - header.parent_hash, - self.miner_behavior.clone(), - difficulty.as_u64(), - ) - .unwrap(); - - let now = Instant::now(); - - let elapsed = now - last_message; - // let ratio_complete = (current_total_gas - first_started_at_gas) as f64 - // / (total_gas - first_started_at_gas) as f64; - let elapsed_since_start = now - input.first_started_at.0; - - // let estimated_total_time = - // Duration::from_secs((elapsed_since_start.as_secs() as f64 / ratio_complete) as u64); - debug!("Elapsed since start {:?}", elapsed_since_start); - debug!("Elapsed mine {:?}", elapsed); - - block_number.0 += 1; - info!("Mined block {}", block_number); - - Ok(ExecOutput::Progress { - stage_progress: block_number, - done: !result.is_empty(), - reached_tip: true, - }) - } - async fn unwind<'tx>( - &mut self, - _: &'tx mut MdbxTransaction<'db, RW, E>, - input: UnwindInput, - ) -> anyhow::Result<UnwindOutput> - where - 'db: 'tx, - { - // Cancel VDF if still running & a new block was mined by somebody else ? - // otherwise nothing to undo or cleanup or destruct - Ok(UnwindOutput { - stage_progress: input.unwind_to, - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::{ - accessors::*, - kv::{new_mem_chaindata, traits::*}, - models::behavior::BehaviorSignature, - stages, - }; - use bytes::Bytes; - use bytes_literal::bytes; - use hex_literal::hex; - use std::{borrow::Cow, collections::BTreeMap, io::Read, sync::Arc}; - use tables::*; - - const CHAIN_ID: ChainId = ChainId(63); - - #[tokio::test] - async fn mine_test() { - // Arrange - let db = new_mem_chaindata().unwrap(); - let mut tx = db.begin_mutable().unwrap(); - - let mut s = String::new(); - std::fs::File::open("./src/res/chainspec/ecomobicoin.ron") - .unwrap() - .read_to_string(&mut s); - let new_chainspec = TableDecode::decode(s.as_bytes()).unwrap(); - - tx.set(tables::Config, (), new_chainspec).unwrap(); - tx.commit().unwrap(); - let mut tx = db.begin_mutable().unwrap(); - - let sender1 = Address::from(hex!("de1ef574fd619979b16fd043ea97c4f4536af2e6")); - let sender2 = Address::from(hex!("c93c9f9cac833846a66bce3bd9dc7c85e36463af")); - - let recipient1 = Address::from(hex!("f4148309cc30f2dd4ba117122cad6be1e3ba0e2b")); - let recipient2 = Address::from(hex!("d7fa8303df7073290f66ced1add5fe89dac0c462")); - - let block1 = BodyForStorage { - base_tx_id: 1.into(), - tx_amount: 2, - ommers: Default::default(), - }; - - let tx1_1 = MessageWithSignature { - message: Message::Legacy { - chain_id: Some(CHAIN_ID), - nonce: 1, - gas_price: 1_000_000.as_u256(), - gas_limit: 21_000, - action: TransactionAction::Call(recipient1), - value: 1.as_u256(), - input: Bytes::new(), - }, - signature: MessageSignature::new( - false, - H256::from(hex!( - "11d244ae19e3bb96d1bb864aa761d48e957984a154329f0de757cd105f9c7ac4" - )), - H256::from(hex!( - "0e3828d13eed24036941eb5f7fd65de57aad1184342f2244130d2941554342ba" - )), - ) - .unwrap(), - }; - - let tx1_2 = MessageWithSignature { - message: Message::Legacy { - chain_id: Some(CHAIN_ID), - nonce: 2, - gas_price: 1_000_000.as_u256(), - gas_limit: 21_000, - action: TransactionAction::Call(recipient1), - value: 0x100.as_u256(), - input: Bytes::new(), - }, - signature: MessageSignature::new( - true, - H256::from(hex!( - "9e8c555909921d359bfb0c2734841c87691eb257cb5f0597ac47501abd8ba0de" - )), - H256::from(hex!( - "7bfd0f8a11568ba2abc3ab4d2df6cb013359316704a3bd7ebd14bca5caf12b57" - )), - ) - .unwrap(), - }; - - let hash1 = H256::random(); - - chain::storage_body::write(&tx, 1, &block1).unwrap(); - // chain::storage_body::write(&tx, 2, &block2).unwrap(); - - tx.set(tables::CanonicalHeader, 1.into(), hash1).unwrap(); - let mut header = BlockHeader::default(); - header.difficulty = U256::new(1); - tx.set(tables::Header, 1.into(), header).unwrap(); - - chain::tx::write(&tx, block1.base_tx_id, &[tx1_1, tx1_2]).unwrap(); - // chain::tx::write(&tx, block2.base_tx_id, &[tx2_1, tx2_2, tx2_3]).unwrap(); - - chain::tl::write(&tx, hash1, 1.into()).unwrap(); - // chain::tl::write(&tx, hash1_2, 1.into()).unwrap(); - - let input = bytes!("01020304b87502f872041a8459682f008459682f0d8252089461815774383099e24810ab832a5b2a5425c154d58829a2241af62c000080c001a059e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafda0016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469"); - let miner_behavior = Behavior::new(ChainId(63), 1672534861, 100_000u64 << 53 / 6500, input); - - let mut stage = Mining { miner_behavior }; - - let stage_input = StageInput { - restarted: false, - first_started_at: (Instant::now(), Some(BlockNumber(0))), - previous_stage: Some((stages::BODIES, 1.into())), - stage_progress: Some(0.into()), - }; - - // Act - let output: ExecOutput = stage.execute(&mut tx, stage_input).await.unwrap(); - tx.commit().unwrap(); - let mut tx = db.begin_mutable().unwrap(); - - // Assert - assert_eq!( - output, - ExecOutput::Progress { - stage_progress: 2.into(), - done: true, - reached_tip: true, - } - ); - // assert_eq!(dbg!(chain::tl::read(&tx, hashed_tx).unwrap()), block_number); - } - - // #[ignore] - #[test] - fn prepare_block_test() { - // ARRANGE - let db = new_mem_chaindata().unwrap(); - let mut txn = db.begin_mutable().unwrap(); - - let mut s = String::new(); - std::fs::File::open("./src/res/chainspec/ecomobicoin.ron") - .unwrap() - .read_to_string(&mut s); - let new_chainspec = TableDecode::decode(s.as_bytes()).unwrap(); - - txn.set(tables::Config, (), new_chainspec).unwrap(); - - let sender = hex!("6b4cd3844587b13512c5db3f69bac569a65eafd7").into(); - txn.set( - tables::Account, - sender, - crate::models::Account { - balance: U256::new(2 * ETHER), - ..Default::default() - }, - ) - .unwrap(); - - let input = bytes!("01020304b87502f872041a8459682f008459682f0d8252089461815774383099e24810ab832a5b2a5425c154d58829a2241af62c000080c001a059e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafda0016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469"); - let miner_behavior = Behavior::new(CHAIN_ID, 1672534861, 99_000_000_000_000, input); - let mut stage = Mining { miner_behavior }; - - let transactions = vec![ - MessageWithSignature { - message: Message::EIP1559 { - chain_id: CHAIN_ID, - nonce: 0, - max_priority_fee_per_gas: 0x50a3d0b5d_u64.into(), - max_fee_per_gas: 0x23a9e38cf8_u64.into(), - gas_limit: 1_200_000, - action: TransactionAction::Call(hex!("a57bd00134b2850b2a1c55860c9e9ea100fdd6cf").into()), - value: U256::new(ETHER), - input: hex!("1cff79cd000000000000000000000000aa2ec16d77cfc057fb9c516282fef9da9de1e987000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001844f0c7c0a00000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000056178a0d5f301baf6cf3e1cd53d9863437345bf9000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000a2a15d09519be00000000000000000000000000000000000000000000000daadf45a4bb347757560000000000000000000000000000000000000000000000000003453af3f6dd960000000000000000000000000000000000000003f994c7f39b6af041a3c553270000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000061303192000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec().into(), - access_list: vec![], - }, - signature: MessageSignature::new(false, hex!("9a8548ba3759730fe25be0412c0b183ec975d15da2f12653d5f0a2016ca01f27"), hex!("6d93f2176bfda918c06365e507c6c66a16d30b9e76d2d8e5a7f2802e3bcc6593")).unwrap(), - }, - ]; - - let behaviors = vec![BehaviorWithSignature { - behavior: Behavior { - chain_id: CHAIN_ID, - timestamp: 1672534861, // 2023/01/01 01:01:01 - quantity: 10_000, - input: hex!( - "a0712d680000000000000000000000000000000000000000000000000000000000000002" - ) - .to_vec() - .into(), - }, - signature: BehaviorSignature::new( - true, - // TODO replace with correct signature - hex!("70bcb39ac6f540498c3adfdf3a23ecce5cf7b4f75b0674c157da02350edf8ed4"), - hex!("40e997c09def486888c34e77565cce82b348d0035e2ea36bf125252f7895ff3c"), - ) - .unwrap(), - }]; - - // ACT - let prepared_block = stage.prepare_block( - &mut txn, - transactions, - behaviors, - CHAIN_ID, - Address::zero(), - BlockHeader::empty(), - U256::ONE, - ); - - // ASSERT - assert_eq!(H256::default(), prepared_block.header.receipts_root) - } -} diff --git a/src/stages/mod.rs b/src/stages/mod.rs index 3d314134abf1ea3b842414b607143721eff07416..60cc1d45c002fa80ed4312a59bcca8459a3f63bd 100644 --- a/src/stages/mod.rs +++ b/src/stages/mod.rs @@ -9,7 +9,6 @@ mod history_index; mod interhashes; mod log_address_index; mod log_topic_index; -mod mining; mod sender_recovery; pub mod stage_util; mod total_gas_index; diff --git a/src/state/genesis.rs b/src/state/genesis.rs index edf920fde6dff5fd6647cf9924d892de195e375f..2464e3b5c566b4681806611d1677bcec906e229f 100644 --- a/src/state/genesis.rs +++ b/src/state/genesis.rs @@ -148,7 +148,6 @@ where txn.set(tables::Header, genesis, header.clone())?; txn.set(tables::CanonicalHeader, genesis, block_hash)?; - println!("ecomobicoin {:?}", block_hash); txn.set(tables::HeaderNumber, block_hash, genesis)?; txn.set(tables::HeadersTotalDifficulty, genesis, header.difficulty)?;