Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Implement eth/64 (EIP-2364) and drop support for eth/62 #11472

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,4 @@ members = [
"chainspec",
"ethcore/wasm/run",
"evmbin",
"util/EIP-2124"
]
1 change: 1 addition & 0 deletions ethcore/spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ keccak-hash = "0.4.0"
kvdb-memorydb = "0.4.0"
log = "0.4.8"
machine = { path = "../machine" }
maplit = "1"
null-engine = { path = "../engines/null-engine" }
pod = { path = "../pod" }
rlp = "0.4.2"
Expand Down
73 changes: 67 additions & 6 deletions ethcore/spec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Parameters for a block chain.

use std::{
collections::BTreeMap,
collections::{BTreeMap, BTreeSet},
convert::TryFrom,
fmt,
io::Read,
Expand Down Expand Up @@ -47,6 +47,7 @@ use instant_seal::{InstantSeal, InstantSealParams};
use keccak_hash::{KECCAK_NULL_RLP, keccak};
use log::{trace, warn};
use machine::{executive::Executive, Machine, substate::Substate};
use maplit::btreeset;
use null_engine::NullEngine;
use pod::PodState;
use rlp::{Rlp, RlpStream};
Expand Down Expand Up @@ -218,6 +219,8 @@ pub struct Spec {
pub seal_rlp: Bytes,
/// Hardcoded synchronization. Allows the light client to immediately jump to a specific block.
pub hardcoded_sync: Option<SpecHardcodedSync>,
/// List of hard forks in the network.
pub hard_forks: BTreeSet<BlockNumber>,
/// Contract constructors to be executed on genesis.
pub constructors: Vec<(Address, Bytes)>,
/// May be pre-populated if we know this in advance.
Expand Down Expand Up @@ -280,7 +283,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er

let hardcoded_sync = s.hardcoded_sync.map(Into::into);

let engine = Spec::engine(spec_params, s.engine, params, builtins);
let (engine, hard_forks) = Spec::engine(spec_params, s.engine, params, builtins);
let author = g.author;
let timestamp = g.timestamp;
let difficulty = g.difficulty;
Expand Down Expand Up @@ -317,6 +320,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
timestamp,
extra_data: g.extra_data,
seal_rlp,
hard_forks,
hardcoded_sync,
constructors,
genesis_state,
Expand Down Expand Up @@ -347,20 +351,77 @@ impl Spec {
engine_spec: ethjson::spec::Engine,
params: CommonParams,
builtins: BTreeMap<Address, Builtin>,
) -> Arc<dyn Engine> {
) -> (Arc<dyn Engine>, BTreeSet<BlockNumber>) {
let mut hard_forks = btreeset![
params.eip150_transition,
params.eip160_transition,
params.eip161abc_transition,
params.eip161d_transition,
params.eip98_transition,
params.eip658_transition,
params.eip155_transition,
params.validate_receipts_transition,
params.validate_chain_id_transition,
params.eip140_transition,
params.eip210_transition,
params.eip211_transition,
params.eip214_transition,
params.eip145_transition,
params.eip1052_transition,
params.eip1283_transition,
params.eip1283_disable_transition,
params.eip1283_reenable_transition,
params.eip1014_transition,
params.eip1706_transition,
params.eip1344_transition,
params.eip1884_transition,
params.eip2028_transition,
params.eip2200_advance_transition,
params.dust_protection_transition,
params.wasm_activation_transition,
params.kip4_transition,
params.kip6_transition,
params.max_code_size_transition,
params.transaction_permission_contract_transition,
];
// BUG: Rinkeby has homestead transition at block 1 but we can't reflect that in specs for non-Ethash networks
if params.network_id == 0x4 {
hard_forks.insert(1);
}

let machine = Self::machine(&engine_spec, params, builtins);

match engine_spec {
let engine: Arc<dyn Engine> = match engine_spec {
ethjson::spec::Engine::Null(null) => Arc::new(NullEngine::new(null.params.into(), machine)),
ethjson::spec::Engine::Ethash(ethash) => Arc::new(Ethash::new(spec_params.cache_dir, ethash.params.into(), machine, spec_params.optimization_setting)),
ethjson::spec::Engine::Ethash(ethash) => {
// Specific transitions for Ethash-based networks
for block in &[ethash.params.homestead_transition, ethash.params.dao_hardfork_transition] {
if let Some(block) = *block {
hard_forks.insert(block.into());
}
}

// Ethereum's difficulty bomb delay is a fork too
if let Some(delays) = &ethash.params.difficulty_bomb_delays {
for delay in delays.keys().copied() {
hard_forks.insert(delay.into());
}
}
Arc::new(Ethash::new(spec_params.cache_dir, ethash.params.into(), machine, spec_params.optimization_setting))
},
ethjson::spec::Engine::InstantSeal(Some(instant_seal)) => Arc::new(InstantSeal::new(instant_seal.params.into(), machine)),
ethjson::spec::Engine::InstantSeal(None) => Arc::new(InstantSeal::new(InstantSealParams::default(), machine)),
ethjson::spec::Engine::BasicAuthority(basic_authority) => Arc::new(BasicAuthority::new(basic_authority.params.into(), machine)),
ethjson::spec::Engine::Clique(clique) => Clique::new(clique.params.into(), machine)
.expect("Failed to start Clique consensus engine."),
ethjson::spec::Engine::AuthorityRound(authority_round) => AuthorityRound::new(authority_round.params.into(), machine)
.expect("Failed to start AuthorityRound consensus engine."),
}
};

// Dummy value is a filler for non-existent transitions
hard_forks.remove(&BlockNumber::max_value());

(engine, hard_forks)
}

/// Get common blockchain parameters.
Expand Down
1 change: 1 addition & 0 deletions ethcore/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ devp2p = { package = "ethcore-network-devp2p", path = "../../util/network-devp2p
enum_primitive = "0.1.1"
ethcore-io = { path = "../../util/io" }
ethcore-private-tx = { path = "../private-tx" }
ethereum-forkid = "0.1"
ethereum-types = "0.8.0"
fastmap = { path = "../../util/fastmap" }
futures = "0.1"
Expand Down
16 changes: 11 additions & 5 deletions ethcore/sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

use std::sync::{Arc, mpsc, atomic};
use std::collections::{HashMap, BTreeMap};
use std::collections::{BTreeSet, HashMap, BTreeMap};
use std::io;
use std::ops::RangeInclusive;
use std::time::Duration;
Expand All @@ -27,10 +27,11 @@ use crate::sync_io::NetSyncIo;
use crate::light_sync::{self, SyncInfo};
use crate::private_tx::PrivateTxHandler;
use crate::chain::{
fork_filter::ForkFilterApi,
sync_packet::SyncPacket::{PrivateTransactionPacket, SignedPrivateTransactionPacket},
ChainSyncApi, SyncState, SyncStatus as EthSyncStatus, ETH_PROTOCOL_VERSION_62,
ETH_PROTOCOL_VERSION_63, PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2,
PAR_PROTOCOL_VERSION_3, PAR_PROTOCOL_VERSION_4,
ChainSyncApi, SyncState, SyncStatus as EthSyncStatus,
ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64,
PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2, PAR_PROTOCOL_VERSION_3, PAR_PROTOCOL_VERSION_4,
};

use bytes::Bytes;
Expand Down Expand Up @@ -268,6 +269,8 @@ pub struct Params {
pub executor: Executor,
/// Blockchain client.
pub chain: Arc<dyn BlockChainClient>,
/// Forks.
pub forks: BTreeSet<BlockNumber>,
/// Snapshot service.
pub snapshot_service: Arc<dyn SnapshotService>,
/// Private tx service.
Expand Down Expand Up @@ -348,10 +351,13 @@ impl EthSync {
})
};

let fork_filter = ForkFilterApi::new(&*params.chain, params.forks);

let (priority_tasks_tx, priority_tasks_rx) = mpsc::channel();
let sync = ChainSyncApi::new(
params.config,
&*params.chain,
fork_filter,
params.private_tx_handler.as_ref().cloned(),
priority_tasks_rx,
);
Expand Down Expand Up @@ -605,7 +611,7 @@ impl ChainNotify for EthSync {
_ => {},
}

self.network.register_protocol(self.eth_handler.clone(), self.subprotocol_name, &[ETH_PROTOCOL_VERSION_62, ETH_PROTOCOL_VERSION_63])
self.network.register_protocol(self.eth_handler.clone(), self.subprotocol_name, &[ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_64])
.unwrap_or_else(|e| warn!("Error registering ethereum protocol: {:?}", e));
// register the warp sync subprotocol
self.network.register_protocol(self.eth_handler.clone(), WARP_SYNC_PROTOCOL_ID, &[PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2, PAR_PROTOCOL_VERSION_3, PAR_PROTOCOL_VERSION_4])
Expand Down
Loading