diff --git a/lib/ain-evm/src/handler.rs b/lib/ain-evm/src/handler.rs index a662e7a24e7..4f9259d284c 100644 --- a/lib/ain-evm/src/handler.rs +++ b/lib/ain-evm/src/handler.rs @@ -15,7 +15,6 @@ use log::debug; use primitive_types::H256; use std::error::Error; use std::sync::Arc; -use std::time::{SystemTime, UNIX_EPOCH}; const GENESIS_STATE_ROOT: &str = "0xbc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a"; @@ -49,7 +48,8 @@ impl Handlers { context: u64, update_state: bool, difficulty: u32, - miner_address: Option, + beneficiary: H160, + timestamp: u64, ) -> Result<(BlockAny, Vec), Box> { let mut all_transactions = Vec::with_capacity(self.evm.tx_queues.len(context)); let mut failed_transactions = Vec::with_capacity(self.evm.tx_queues.len(context)); @@ -134,7 +134,7 @@ impl Handlers { let block = Block::new( PartialHeader { parent_hash, - beneficiary: miner_address.unwrap_or_default(), + beneficiary, state_root: if update_state { backend.commit() } else { @@ -146,10 +146,7 @@ impl Handlers { number: parent_number + 1, gas_limit: U256::from(30_000_000), gas_used: U256::from(gas_used), - timestamp: SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() as u64, + timestamp, extra_data: Vec::default(), mix_hash: H256::default(), nonce: H64::default(), diff --git a/lib/ain-rs-exports/src/lib.rs b/lib/ain-rs-exports/src/lib.rs index cffd04f5bfd..4a1b69a620e 100644 --- a/lib/ain-rs-exports/src/lib.rs +++ b/lib/ain-rs-exports/src/lib.rs @@ -1,5 +1,5 @@ use ain_evm::transaction::{self, SignedTx}; -use ain_grpc::{init_runtime, start_servers, stop_runtime}; +use ain_grpc::{init_evm_runtime, start_servers, stop_runtime}; use ain_evm::runtime::RUNTIME; use log::debug; @@ -56,6 +56,7 @@ pub mod ffi { update_state: bool, difficulty: u32, miner_address: [u8; 20], + timestamp: u64, ) -> Result; unsafe fn init(_argc: i32, _argv: *const *const c_char); @@ -181,12 +182,16 @@ fn evm_finalize( update_state: bool, difficulty: u32, miner_address: [u8; 20], + timestamp: u64, ) -> Result> { let eth_address = H160::from(miner_address); - let (block, failed_txs) = - RUNTIME - .handlers - .finalize_block(context, update_state, difficulty, Some(eth_address))?; + let (block, failed_txs) = RUNTIME.handlers.finalize_block( + context, + update_state, + difficulty, + eth_address, + timestamp, + )?; Ok(ffi::FinalizeBlockResult { block_header: block.header.rlp_bytes().into(), failed_transactions: failed_txs, diff --git a/src/miner.cpp b/src/miner.cpp index c0dc941620b..17f69d9480a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -248,7 +248,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc std::vector evmHeader{}; if (IsEVMEnabled(nHeight, mnview)) { std::array dummyAddress{}; - auto blockResult = evm_finalize(evmContext, false, pos::GetNextWorkRequired(pindexPrev, pblock->nTime, consensus), dummyAddress); + auto blockResult = evm_finalize(evmContext, false, pos::GetNextWorkRequired(pindexPrev, pblock->nTime, consensus), dummyAddress, blockTime); evmHeader.resize(blockResult.block_header.size()); std::copy(blockResult.block_header.begin(), blockResult.block_header.end(), evmHeader.begin()); diff --git a/src/validation.cpp b/src/validation.cpp index 30e0456154b..0809d2fd961 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2906,7 +2906,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl std::copy(minter.begin(), minter.end(), minerAddress.begin()); } - const auto blockResult = evm_finalize(evmContext, true, block.nBits, minerAddress); + const auto blockResult = evm_finalize(evmContext, true, block.nBits, minerAddress, block.GetBlockTime()); if (!blockResult.failed_transactions.empty()) { std::vector failedTransactions;