Skip to content

Commit

Permalink
moved block_gas_limit_contract_transitions to AuRa params
Browse files Browse the repository at this point in the history
  • Loading branch information
vkomenda authored and afck committed Aug 30, 2019
1 parent a7fd6b3 commit 748a8c7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 deletions.
20 changes: 16 additions & 4 deletions ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ pub struct AuthorityRoundParams {
/// If set, this is the block number at which the consensus engine switches from AuRa to AuRa
/// with POSDAO modifications.
pub posdao_transition: Option<BlockNumber>,
/// The addresses of a contracts that determine the block gas limit with their associated block
/// numbers.
pub block_gas_limit_contract_transitions: BTreeMap<u64, Address>,
}

const U16_MAX: usize = ::std::u16::MAX as usize;
Expand Down Expand Up @@ -149,7 +152,12 @@ impl From<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams {
BlockRewardContract::new_from_address(address.into())
);
}

let block_gas_limit_contract_transitions: BTreeMap<_, _> =
p.block_gas_limit_contract_transitions
.unwrap_or_default()
.into_iter()
.map(|(block_num, address)| (block_num.into(), address.into()))
.collect();
AuthorityRoundParams {
step_durations,
validators: new_validator_set_posdao(p.validators, p.posdao_transition.map(Into::into)),
Expand All @@ -167,6 +175,7 @@ impl From<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams {
strict_empty_steps_transition: p.strict_empty_steps_transition.map_or(0, Into::into),
randomness_contract_address: p.randomness_contract_address.map(Into::into),
posdao_transition: p.posdao_transition.map(Into::into),
block_gas_limit_contract_transitions,
}
}
}
Expand Down Expand Up @@ -534,6 +543,8 @@ pub struct AuthorityRound {
/// The block number at which the consensus engine switches from AuRa to AuRa with POSDAO
/// modifications.
posdao_transition: Option<BlockNumber>,
/// The addresses of a contracts that determine the block gas limit.
block_gas_limit_contract_transitions: BTreeMap<u64, Address>,
}

// header-chain validator.
Expand Down Expand Up @@ -804,9 +815,10 @@ impl AuthorityRound {
maximum_empty_steps: our_params.maximum_empty_steps,
quorum_2_3_transition: our_params.quorum_2_3_transition,
strict_empty_steps_transition: our_params.strict_empty_steps_transition,
machine: machine,
machine,
randomness_contract_address: our_params.randomness_contract_address,
posdao_transition: our_params.posdao_transition,
block_gas_limit_contract_transitions: our_params.block_gas_limit_contract_transitions,
});

// Do not initialize timeouts for tests.
Expand Down Expand Up @@ -1802,8 +1814,7 @@ impl Engine<EthereumMachine> for AuthorityRound {
}

fn gas_limit_override(&self, header: &Header) -> Option<U256> {
let (_, &address) = self.machine.params().block_gas_limit_contract.range(..=header.number()).last()?;

let (_, &address) = self.block_gas_limit_contract_transitions.range(..=header.number()).last()?;
let client = match self.client.read().as_ref().and_then(|weak| weak.upgrade()) {
Some(client) => client,
None => {
Expand Down Expand Up @@ -1875,6 +1886,7 @@ mod tests {
quorum_2_3_transition: 0,
randomness_contract_address: None,
posdao_transition: Some(0),
block_gas_limit_contract_transitions: BTreeMap::new(),
};

// mutate aura params
Expand Down
3 changes: 0 additions & 3 deletions ethcore/src/spec/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ pub struct CommonParams {
pub subprotocol_name: String,
/// Minimum gas limit.
pub min_gas_limit: U256,
/// The address of a contract that determines the block gas limit.
pub block_gas_limit_contract: BTreeMap<BlockNumber, Address>,
/// Fork block to check.
pub fork_block: Option<(BlockNumber, H256)>,
/// EIP150 transition block number.
Expand Down Expand Up @@ -244,7 +242,6 @@ impl From<ethjson::spec::Params> for CommonParams {
},
subprotocol_name: p.subprotocol_name.unwrap_or_else(|| "eth".to_owned()),
min_gas_limit: p.min_gas_limit.into(),
block_gas_limit_contract: p.block_gas_limit_contract.map(|bglc| bglc.into()).unwrap_or_default(),
fork_block: if let (Some(n), Some(h)) = (p.fork_block, p.fork_hash) {
Some((n.into(), h.into()))
} else {
Expand Down
18 changes: 16 additions & 2 deletions json/src/spec/authority_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,23 @@ pub struct AuthorityRoundParams {
/// The block number at which the consensus engine switches from AuRa to AuRa with POSDAO
/// modifications.
pub posdao_transition: Option<Uint>,
/// The addresses of contracts that determine the block gas limit starting from the block number
/// associated with each of those contracts.
pub block_gas_limit_contract_transitions: Option<BTreeMap<Uint, Address>>,
}

/// Authority engine deserialization.
#[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AuthorityRound {
/// Ethash params.
/// Authority Round parameters.
pub params: AuthorityRoundParams,
}

#[cfg(test)]
mod tests {
use std::str::FromStr;

use ethereum_types::{U256, H160};
use uint::Uint;
use serde_json;
Expand All @@ -108,7 +113,11 @@ mod tests {
"validateStepTransition": 150,
"blockReward": 5000000,
"maximumUncleCountTransition": 10000000,
"maximumUncleCount": 5
"maximumUncleCount": 5,
"blockGasLimitContractTransitions": {
"10": "0x1000000000000000000000000000000000000001",
"20": "0x2000000000000000000000000000000000000002"
}
}
}"#;

Expand All @@ -119,5 +128,10 @@ mod tests {
assert_eq!(deserialized.params.immediate_transitions, None);
assert_eq!(deserialized.params.maximum_uncle_count_transition, Some(Uint(10_000_000.into())));
assert_eq!(deserialized.params.maximum_uncle_count, Some(Uint(5.into())));
let expected_bglc =
[(Uint(10.into()), Address(H160::from_str("1000000000000000000000000000000000000001").unwrap())),
(Uint(20.into()), Address(H160::from_str("2000000000000000000000000000000000000002").unwrap()))];
assert_eq!(deserialized.params.block_gas_limit_contract_transitions,
Some(expected_bglc.to_vec().into_iter().collect()));
}
}
32 changes: 2 additions & 30 deletions json/src/spec/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub struct Params {
pub maximum_extra_data_size: Uint,
/// Minimum gas limit.
pub min_gas_limit: Uint,
/// The address of a contract that determines the block gas limit.
pub block_gas_limit_contract: Option<BlockGasLimitContract>,

/// Network id.
#[serde(rename = "networkID")]
Expand Down Expand Up @@ -131,36 +129,14 @@ pub struct Params {
pub kip6_transition: Option<Uint>,
}

/// A contract that determines block gas limits can be configured either as a single address, or as a map, assigning
/// to each starting block number the contract address that should be used from that block on.
#[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields, untagged)]
pub enum BlockGasLimitContract {
/// A single address for a block gas limit contract.
Single(Address),
/// A map from block numbers to the contract addresses that should be used for the gas limit after that block.
Transitions(BTreeMap<Uint, Address>),
}

impl From<BlockGasLimitContract> for BTreeMap<u64, H160> {
fn from(contract: BlockGasLimitContract) -> Self {
match contract {
BlockGasLimitContract::Single(Address(addr)) => iter::once((0, addr)).collect(),
BlockGasLimitContract::Transitions(transitions) => {
transitions.into_iter().map(|(Uint(block), Address(addr))| (block.into(), addr)).collect()
}
}
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;
use serde_json;
use uint::Uint;
use ethereum_types::{U256, H160};
use hash::Address;
use spec::params::{BlockGasLimitContract, Params};
use spec::params::Params;

#[test]
fn params_deserialization() {
Expand All @@ -173,11 +149,7 @@ mod tests {
"accountStartNonce": "0x01",
"gasLimitBoundDivisor": "0x20",
"maxCodeSize": "0x1000",
"wasmActivationTransition": "0x1010",
"blockGasLimitContract": {
"10": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"20": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
}
"wasmActivationTransition": "0x1010"
}"#;

let deserialized: Params = serde_json::from_str(s).unwrap();
Expand Down

0 comments on commit 748a8c7

Please sign in to comment.