Skip to content

Commit a14279e

Browse files
committed
Transaction fee distribution:
Introduced BlockAuthorOption: Engines are now able to specify who is the block author via BlockAuthorOption::EngineBlockAuthor(Address),
1 parent 35c2f5f commit a14279e

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

crates/ethcore/src/engines/hbbft/hbbft_engine.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::{
1111
traits::{EngineClient, ForceUpdateSealing},
1212
},
1313
engines::{
14-
Engine, EngineError, ForkChoice, Seal, SealingState, default_system_or_code_call,
14+
BlockAuthorOption, Engine, EngineError, ForkChoice, Seal, SealingState,
15+
default_system_or_code_call,
1516
hbbft::{
1617
contracts::random_hbbft::set_current_seed_tx_raw, hbbft_message_memorium::BadSealReason,
1718
},
@@ -595,14 +596,9 @@ impl HoneyBadgerBFT {
595596
.write()
596597
.insert(batch.epoch, random_number);
597598

598-
if let Some(mut header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) {
599+
if let Some(header) = client.create_pending_block_at(batch_txns, timestamp, batch.epoch) {
599600
let block_num = header.number();
600601
let hash = header.bare_hash();
601-
if let Some(reward_contract_address) = self.params.block_reward_contract_address {
602-
header.set_author(reward_contract_address);
603-
} else {
604-
warn!("Creating block with no blockRewardContractAddress {}", block_num);
605-
}
606602
// TODO: trace is missleading here: we already got the signature shares, we can already
607603
trace!(target: "consensus", "Sending signature share of {} for block {}", hash, block_num);
608604
let step = match self
@@ -795,7 +791,7 @@ impl HoneyBadgerBFT {
795791
.map(|msg| msg.map(|m| Message::Sealing(block_num, m)));
796792
self.dispatch_messages(&client, messages, network_info);
797793
if let Some(sig) = step.output.into_iter().next() {
798-
trace!(target: "consensus", "Signature for block {} is ready", block_num);
794+
trace!(target: "consensus", "Signature for block {} is ready.", block_num);
799795
let state = Sealing::Complete(sig);
800796
self.sealing.write().insert(block_num, state);
801797

@@ -1473,8 +1469,11 @@ impl Engine<EthereumMachine> for HoneyBadgerBFT {
14731469
false
14741470
}
14751471

1476-
fn use_block_author(&self) -> bool {
1477-
true
1472+
fn use_block_author(&self) -> BlockAuthorOption {
1473+
if let Some(address) = self.params.block_reward_contract_address {
1474+
return BlockAuthorOption::EngineBlockAuthor(address);
1475+
}
1476+
return BlockAuthorOption::ConfiguredBlockAuthor;
14781477
}
14791478

14801479
fn on_before_transactions(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
@@ -1542,7 +1541,7 @@ impl Engine<EthereumMachine> for HoneyBadgerBFT {
15421541

15431542
/// Allow mutating the header during seal generation.
15441543
fn on_seal_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
1545-
let random_numbers = self.random_numbers.read();
1544+
let random_numbers = self.random_numbers.read();
15461545
match random_numbers.get(&block.header.number()) {
15471546
None => {
15481547
warn!("No rng value available for header.");
@@ -1563,7 +1562,6 @@ impl Engine<EthereumMachine> for HoneyBadgerBFT {
15631562
if let Some(address) = self.params.block_reward_contract_address {
15641563
// only if no block reward skips are defined for this block.
15651564
let header_number = block.header.number();
1566-
block.header.set_author(address);
15671565

15681566
if self
15691567
.params

crates/ethcore/src/engines/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ pub enum EpochChange<M: Machine> {
305305
Yes(Proof<M>),
306306
}
307307

308+
/// who shall author a new Block ?
309+
pub enum BlockAuthorOption {
310+
/// use the Zero address as block author.
311+
ZeroBlockAuthor,
312+
313+
/// use the block author from the config.
314+
ConfiguredBlockAuthor,
315+
316+
/// use the block author provivided by the EngineClient.
317+
EngineBlockAuthor(Address),
318+
}
319+
308320
/// A consensus mechanism for the chain. Generally either proof-of-work or proof-of-stake-based.
309321
/// Provides hooks into each of the major parts of block import.
310322
pub trait Engine<M: Machine>: Sync + Send {
@@ -581,8 +593,8 @@ pub trait Engine<M: Machine>: Sync + Send {
581593
}
582594

583595
/// Use the author as signer as well as block author.
584-
fn use_block_author(&self) -> bool {
585-
true
596+
fn use_block_author(&self) -> BlockAuthorOption {
597+
BlockAuthorOption::ConfiguredBlockAuthor
586598
}
587599

588600
/// allows engines to define a block that should not get pruned in the DB.

crates/ethcore/src/miner/miner.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,10 @@ impl Miner {
463463
let params = self.params.read().clone();
464464

465465
let block = match chain.prepare_open_block(
466-
if self.engine.use_block_author() {
467-
params.author
468-
} else {
469-
Address::zero()
466+
match self.engine.use_block_author() {
467+
crate::engines::BlockAuthorOption::ZeroBlockAuthor => Address::zero(),
468+
crate::engines::BlockAuthorOption::ConfiguredBlockAuthor => params.author,
469+
crate::engines::BlockAuthorOption::EngineBlockAuthor(address) => address,
470470
},
471471
params.gas_range_target,
472472
params.extra_data,

0 commit comments

Comments
 (0)