Add randomness contract support to AuthorityRound. (#10946)

* Add randomness contract support to Authority Round.

Changes have been cherry-picked from poanetwork's aura-pos branch.
Most of the work has been done by @mbr.

* Address review comments for randomness contract.

Co-Authored-By: David <dvdplm@gmail.com>

* Rename revealSecret to revealNumber

* Update Randomness contract bytecode

* Use H256, rename secret to random number.

* Use get_commit_and_cipher

* Clean up Miner::prepare_block.

* Remove is_reveal_phase call.

* Add more comments, require randomness contract map.

* Simplify run_randomness_phase

* Address review comments.

* Remove Client::transact_contract.
This commit is contained in:
Andreas Fackler
2019-12-17 11:34:14 +01:00
committed by David
parent f6909d8243
commit 2b1d148ceb
26 changed files with 1293 additions and 69 deletions

View File

@@ -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;
@@ -185,6 +185,14 @@ 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 generate_engine_transactions(&self, _block: &ExecutedBlock) -> Result<Vec<SignedTransaction>, Error> {
Ok(Vec::new())
}
/// Returns the engine's current sealing state.
fn sealing_state(&self) -> SealingState { SealingState::External }

View File

@@ -17,7 +17,7 @@
//! A signer used by Engines which need to sign messages.
use ethereum_types::{H256, Address};
use parity_crypto::publickey::{Signature, KeyPair, Error};
use parity_crypto::publickey::{ecies, Public, Signature, KeyPair, Error};
/// Everything that an Engine needs to sign messages.
pub trait EngineSigner: Send + Sync {
@@ -26,6 +26,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>, Error>;
/// The signer's public key, if available.
fn public(&self) -> Option<Public>;
}
/// Creates a new `EngineSigner` from given key pair.
@@ -40,7 +46,15 @@ impl EngineSigner for Signer {
parity_crypto::publickey::sign(self.0.secret(), &hash)
}
fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, Error> {
ecies::decrypt(self.0.secret(), auth_data, cipher)
}
fn address(&self) -> Address {
self.0.address()
}
fn public(&self) -> Option<Public> {
Some(*self.0.public())
}
}

View File

@@ -20,7 +20,7 @@ use std::sync::Arc;
use ethereum_types::{Address, H256};
use ethkey::Password;
use parity_crypto::publickey::{Signature, Error};
use parity_crypto::publickey::{Public, Signature, Error};
use log::warn;
use accounts::{self, AccountProvider, SignError};
@@ -44,7 +44,18 @@ impl EngineSigner for (Arc<AccountProvider>, Address, Password) {
}
}
fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, Error> {
self.0.decrypt(self.1, None, auth_data, cipher).map_err(|e| {
warn!("Unable to decrypt message: {:?}", e);
Error::InvalidMessage
})
}
fn address(&self) -> Address {
self.1
}
fn public(&self) -> Option<Public> {
self.0.account_public(self.1, &self.2).ok()
}
}