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

Rewards on closing blocks #6194

Merged
merged 31 commits into from
Aug 30, 2017
Merged

Rewards on closing blocks #6194

merged 31 commits into from
Aug 30, 2017

Conversation

grbIzl
Copy link
Collaborator

@grbIzl grbIzl commented Jul 31, 2017

Added tracing of rewards on closing blocks. The following major changes made:

  • Add new action Reward with reward type (Block or Uncle)
  • Extended engine's API in order to return traces on closing block.
  • New parameter for engine's spec params added (apply_reward). By default it's true
  • New engine spec null_morden_with_reward created (in order to distinguish with default null_morden without reward)
  • Db code of trace filtering was modified in order to reflect, that traces can be block-related not only transaction-related
  • Localisation trace (passed outside by rpc) modified. Transaction id and hash in trace made optional. So it can be null now. This should be expressed in release notes somehow.
  • Integration and unit tests added

The work was done in terms of #4858

@grbIzl grbIzl added the A0-pleasereview 🤓 Pull request needs code review. label Jul 31, 2017
@NikVolf
Copy link
Contributor

NikVolf commented Jul 31, 2017

needs a rebase to master

@NikVolf NikVolf added the M4-core ⛓ Core client code / Rust. label Jul 31, 2017
@@ -166,9 +168,17 @@ impl From<ethjson::spec::Params> for CommonParams {
nonce_cap_increment: p.nonce_cap_increment.map_or(64, Into::into),
remove_dust_contracts: p.remove_dust_contracts.unwrap_or(false),
wasm: p.wasm.unwrap_or(false),
<<<<<<< HEAD
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers

@@ -196,6 +204,9 @@ pub trait IsBlock {

/// Get all uncles in this block.
fn uncles(&self) -> &[Header] { &self.block().uncles }

/// Get tracing enabled flag for this block.
fn tracing_enabled(&self) -> &bool { &self.block().tracing_enabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just return bool, it's actually smaller than the ref type

use engines::Engine;
use block::*;
use util::*;
use engines::{Engine, CloseOutcome};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better not to use glob imports where avoidable

fields.state.add_balance(
u.author(),
&(reward * U256::from(8 + u.number() - current_number) / U256::from(8)),
&(result_uncle_reward),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parentheses no longer necessary

@grbIzl grbIzl added the B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. label Aug 1, 2017
@grbIzl
Copy link
Collaborator Author

grbIzl commented Aug 1, 2017

Add relnotes label in order to reflect, that transaction id and hash for trace can be null after this change

@tomusdrw tomusdrw changed the title Fix 4858 Tracing of rewards on closing blocks Aug 2, 2017
@@ -419,7 +423,7 @@ impl<'x> OpenBlock<'x> {
let mut s = self;

if let Err(e) = s.engine.on_close_block(&mut s.block) {
warn!("Encountered error on closing the block: {}", e);
warn!("Encountered error on closing the block: {}", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dodgy space added (beginning of line)

@@ -429,7 +433,7 @@ impl<'x> OpenBlock<'x> {
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
}
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
if s.block.header.uncles_hash().is_zero() {
if s.block.header.uncles_hash().is_zero() || s.block.header.uncles_hash() == &SHA3_EMPTY_LIST_RLP {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. From my point of view it's a logical flaw. If block is initialized using default construction, uncle_hash won't be zero and won't be set in this method. I assume, that original intent was to set it in this case. You can see the same pattern (checking default values and zero) in this function for other fields. As a result simple integration test with close_and_seal for block failed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that's fair enough.

@@ -229,7 +229,7 @@ pub trait Engine : Sync + Send {

/// Block transformation functions, after the transactions.
fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> {
Ok(())
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dodgy space added

@@ -24,6 +24,7 @@ use block::*;
use builtin::Builtin;
use vm::EnvInfo;
use error::{BlockError, Error, TransactionError};
use trace::{Tracer, ExecutiveTracer,RewardType};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent spaces.

CleanupMode::NoEmpty
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

@@ -170,7 +170,7 @@ impl From<ethjson::spec::Params> for CommonParams {
wasm: p.wasm.unwrap_or(false),
gas_limit_bound_divisor: p.gas_limit_bound_divisor.into(),
block_reward: p.block_reward.map_or_else(U256::zero, Into::into),
registrar: p.registrar.map_or_else(Address::new, Into::into),
registrar: p.registrar.map_or_else(Address::new, Into::into)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't kill the trailing ,


// Add root block first
let mut root_block = OpenBlock::new(
engine,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one indentation needed


// Add parent block
let mut parent_block = OpenBlock::new(
engine,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one indentation needed

(3141562.into(), 31415620.into()),
vec![],
false
).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be one indent fewer


// Test0. Check overall filter
let filter = TraceFilter {
range: (BlockId::Number(1)..BlockId::Number(3)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be one indentation fewer

@@ -128,6 +128,10 @@ impl Filter {
let from_matches = self.from_address.matches(&suicide.address);
let to_matches = self.to_address.matches(&suicide.refund_address);
from_matches && to_matches
},
Action::Reward(ref reward) => {
let to_matches = self.to_address.matches(&reward.author);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of let X = ...; X ? why not just ...?

use evm::CallType;
use trace::RewardType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabs! not spaces.

@gavofyork
Copy link
Contributor

more just did a style review. quite a lot of issues. some were probably just misconfigured editor, others misunderstanding about our house style.

one or two, however, were carelessness, which is a bad omen given this is utterly consensus-critical code that you're hacking on.

the logic here should be positively and deeply reviewed by at least three experienced core devs before merge.

@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Aug 9, 2017
@grbIzl
Copy link
Collaborator Author

grbIzl commented Aug 9, 2017

@gavofyork I provided the reasoning in the question about logic's change. All other style comments will be fixed with the next commit.

@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Aug 28, 2017
@gavofyork gavofyork added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Aug 29, 2017
@debris
Copy link
Collaborator

debris commented Aug 30, 2017

I will fix build failures and merge to master

@grbIzl
Copy link
Collaborator Author

grbIzl commented Aug 30, 2017

Thanks @debris !

@debris
Copy link
Collaborator

debris commented Aug 30, 2017

Done. I'll merge once CI is green 👍

@debris debris merged commit f7e15f2 into master Aug 30, 2017
@debris debris deleted the Fix-4858 branch August 30, 2017 13:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants