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:
@@ -118,31 +118,35 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding amount of blocks
|
||||
pub fn generate_dummy_client(block_number: u32) -> Arc<Client> {
|
||||
generate_dummy_client_with_spec_and_data(spec::new_test, block_number, 0, &[])
|
||||
generate_dummy_client_with_spec_and_data(spec::new_test, block_number, 0, &[], false)
|
||||
}
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding amount of blocks and txs per every block
|
||||
pub fn generate_dummy_client_with_data(block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> {
|
||||
generate_dummy_client_with_spec_and_data(spec::new_null, block_number, txs_per_block, tx_gas_prices)
|
||||
generate_dummy_client_with_spec_and_data(spec::new_null, block_number, txs_per_block, tx_gas_prices, false)
|
||||
}
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding spec and accounts
|
||||
pub fn generate_dummy_client_with_spec<F>(test_spec: F) -> Arc<Client> where F: Fn() -> Spec {
|
||||
generate_dummy_client_with_spec_and_data(test_spec, 0, 0, &[])
|
||||
generate_dummy_client_with_spec_and_data(test_spec, 0, 0, &[], false)
|
||||
}
|
||||
|
||||
/// Generates dummy client (not test client) with corresponding amount of blocks, txs per block and spec
|
||||
pub fn generate_dummy_client_with_spec_and_data<F>(test_spec: F, block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256]) -> Arc<Client> where
|
||||
pub fn generate_dummy_client_with_spec_and_data<F>(
|
||||
test_spec: F, block_number: u32, txs_per_block: usize, tx_gas_prices: &[U256], force_sealing: bool,
|
||||
) -> Arc<Client> where
|
||||
F: Fn() -> Spec
|
||||
{
|
||||
let test_spec = test_spec();
|
||||
let client_db = new_db();
|
||||
|
||||
let miner = Miner::new_for_tests_force_sealing(&test_spec, None, force_sealing);
|
||||
|
||||
let client = Client::new(
|
||||
ClientConfig::default(),
|
||||
&test_spec,
|
||||
client_db,
|
||||
Arc::new(Miner::new_for_tests(&test_spec, None)),
|
||||
Arc::new(miner),
|
||||
IoChannel::disconnected(),
|
||||
).unwrap();
|
||||
let test_engine = &*test_spec.engine;
|
||||
|
||||
@@ -72,7 +72,7 @@ use client::{
|
||||
use client_traits::{
|
||||
BlockInfo, Nonce, Balance, ChainInfo, TransactionInfo, BlockChainClient, ImportBlock,
|
||||
AccountData, BlockChain, IoClient, BadBlocks, ScheduleInfo, StateClient, ProvingBlockChainClient,
|
||||
StateOrBlock, ForceUpdateSealing
|
||||
StateOrBlock, ForceUpdateSealing, TransactionRequest
|
||||
};
|
||||
use engine::Engine;
|
||||
use machine::executed::Executed;
|
||||
@@ -912,18 +912,24 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error> {
|
||||
fn create_transaction(&self, TransactionRequest { action, data, gas, gas_price, nonce }: TransactionRequest)
|
||||
-> Result<SignedTransaction, transaction::Error>
|
||||
{
|
||||
let transaction = Transaction {
|
||||
nonce: self.latest_nonce(&self.miner.authoring_params().author),
|
||||
action: Action::Call(address),
|
||||
gas: self.spec.gas_limit,
|
||||
gas_price: U256::zero(),
|
||||
nonce: nonce.unwrap_or_else(|| self.latest_nonce(&self.miner.authoring_params().author)),
|
||||
action,
|
||||
gas: gas.unwrap_or(self.spec.gas_limit),
|
||||
gas_price: gas_price.unwrap_or_else(U256::zero),
|
||||
value: U256::default(),
|
||||
data: data,
|
||||
};
|
||||
let chain_id = Some(self.spec.chain_id());
|
||||
let sig = self.spec.engine.sign(transaction.hash(chain_id)).unwrap();
|
||||
let signed = SignedTransaction::new(transaction.with_signature(sig, chain_id)).unwrap();
|
||||
Ok(SignedTransaction::new(transaction.with_signature(sig, chain_id)).unwrap())
|
||||
}
|
||||
|
||||
fn transact(&self, tx_request: TransactionRequest) -> Result<(), transaction::Error> {
|
||||
let signed = self.create_transaction(tx_request)?;
|
||||
self.miner.import_own_transaction(self, signed.into())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user