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

Extract engines to own crates #10966

Merged
merged 74 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
ddeef45
Add client-traits crate
dvdplm Aug 6, 2019
0d49c45
New crate `machine`
dvdplm Aug 6, 2019
0465e6b
Use new machine and client-traits crates in ethcore
dvdplm Aug 6, 2019
50ca45a
Use new crates machine and client-traits instead of ethcore where app…
dvdplm Aug 6, 2019
29d4095
Fix tests
dvdplm Aug 6, 2019
cd6e0e2
Don't re-export so many types from ethcore::client
dvdplm Aug 6, 2019
2477cbd
Fixing more fallout from removing re-export
dvdplm Aug 6, 2019
51ba2f4
Merge branch 'master' into dp/chore/move-machine-to-own-crate
dvdplm Aug 6, 2019
c84a01f
fix test
dvdplm Aug 7, 2019
f2497f4
More fallout from not re-exporting types
dvdplm Aug 7, 2019
1e43534
Add some docs
dvdplm Aug 7, 2019
6d83cf2
cleanup
dvdplm Aug 7, 2019
e04d188
import the macro edition style
dvdplm Aug 7, 2019
b6e91de
Merge branch 'master' into dp/chore/move-machine-to-own-crate
dvdplm Aug 7, 2019
bac7268
Tweak docs
dvdplm Aug 7, 2019
978eb88
Add missing import
dvdplm Aug 7, 2019
d6273a7
Merge branch 'master' into dp/chore/move-machine-to-own-crate
dvdplm Aug 8, 2019
18d6a94
remove unused ethabi_derive imports
dvdplm Aug 8, 2019
d5700d9
Use latest ethabi-contract
dvdplm Aug 8, 2019
83bb140
Move many traits from ethcore/client/traits to client-traits crate
dvdplm Aug 9, 2019
d96fff3
Move snapshot related traits to the engine crate (eew)
dvdplm Aug 9, 2019
33aa152
Move a few snapshot related types to common_types
dvdplm Aug 9, 2019
9b70856
fix warning
dvdplm Aug 9, 2019
f76e5ed
Gradually introduce new engine crate: snapshot
dvdplm Aug 9, 2019
5b3a8ca
ethcore typechecks with new engine crate
dvdplm Aug 9, 2019
cecd69c
Sort out types outside ethcore
dvdplm Aug 10, 2019
c5ab534
Add an EpochVerifier to ethash and use that in Engine.epoch_verifier()
dvdplm Aug 10, 2019
45c0497
Document pub members
dvdplm Aug 10, 2019
b11a21f
Sort out tests
dvdplm Aug 10, 2019
af485cc
Add test-helpers feature and move EngineSigner impl to the right place
dvdplm Aug 10, 2019
f617bcb
Sort out tests
dvdplm Aug 10, 2019
64b5c60
Sort out tests and refactor verification types
dvdplm Aug 10, 2019
b1b6b46
Fix missing traits
dvdplm Aug 10, 2019
881b71f
More missing traits
dvdplm Aug 10, 2019
ddca9ee
Fix tests and cleanup
dvdplm Aug 10, 2019
d7d3f4b
cleanup
dvdplm Aug 10, 2019
b2f8be6
Put back needed logger import
dvdplm Aug 10, 2019
8ab2a02
Don't rexport common_types from ethcore/src/client
dvdplm Aug 10, 2019
4aef5f2
Remove files no longer used
dvdplm Aug 10, 2019
951f63e
Get rid of itertools
dvdplm Aug 10, 2019
1c42cc1
Move a few more traits from ethcore to client-traits: BlockChainReset…
dvdplm Aug 10, 2019
07b1c2d
Move ProvingBlockChainClient to client-traits
dvdplm Aug 10, 2019
7e5e4bc
Don't re-export ForkChoice and Transition from ethcore
dvdplm Aug 10, 2019
b244bfb
Address grumbles: sort imports, remove commented out code
dvdplm Aug 13, 2019
37be7b2
Merge branch 'master' into dp/chore/extract-engine-trait
dvdplm Aug 13, 2019
88cfa7f
Fix merge resolution error
dvdplm Aug 13, 2019
f4c9b9c
Extract the Clique engine to own crate
dvdplm Aug 13, 2019
5e307ab
Extract NullEngine and the block_reward module from ethcore
dvdplm Aug 13, 2019
db12d1b
Extract InstantSeal engine to own crate
dvdplm Aug 13, 2019
e9e9d62
Extract remaining engines
dvdplm Aug 14, 2019
0f5e970
Extract executive_state to own crate so it can be used by engine crates
dvdplm Aug 14, 2019
e7ba4a5
Remove snapshot stuff from the engine crate
dvdplm Aug 14, 2019
c9dca59
Put snapshot traits back in ethcore
dvdplm Aug 14, 2019
6e3b365
cleanup
dvdplm Aug 14, 2019
c92751a
Remove stuff from ethcore
dvdplm Aug 14, 2019
61b0dd6
Don't use itertools
dvdplm Aug 14, 2019
c79b7e2
itertools in aura is legit-ish
dvdplm Aug 15, 2019
42e1d57
Merge branch 'master' into dp/chore/extract-clique
dvdplm Aug 15, 2019
663f13e
More post-merge fixes
dvdplm Aug 15, 2019
0bd9176
Re-export less types in client
dvdplm Aug 16, 2019
0bd3713
cleanup
dvdplm Aug 16, 2019
fbe0365
Update ethcore/block-reward/Cargo.toml
dvdplm Aug 21, 2019
fdd35c7
Update ethcore/engines/basic-authority/Cargo.toml
dvdplm Aug 21, 2019
0be9f98
Update ethcore/engines/ethash/Cargo.toml
dvdplm Aug 21, 2019
8fc5929
Update ethcore/engines/clique/src/lib.rs
dvdplm Aug 21, 2019
8077b51
signers is already a ref
dvdplm Aug 21, 2019
7f5c4d3
Add an EngineType enum to tighten up Engine.name()
dvdplm Aug 21, 2019
a22870d
Introduce Snapshotting enum to distinguish the type of snapshots a ch…
dvdplm Aug 21, 2019
791e99a
Rename supports_warp to snapshot_mode
dvdplm Aug 21, 2019
77e76f1
Missing import
dvdplm Aug 21, 2019
ad35cb1
Update ethcore/src/snapshot/consensus/mod.rs
dvdplm Aug 21, 2019
081e40e
Merge branch 'master' into dp/chore/extract-clique
dvdplm Aug 21, 2019
792e84e
Merge branch 'master' into dp/chore/extract-clique
dvdplm Aug 22, 2019
ce31277
remove double-semicolons
dvdplm Aug 22, 2019
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
385 changes: 304 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,4 @@ members = [
"ethcore/wasm/run",
"evmbin",
"parity-clib",
"util/triehash-ethereum",
"util/keccak-hasher",
"util/patricia-trie-ethereum",
"util/fastmap",
"util/time-utils",
]
17 changes: 12 additions & 5 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
account-db = { path = "account-db" }
account-state = { path = "account-state" }
authority-round = { path = "./engines/authority-round" }
ansi_term = "0.11"
basic-authority = { path = "./engines/basic-authority" }
blooms-db = { path = "../util/blooms-db", optional = true }
client-traits = { path = "./client-traits" }
clique = { path = "./engines/clique" }
common-types = { path = "types" }
crossbeam-utils = "0.6"
engine = { path = "./engine" }
Expand All @@ -20,6 +23,7 @@ ethabi = "8.0"
ethabi-contract = "8.0"
ethabi-derive = "8.0"
ethash = { path = "../ethash" }
ethash-engine = { path = "./engines/ethash" }
ethcore-blockchain = { path = "./blockchain" }
ethcore-bloom-journal = { path = "../util/bloom" }
ethcore-builtin = { path = "./builtin" }
Expand All @@ -32,23 +36,25 @@ ethereum-types = "0.6.0"
ethjson = { path = "../json" }
ethkey = { path = "../accounts/ethkey" }
evm = { path = "evm" }
executive-state = { path = "executive-state" }
futures = "0.1"
hash-db = "0.15.0"
parity-util-mem = "0.2.0"
instant-seal = { path = "./engines/instant-seal" }
itertools = "0.5"
journaldb = { path = "../util/journaldb" }
keccak-hash = "0.2.0"
keccak-hasher = { path = "../util/keccak-hasher" }
kvdb = "0.1"
kvdb-memorydb = "0.1"
kvdb-rocksdb = { version = "0.1.3", optional = true }
lazy_static = "1.2.0"
lazy_static = "1.3.0"
len-caching-lock = { path = "../util/len-caching-lock" }
log = "0.4"
lru-cache = "0.1"
macros = { path = "../util/macros", optional = true }
machine = { path = "./machine" }
macros = { path = "../util/macros" }
memory-cache = { path = "../util/memory-cache" }
null-engine = { path = "./engines/null-engine" }
num_cpus = "1.2"
parity-bytes = "0.1"
parity-snappy = "0.1"
Expand Down Expand Up @@ -85,14 +91,15 @@ ethcore-accounts = { path = "../accounts" }
fetch = { path = "../util/fetch" }
kvdb-rocksdb = "0.1.3"
machine = { path = "./machine", features = ["test-helpers"] }
macros = { path = "../util/macros" }
parity-runtime = { path = "../util/runtime" }
rlp_compress = { path = "../util/rlp-compress" }
serde_json = "1.0"
tempdir = "0.3"
trie-standardmap = "0.15.0"

[features]
parity = ["work-notify", "price-info", "stratum"]
parity = ["work-notify", "price-info", "stratum", "macros"]
# Large optional features that are enabled by default for Parity,
# but might be omitted for other dependent crates.
work-notify = ["ethcore-miner/work-notify"]
Expand All @@ -119,7 +126,7 @@ ci-skip-tests = []
# Run memory/cpu heavy tests.
test-heavy = []
# Compile test helpers
test-helpers = ["tempdir", "kvdb-rocksdb", "blooms-db"]
test-helpers = ["tempdir", "kvdb-rocksdb", "blooms-db", "macros", "basic-authority/test-helpers"]

[[bench]]
name = "builtin"
Expand Down
21 changes: 21 additions & 0 deletions ethcore/block-reward/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
description = "A crate to interact with the block rewards contract."
name = "block-reward"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0"

[dependencies]
common-types = { path = "../types" }
engine = { path = "../engine" }
ethabi = "8.0.1"
ethabi-derive = "8.0.0"
ethabi-contract = "8.0.1"
ethereum-types = "0.6.0"
keccak-hash = "0.2.0"
machine = { path = "../machine" }
trace = { path = "../trace" }

[dev-dependencies]
ethcore = { path = "..", features = ["test-helpers"] }
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

//! A module with types for declaring block rewards and a client interface for interacting with a
//! Types for declaring block rewards and a client interface for interacting with a
//! block reward contract.

use std::sync::Arc;

use ethabi::FunctionOutputDecoder;
use ethabi_contract::use_contract;
use ethereum_types::{Address, U256};

use std::sync::Arc;
use hash::keccak;
use machine::{Machine, ExecutedBlock};
use trace;
use types::{
use common_types::{
BlockNumber,
errors::{EngineError, EthcoreError as Error},
};
use keccak_hash::keccak;
use machine::{Machine, ExecutedBlock};
use engine::{SystemOrCodeCall, SystemOrCodeCallKind};
use trace;
use trace::{Tracer, ExecutiveTracer, Tracing};

use_contract!(block_reward_contract, "res/contracts/block_reward.json");
use_contract!(block_reward_contract, "res/block_reward.json");

/// The kind of block reward.
/// Depending on the consensus engine the allocated block reward might have
Expand Down Expand Up @@ -161,13 +162,14 @@ pub fn apply_block_rewards(
#[cfg(test)]
mod test {
use std::str::FromStr;
use client::PrepareOpenBlock;
use ethcore::{
client::PrepareOpenBlock,
spec,
test_helpers::generate_dummy_client_with_spec,
};
use ethereum_types::{U256, Address};
use crate::spec;
use test_helpers::generate_dummy_client_with_spec;

use engine::SystemOrCodeCallKind;
use super::{BlockRewardContract, RewardKind};
use crate::{BlockRewardContract, RewardKind};

#[test]
fn block_reward_contract() {
Expand Down
18 changes: 4 additions & 14 deletions ethcore/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use common_types::{
machine::{AuxiliaryData, AuxiliaryRequest},
},
errors::{EthcoreError as Error, EngineError},
snapshot::Snapshotting,
transaction::{self, UnverifiedTransaction},
};
use client_traits::EngineClient;
Expand All @@ -43,10 +44,7 @@ use machine::{
};
use vm::{EnvInfo, Schedule, CallType, ActionValue};

use crate::{
signer::EngineSigner,
snapshot::SnapshotComponents,
};
use crate::signer::EngineSigner;

/// A system-calling closure. Enacts calls on a block's state from the system address.
pub type SystemCall<'a> = dyn FnMut(Address, Vec<u8>) -> Result<Vec<u8>, String> + 'a;
Expand Down Expand Up @@ -306,16 +304,8 @@ pub trait Engine: Sync + Send {
/// Trigger next step of the consensus engine.
fn step(&self) {}

/// Create a factory for building snapshot chunks and restoring from them.
/// Returning `None` indicates that this engine doesn't support snapshot creation.
fn snapshot_components(&self) -> Option<Box<dyn SnapshotComponents>> {
None
}

/// Whether this engine supports warp sync.
fn supports_warp(&self) -> bool {
self.snapshot_components().is_some()
}
/// Snapshot mode for the engine: Unsupported, PoW or PoA
fn snapshot_mode(&self) -> Snapshotting { Snapshotting::Unsupported }

/// Return a new open block header timestamp based on the parent timestamp.
fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64 {
Expand Down
1 change: 0 additions & 1 deletion ethcore/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

mod engine;
pub mod signer;
pub mod snapshot;

pub use crate::engine::{
Engine,
Expand Down
39 changes: 39 additions & 0 deletions ethcore/engines/authority-round/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
description = "Non-instant BFT proof-of-authority blockchain engine"
name = "authority-round"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0"

[dependencies]
block-reward = { path = "../../block-reward" }
client-traits = { path = "../../client-traits" }
common-types = { path = "../../types" }
ethereum-types = "0.6.0"
ethjson = { path = "../../../json" }
ethkey = { path = "../../../accounts/ethkey" }
engine = { path = "../../engine" }
io = { package = "ethcore-io", path = "../../../util/io" }
itertools = "0.5"
keccak-hash = "0.2.0"
lazy_static = "1.3.0"
log = "0.4"
lru-cache = "0.1"
machine = { path = "../../machine" }
macros = { path = "../../../util/macros" }
parking_lot = "0.8"
rand = "0.6"
rlp = "0.4.0"
time-utils = { path = "../../../util/time-utils" }
unexpected = { path = "../../../util/unexpected" }
validator-set = { path = "../validator-set" }

[dev-dependencies]
accounts = { package = "ethcore-accounts", path = "../../../accounts" }
engine = { path = "../../engine", features = ["test-helpers"] }
env_logger = "0.6.2"
ethcore = { path = "../..", features = ["test-helpers"] }
state-db = { path = "../../state-db" }
validator-set = { path = "../validator-set", features = ["test-helpers"] }
serde_json = "1"
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
use std::collections::{VecDeque};
use std::collections::hash_map::{HashMap, Entry};

use common_types::BlockNumber;
use ethereum_types::{H256, Address};
use types::BlockNumber;

use engines::validator_set::SimpleList;
use log::{trace, warn};
use validator_set::SimpleList;

/// Error indicating unknown validator.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -179,8 +179,8 @@ impl RollingFinality {

#[cfg(test)]
mod tests {
use common_types::BlockNumber;
use ethereum_types::{H256, Address};
use types::BlockNumber;
use super::RollingFinality;

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,25 @@ use std::sync::{Weak, Arc};
use std::time::{UNIX_EPOCH, Duration};

use client_traits::EngineClient;
use engine::{Engine,ConstructedVerifier};
use engines::block_reward;
use engines::block_reward::{BlockRewardContract, RewardKind};
use engine::snapshot::SnapshotComponents;
use engine::{Engine, ConstructedVerifier};
use block_reward::{self, BlockRewardContract, RewardKind};
use ethjson;
use machine::{
ExecutedBlock,
Machine,
};
use hash::keccak;
use macros::map;
use keccak_hash::keccak;
use log::{info, debug, error, trace, warn};
use engine::signer::EngineSigner;
use super::validator_set::{ValidatorSet, SimpleList, new_validator_set};
use self::finality::RollingFinality;
use ethkey::{self, Signature};
use io::{IoContext, IoHandler, TimerToken, IoService};
use itertools::{self, Itertools};
use rlp::{encode, Decodable, DecoderError, Encodable, RlpStream, Rlp};
use ethereum_types::{H256, H520, Address, U128, U256};
use parking_lot::{Mutex, RwLock};
use time_utils::CheckedSystemTime;
use types::{
use common_types::{
ancestry_action::AncestryAction,
BlockNumber,
header::{Header, ExtendedHeader},
Expand All @@ -62,11 +60,16 @@ use types::{
machine::{Call, AuxiliaryData},
},
errors::{BlockError, EthcoreError as Error, EngineError},
snapshot::Snapshotting,
};
use unexpected::{Mismatch, OutOfBounds};

use validator_set::{ValidatorSet, SimpleList, new_validator_set};

mod finality;

use self::finality::RollingFinality;

/// `AuthorityRound` params.
pub struct AuthorityRoundParams {
/// Time to wait before next block or authority switching,
Expand Down Expand Up @@ -1631,11 +1634,11 @@ impl Engine for AuthorityRound {
)
}

fn snapshot_components(&self) -> Option<Box<dyn (SnapshotComponents)>> {
fn snapshot_mode(&self) -> Snapshotting {
if self.immediate_transitions {
None
Snapshotting::Unsupported
} else {
Some(Box::new(::snapshot::PoaSnapshot))
Snapshotting::PoA
}
}

Expand Down Expand Up @@ -1663,29 +1666,33 @@ mod tests {
use std::str::FromStr;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use hash::keccak;
use keccak_hash::keccak;
use accounts::AccountProvider;
use ethereum_types::{Address, H520, H256, U256};
use ethkey::Signature;
use types::{
use common_types::{
header::Header,
engines::{Seal, params::CommonParams},
errors::{EthcoreError as Error, EngineError},
transaction::{Action, Transaction},
};
use rlp::encode;
use block::*;
use test_helpers::{
generate_dummy_client_with_spec, get_temp_state_db,
TestNotify
use ethcore::{
block::*,
test_helpers::{
generate_dummy_client_with_spec, get_temp_state_db,
TestNotify
},
spec::{self, Spec},
};
use crate::spec::{Spec, self};
use engine::Engine;
use engines::block_reward::BlockRewardContract;
use engines::validator_set::{TestSet, SimpleList};
use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score};
use block_reward::BlockRewardContract;
use validator_set::{TestSet, SimpleList};
use machine::Machine;
use ethjson;
use serde_json;

use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score};

fn build_aura<F>(f: F) -> Arc<AuthorityRound> where
F: FnOnce(&mut AuthorityRoundParams),
Expand Down Expand Up @@ -1719,7 +1726,7 @@ mod tests {
#[test]
fn has_valid_metadata() {
let engine = spec::new_test_round().engine;
assert!(!engine.name().is_empty());
assert_eq!(engine.name(), "AuthorityRound");
}

#[test]
Expand Down
Loading