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

PoA: Wait for transition finality before applying #5774

Merged
merged 35 commits into from
Jun 28, 2017

Conversation

rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Jun 6, 2017

Summary of changes:

  • Engine::on_new_block gets a flag indicating if the block was the first of an epoch. For PoA engines this will lead to the contracts finalizeChange function being called.
  • Epoch changes split into two modes: signals and instant changes. Switching to a new fixed list is an instant change, but switching to a contract requires finality so it just signals a change.
  • Signals lead to instant changes at the block where they are finalized.
  • authority_round::RollingFinality keeps track of the current finality state for Aura engines.
  • Warp snapshots for PoA include a proof of the change and a proof of finality if necessary.
  • EpochVerifier gains a check_finality_proof function which will check a finality proof under the epoch.
  • AuthorityRound configuration gains a immediateTransitions flag to retain the old behavior and disregard

Although the API looks complicated, it's largely just to support light clients easily -- checking on epoch_end_signal requires nothing more than the block and receipts, as generating a proof is done only on full nodes.

is_epoch_end doesn't have access to the state, which enforces that any epoch changes requiring secure access to state are only applied on finality.

Tendermint hasn't been ported yet, but it should be pretty quick

@rphmeier rphmeier added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M4-core ⛓ Core client code / Rust. labels Jun 6, 2017
@rphmeier
Copy link
Contributor Author

rphmeier commented Jun 9, 2017

Core logic is done now, but tests still need patching up. I'll leave a list of things I'd like to have automated tests against before merging:

  • epoch_transition_for on canonical/non-canonical chains
  • test that transition to fixed list is instant
  • test that transition to contract is not instant
  • test that transition within contract is also not instant
  • test snapshot on contract chain.
  • test snapshot on chain that transitions to contract.

Also the snapshot warp target needs to be changed to target the most recent finalized block to prevent an unfinalized pending transitions to be missed when there is a gap.

@rphmeier
Copy link
Contributor Author

rphmeier commented Jun 9, 2017

I'd also really like to have "import tests" run as part of the CI:
basically, we'll have a submodule containing tests. each test will consist of a chain spec and blocks to import and we'll test (using freshly compiled parity) parity import --chain spec_file blocks_file completes without issue. We can do something similar with snapshots.

Some(t) => t,
None => {
// this really should never happen :)
debug!(target: "engine", "No genesis transition found.");
Copy link
Contributor

@NikVolf NikVolf Jun 12, 2017

Choose a reason for hiding this comment

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

why not panic here, if it can never happen

@rphmeier rphmeier added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Jun 16, 2017
@@ -49,6 +49,9 @@ pub struct AuthorityRoundParams {
/// Block from which monotonic steps start.
#[serde(rename="validateStepTransition")]
pub validate_step_transition: Option<Uint>,
/// Whether transitions should be immediate.
#[serde(rename="immediateTransitions")]
pub immediate_transitions: Option<bool>,
Copy link

Choose a reason for hiding this comment

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

Shouldn't that be only relevant to ValidatorSets that do transitions (unlike SimpleList)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Transitions to SimpleList in a Multi set are instant regardless of the setting of this flag. It could be a per-validator-set flag, but it makes more sense to have it global because
a) this flag influences whether finality checking is done, which is at the engine level
b) if any single validator set doesn't finalize transitions as necessary, then warp sync and light sync won't work and it's the same effect as having none of the sets finalize transitions.

let firsts_iter = self.unverified_firsts.iter().map(|&(_, ref hdr)| hdr);
// we store all last verifiers, but not all firsts.
// match each unverified first epoch with a last epoch verifier.
let mut lasts_reversed = self.last_epochs.iter().rev();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this efficient enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a reversed [T] iterator is just pointer-bumping, same as an in-order iterator. The loop itself just walks two vectors in reverse, which should be pretty fast.

let mut lasts_reversed = self.last_epochs.iter().rev();
for &(ref header, ref finality_proof, hash) in self.unverified_firsts.iter().rev() {
let mut found = false;
while let Some(last) = lasts_reversed.next() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

More idiomatic version: while let Some((header, verifier)) =

@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jun 27, 2017
@arkpar
Copy link
Collaborator

arkpar commented Jun 27, 2017

LGTM, I've looked into changes outside of authority_round mostly.

@arkpar
Copy link
Collaborator

arkpar commented Jun 28, 2017

needs merging

@arkpar arkpar merged commit d069b98 into master Jun 28, 2017
@arkpar arkpar deleted the wait-for-transition-finality branch June 28, 2017 11:17
@@ -39,11 +43,11 @@
"0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
"0000000000000000000000000000000000000005": {
"balance": "1",
"constructor": "6060604052604060405190810160405280737d577a597b2742b498cb5cf0c26cdcd726d39e6e73ffffffffffffffffffffffffffffffffffffffff1681526020017382a978b3f5962a5b0957d9ee9eef472ee55b42f173ffffffffffffffffffffffffffffffffffffffff16815250600290600261007e929190610096565b50341561008757fe5b5b60006001819055505b610163565b82805482825590600052602060002090810192821561010f579160200282015b8281111561010e5782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550916020019190600101906100b6565b5b50905061011c9190610120565b5090565b61016091905b8082111561015c57600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550600101610126565b5090565b90565b61045d806101726000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063303e98e5146100675780639300c9261461008d578063b7ab4db5146100e4578063bfc708a014610159578063fd6e1b501461018f575bfe5b341561006f57fe5b6100776101c5565b6040518082815260200191505060405180910390f35b341561009557fe5b6100e26004808035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919050506101d0565b005b34156100ec57fe5b6100f46102b3565b6040518080602001828103825283818151815260200191508051906020019060200280838360008314610146575b80518252602083111561014657602082019150602081019050602083039250610122565b5050509050019250505060405180910390f35b341561016157fe5b61018d600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610348565b005b341561019757fe5b6101c3600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061034c565b005b600060015490505b90565b600081600290805190602001906101e8929190610350565b50600143034090506000546000191681600019161415156102ae578060008160001916905550600160016000828254019250508190555060015481600019167f47e91f47ccfdcb578564e1af55da55c5e5d33403372fe68e4fed3dfd385764a184604051808060200182810382528381815181526020019150805190602001906020028083836000831461029b575b80518252602083111561029b57602082019150602081019050602083039250610277565b5050509050019250505060405180910390a35b5b5050565b6102bb6103da565b600280548060200260200160405190810160405280929190818152602001828054801561033d57602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190600101908083116102f3575b505050505090505b90565b5b50565b5b50565b8280548282559060005260206000209081019282156103c9579160200282015b828111156103c85782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555091602001919060010190610370565b5b5090506103d691906103ee565b5090565b602060405190810160405280600081525090565b61042e91905b8082111561042a57600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055506001016103f4565b5090565b905600a165627a7a723058205c9ed1e1da2b93682907ac47377a662b21a5f9d89c4b21be40b098bdb00254360029"
"constructor": "6060604052602060405190810160405280737d577a597b2742b498cb5cf0c26cdcd726d39e6e73ffffffffffffffffffffffffffffffffffffffff16815250600090600161004e92919061005c565b50341561005757fe5b610129565b8280548282559060005260206000209081019282156100d5579160200282015b828111156100d45782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055509160200191906001019061007c565b5b5090506100e291906100e6565b5090565b61012691905b8082111561012257600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055506001016100ec565b5090565b90565b61056f806101386000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806375286211146100675780639300c92614610079578063b7ab4db5146100d0578063c476dd4014610145578063d69f13bb146101c7575bfe5b341561006f57fe5b610077610206565b005b341561008157fe5b6100ce600480803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091905050610275565b005b34156100d857fe5b6100e061031f565b6040518080602001828103825283818151815260200191508051906020019060200280838360008314610132575b8051825260208311156101325760208201915060208101905060208303925061010e565b5050509050019250505060405180910390f35b341561014d57fe5b6101c5600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919050506103b4565b005b34156101cf57fe5b610204600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506103ba565b005b73fffffffffffffffffffffffffffffffffffffffe3373ffffffffffffffffffffffffffffffffffffffff1614151561023f5760006000fd5b600060018054905014151561027257600160009080546102609291906103bf565b5060006001816102709190610411565b505b5b565b806001908051906020019061028b92919061043d565b506001430340600019167f55252fa6eee4741b4e24a74a70e9c11fd2c2281df8d6ea13126ff845f7825c89826040518080602001828103825283818151815260200191508051906020019060200280838360008314610309575b805182526020831115610309576020820191506020810190506020830392506102e5565b5050509050019250505060405180910390a25b50565b6103276104c7565b60008054806020026020016040519081016040528092919081815260200182805480156103a957602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001906001019080831161035f575b505050505090505b90565b5b505050565b5b5050565b8280548282559060005260206000209081019282156104005760005260206000209182015b828111156103ff5782548255916001019190600101906103e4565b5b50905061040d91906104db565b5090565b81548183558181151161043857818360005260206000209182019101610437919061051e565b5b505050565b8280548282559060005260206000209081019282156104b6579160200282015b828111156104b55782518260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055509160200191906001019061045d565b5b5090506104c391906104db565b5090565b602060405190810160405280600081525090565b61051b91905b8082111561051757600081816101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055506001016104e1565b5090565b90565b61054091905b8082111561053c576000816000905550600101610524565b5090565b905600a165627a7a7230582041ce7e5c820bc89b1a330a3233c4f3013e77433ecba368fa234adf758d87fe1d0029"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that really the code from https://gist.github.com/anonymous/2a43783647e0f0dfcc359bd6fd81d6d9?
https://ethervm.io/decompile says this code contains a finalizeChange function, but the gist has a finalizeSignal. Also, the signature of reportMalicious seems to be different.

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. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants