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

Commit

Permalink
Add randomness contract support to Authority Round.
Browse files Browse the repository at this point in the history
Changes have been cherry-picked from poanetwork's aura-pos branch.
Most of the work has been done by @mbr.
  • Loading branch information
afck committed Aug 29, 2019
1 parent 3420c2b commit 0218adc
Show file tree
Hide file tree
Showing 27 changed files with 1,246 additions and 55 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ ethcore-builtin = { path = "./builtin" }
criterion = "0.2"
engine = { path = "./engine", features = ["test-helpers"] }
env_logger = "0.5"
ethash = { path = "../ethash" }
ethcore-accounts = { path = "../accounts" }
ethjson = { path = "../json" }
ethkey = { path = "../accounts/ethkey" }
Expand All @@ -106,7 +105,7 @@ parity = ["work-notify", "price-info", "stratum", "macros"]
# but might be omitted for other dependent crates.
work-notify = ["ethcore-miner/work-notify"]
price-info = ["ethcore-miner/price-info"]
stratum = ["ethcore-stratum"]
stratum = ["ethash", "ethcore-stratum"]

# Disables seal verification for mined blocks.
# This allows you to submit any seal via RPC to test and benchmark
Expand Down
24 changes: 22 additions & 2 deletions ethcore/client-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use common_types::{
pruning_info::PruningInfo,
receipt::LocalizedReceipt,
trace_filter::Filter as TraceFilter,
transaction::{self, LocalizedTransaction, CallError, SignedTransaction},
transaction::{self, Action, LocalizedTransaction, CallError, SignedTransaction},
tree_route::TreeRoute,
verification::{VerificationQueueInfo, Unverified},
};
Expand Down Expand Up @@ -380,7 +380,27 @@ pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContra
fn pruning_info(&self) -> PruningInfo;

/// Schedule state-altering transaction to be executed on the next pending block.
fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error>;
fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error> {
self.transact(Action::Call(address), data, None, None, None)
}

/// Returns a signed transaction. If gas limit, gas price, or nonce are not
/// specified, the defaults are used.
fn create_transaction(
&self,
action: Action,
data: Bytes,
gas: Option<U256>,
gas_price: Option<U256>,
nonce: Option<U256>
) -> Result<SignedTransaction, transaction::Error>;

/// Schedule state-altering transaction to be executed on the next pending
/// block with the given gas and nonce parameters.
///
/// If they are `None`, sensible values are selected automatically.
fn transact(&self, action: Action, data: Bytes, gas: Option<U256>, gas_price: Option<U256>, nonce: Option<U256>)
-> Result<(), transaction::Error>;

/// Get the address of the registry itself.
fn registrar_address(&self) -> Option<Address>;
Expand Down
8 changes: 7 additions & 1 deletion ethcore/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use common_types::{
},
errors::{EthcoreError as Error, EngineError},
snapshot::Snapshotting,
transaction::{self, UnverifiedTransaction},
transaction::{self, SignedTransaction, UnverifiedTransaction},
};
use client_traits::EngineClient;

Expand Down Expand Up @@ -185,6 +185,12 @@ pub trait Engine: Sync + Send {
/// Allow mutating the header during seal generation. Currently only used by Clique.
fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { Ok(()) }

/// Returns a list of transactions for a new block if we are the author.
///
/// This is called when the miner prepares a new block that this node will author and seal. It returns a list of
/// transactions that will be added to the block before any other transactions from the queue.
fn on_prepare_block(&self, _block: &ExecutedBlock) -> Result<Vec<SignedTransaction>, Error> { Ok(Vec::new()) }

/// Returns the engine's current sealing state.
fn sealing_state(&self) -> SealingState { SealingState::External }

Expand Down
15 changes: 15 additions & 0 deletions ethcore/engine/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use ethereum_types::{H256, Address};
use ethkey::{self, Signature};
use ethkey::crypto::ecies;

/// Everything that an Engine needs to sign messages.
pub trait EngineSigner: Send + Sync {
Expand All @@ -26,6 +27,12 @@ pub trait EngineSigner: Send + Sync {

/// Signing address
fn address(&self) -> Address;

/// Decrypt a message that was encrypted to this signer's key.
fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, ethkey::crypto::Error>;

/// The signer's public key, if available.
fn public(&self) -> Option<ethkey::Public>;
}

/// Creates a new `EngineSigner` from given key pair.
Expand All @@ -40,7 +47,15 @@ impl EngineSigner for Signer {
ethkey::sign(self.0.secret(), &hash)
}

fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, ethkey::crypto::Error> {
ecies::decrypt(self.0.secret(), auth_data, cipher)
}

fn address(&self) -> Address {
self.0.address()
}

fn public(&self) -> Option<ethkey::Public> {
Some(*self.0.public())
}
}
11 changes: 11 additions & 0 deletions ethcore/engine/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ impl EngineSigner for (Arc<AccountProvider>, Address, Password) {
}
}

fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, ethkey::crypto::Error> {
self.0.decrypt(self.1, None, auth_data, cipher).map_err(|e| {
warn!("Unable to decrypt message: {:?}", e);
ethkey::crypto::Error::InvalidMessage
})
}

fn address(&self) -> Address {
self.1
}

fn public(&self) -> Option<ethkey::Public> {
self.0.account_public(self.1, &self.2).ok()
}
}
5 changes: 5 additions & 0 deletions ethcore/engines/authority-round/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ license = "GPL-3.0"
block-reward = { path = "../../block-reward" }
client-traits = { path = "../../client-traits" }
common-types = { path = "../../types" }
derive_more = "0.15.0"
ethabi = "8.0"
ethabi-contract = "8.0"
ethabi-derive = "8.0"
ethereum-types = "0.6.0"
ethjson = { path = "../../../json" }
ethkey = { path = "../../../accounts/ethkey" }
Expand All @@ -22,6 +26,7 @@ log = "0.4"
lru-cache = "0.1"
machine = { path = "../../machine" }
macros = { path = "../../../util/macros" }
parity-bytes = "0.1"
parking_lot = "0.8"
rand = "0.6"
rlp = "0.4.0"
Expand Down
Loading

0 comments on commit 0218adc

Please sign in to comment.