Skip to content

Commit

Permalink
Restore main state
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAR2 committed Sep 3, 2024
1 parent 633deb2 commit c46b7bd
Show file tree
Hide file tree
Showing 23 changed files with 374 additions and 703 deletions.
1 change: 0 additions & 1 deletion bin/oe/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
*client.best_block_header().gas_limit(),
base_fee,
allow_non_eoa_sender,
None,
);

let connection_filter = connection_filter_address.map(|a| {
Expand Down
33 changes: 0 additions & 33 deletions crates/ethcore/res/contracts/fees.json

This file was deleted.

67 changes: 1 addition & 66 deletions crates/ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ use types::{
transaction::{Error as TransactionError, SignedTransaction},
};

use crate::{executive::FeesParams, trace::{ExecutiveTracer, Tracer, RewardType}};

/// Block that is ready for transactions to be added.
///
/// It's a bit like a Vec<Transaction>, except that whenever a transaction is pushed, we execute it and
/// maintain the system `state()`. We also archive execution receipts in preparation for later block creation.
pub struct OpenBlock<'x> {
block: ExecutedBlock,
engine: &'x dyn EthEngine,
gas_price: Option<U256>,
fees_params: Option<FeesParams>,
}

/// Just like `OpenBlock`, except that we've applied `Engine::on_close_block`, finished up the non-seal header fields,
Expand Down Expand Up @@ -192,8 +188,6 @@ impl<'x> OpenBlock<'x> {
let mut r = OpenBlock {
block: ExecutedBlock::new(state, last_hashes, tracing),
engine: engine,
gas_price: None,
fees_params: None,
};

r.block.header.set_parent_hash(parent.hash());
Expand Down Expand Up @@ -224,9 +218,6 @@ impl<'x> OpenBlock<'x> {
engine.machine().on_new_block(&mut r.block)?;
engine.on_new_block(&mut r.block, is_epoch_begin, &mut ancestry.into_iter())?;

r.update_gas_price();
r.update_fees_params();

Ok(r)
}

Expand Down Expand Up @@ -291,7 +282,6 @@ impl<'x> OpenBlock<'x> {
let outcome = self.block.state.apply(
&env_info,
self.engine.machine(),
self.fees_params,
&t,
self.block.traces.is_enabled(),
)?;
Expand All @@ -311,25 +301,6 @@ impl<'x> OpenBlock<'x> {
.expect("receipt just pushed; qed"))
}

/// Returns gas price getted from from contract during block creation
pub fn get_current_gas_price(&self) -> Option<U256> {
self.gas_price
}

/// Gets the current gas price from the fees contract.
fn update_gas_price(&mut self) {
if let Some(price) = self.engine.get_gas_price(&self.block.header) {
self.gas_price = Some(price);
}
}

/// Get the current fees params from the fees contract.
fn update_fees_params(&mut self) {
if let Some(params) = self.engine.get_fee_params(&self.block.header) {
self.fees_params = Some(params);
}
}

/// Push transactions onto the block.
#[cfg(not(feature = "slow-blocks"))]
fn push_transactions(&mut self, transactions: Vec<SignedTransaction>) -> Result<(), Error> {
Expand Down Expand Up @@ -401,41 +372,6 @@ impl<'x> OpenBlock<'x> {
pub fn close_and_lock(self) -> Result<LockedBlock, Error> {
let mut s = self;

if let Some(params) = s.fees_params {
let (author_fees, governance_fees) = s.block.transactions.iter().enumerate()
.filter_map(|(i, tx)| {
if i == 0 {
// Handling the first transaction in the block
let gas_used = s.block.receipts[i].gas_used;
tx.gas_price().map(|gas_price| (gas_used, gas_price))
} else {
let prev = &s.block.receipts[i-1];
let current = &s.block.receipts[i];
let gas_used = current.gas_used - prev.gas_used;
tx.gas_price().map(|gas_price| (gas_used, gas_price))
}
})
.fold((U256::zero(), U256::zero()), |(acc_author, acc_governance), (gas_used, gas_price)| {
//Assume that transaction is checked already
let (fees_value, _) = gas_used.overflowing_mul(gas_price);
let governance_part = fees_value.saturating_mul(params.governance_part) / U256::from(1_000_000);
let author_part = fees_value.saturating_sub(governance_part);
(acc_author.saturating_add(author_part), acc_governance.saturating_add(governance_part))
});

let author_addr = *s.block.header.author();
if let Tracing::Enabled(ref mut traces) = *s.block.traces_mut() {
let mut tracer = ExecutiveTracer::default();
if author_fees != U256::zero() {
tracer.trace_reward(author_addr, author_fees, RewardType::Uncle.into());
}
if governance_fees != U256::zero() {
tracer.trace_reward(params.address, governance_fees, RewardType::EmptyStep.into());
}
traces.push(tracer.drain().into());
}
}

// t_nb 8.5.1 engine applies block rewards (Ethash and AuRa do.Clique is empty)
s.engine.on_close_block(&mut s.block)?;

Expand Down Expand Up @@ -468,6 +404,7 @@ impl<'x> OpenBlock<'x> {
Ok(LockedBlock { block: s.block })
}

#[cfg(test)]
/// Return mutable block reference. To be used in tests only.
pub fn block_mut(&mut self) -> &mut ExecutedBlock {
&mut self.block
Expand Down Expand Up @@ -520,8 +457,6 @@ impl ClosedBlock {
OpenBlock {
block: block,
engine: engine,
gas_price: None,
fees_params: None,
}
}
}
Expand Down
20 changes: 2 additions & 18 deletions crates/ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ use db::{keys::BlockDetails, Readable, Writable};
pub use reth_util::queue::ExecutionQueue;
pub use types::{block_status::BlockStatus, blockchain_info::BlockChainInfo};
pub use verification::QueueInfo as BlockQueueInfo;

use_contract!(registry, "res/contracts/registrar.json");

const ANCIENT_BLOCKS_QUEUE_SIZE: usize = 4096;
Expand Down Expand Up @@ -803,10 +802,7 @@ impl Importer {
receipts: Some(&receipts),
};

match self
.engine
.signals_epoch_end(header, auxiliary, self.engine.machine())
{
match self.engine.signals_epoch_end(header, auxiliary, self.engine.machine()) {
EpochChange::Yes(proof) => {
use engines::Proof;
let proof = match proof {
Expand Down Expand Up @@ -845,7 +841,7 @@ impl Importer {
let machine = self.engine.machine();
let schedule = machine.schedule(env_info.number);
let res = Executive::new(&mut state, &env_info, &machine, &schedule)
.transact(&transaction, options, None);
.transact(&transaction, options);

let res = match res {
Err(e) => {
Expand Down Expand Up @@ -2090,7 +2086,6 @@ impl Call for Client {
let mut clone = state.clone();
let machine = self.engine.machine();
let schedule = machine.schedule(env_info.number);
// fees_params is None because they have no influence on gas
Executive::new(&mut clone, &env_info, &machine, &schedule)
.transact_virtual(&tx, options())
};
Expand Down Expand Up @@ -2830,10 +2825,6 @@ impl BlockChainClient for Client {
fn state_data(&self, hash: &H256) -> Option<Bytes> {
self.state_db.read().journal_db().state(hash)
}

fn latest_state_and_header_external(&self) -> (State<StateDB>, Header) {
self.latest_state_and_header()
}
}

impl IoClient for Client {
Expand Down Expand Up @@ -3163,13 +3154,6 @@ impl super::traits::EngineClient for Client {
fn block_header(&self, id: BlockId) -> Option<encoded::Header> {
<dyn BlockChainClient>::block_header(self, id)
}

fn proxy_call(&self, transaction: &SignedTransaction, analytics: CallAnalytics, state: &mut State<StateDB>, header: &Header) -> Option<Bytes> {
match self.call(transaction, analytics, state, header) {
Ok(executed) => Some(executed.output),
Err(_) => None,
}
}
}

impl ProvingBlockChainClient for Client {
Expand Down
10 changes: 1 addition & 9 deletions crates/ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ use engines::EthEngine;
use error::{Error, EthcoreResult};
use executed::CallError;
use executive::Executed;
use state::{StateInfo, State};
use state::StateInfo;
use trace::LocalizedTrace;
use verification::queue::{kind::blocks::Unverified, QueueInfo as BlockQueueInfo};

use crate::state_db::StateDB;

/// State information to be used during client query
pub enum StateOrBlock {
/// State to be used, may be pending
Expand Down Expand Up @@ -492,9 +490,6 @@ pub trait BlockChainClient:

/// Returns true, if underlying import queue is processing possible fork at the moment
fn is_processing_fork(&self) -> bool;

/// Returns latest known state and header. Created only to get gas price on the verification stage.
fn latest_state_and_header_external(&self) -> (State<StateDB>, Header);
}

/// The data required for a `Client` to create a transaction.
Expand Down Expand Up @@ -622,9 +617,6 @@ pub trait EngineClient: Sync + Send + ChainInfo {

/// Get raw block header data by block id.
fn block_header(&self, id: BlockId) -> Option<encoded::Header>;

/// Proxy to the Client::call to use in engine. Added to get gas_price.
fn proxy_call(&self, transaction: &SignedTransaction, analytics: CallAnalytics, state: &mut State<StateDB>, header: &Header) -> Option<Bytes>;
}

/// Extended client interface for providing proofs of the state.
Expand Down
39 changes: 0 additions & 39 deletions crates/ethcore/src/engines/authority_round/block_gas_price.rs

This file was deleted.

53 changes: 0 additions & 53 deletions crates/ethcore/src/engines/authority_round/block_tx_fee.rs

This file was deleted.

Loading

0 comments on commit c46b7bd

Please sign in to comment.