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

Authority round consensus engine #3426

Merged
merged 96 commits into from Nov 16, 2016
Merged

Authority round consensus engine #3426

merged 96 commits into from Nov 16, 2016

Conversation

keorn
Copy link

@keorn keorn commented Nov 14, 2016

Authorities release blocks in a round based on unix epoch time. It remains lively under benign faults.
When ran with --force-sealing it will release blocks even when no transactions are present making it BFT up to 50% with finality of authority_count * block_time.

Initial docs

keorn added 30 commits September 8, 2016 10:36
@keorn keorn added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 14, 2016
if let Some(engine) = self.engine.upgrade() {
engine.step.fetch_add(1, AtomicOrdering::SeqCst);
engine.proposed.store(false, AtomicOrdering::SeqCst);
if let Some(ref channel) = *engine.message_channel.try_lock().expect("Could not acquire message channel work.") {
Copy link
Contributor

Choose a reason for hiding this comment

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

what are the possible scenarios where this could occur? what would happen if you used a blocking lock call?

@@ -167,6 +167,8 @@ pub enum BlockError {
UnknownParent(H256),
/// Uncle parent given is unknown.
UnknownUncleParent(H256),
/// The same author issued different votes at the same step.
DoubleVote(H160)
Copy link
Contributor

Choose a reason for hiding this comment

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

trailing comma missing.

one nice thing in a future redesign of the engine trait might involve an associated Error type to convey potential consensus errors (which are unique to each engine) as opposed to bundling all possible consensus errors in with block errors.

@gavofyork this is one of the use-cases of the diverging ! being promoted to a full type -- you might have something like an InstantSeal engine where consensus errors are not possible, and this makes it possible to specify it in the type-system.

@@ -200,6 +202,7 @@ impl fmt::Display for BlockError {
RidiculousNumber(ref oob) => format!("Implausible block number. {}", oob),
UnknownParent(ref hash) => format!("Unknown parent: {}", hash),
UnknownUncleParent(ref hash) => format!("Unknown uncle parent: {}", hash),
DoubleVote(ref address) => format!("Author {} issued to many blocks.", address),
Copy link
Contributor

Choose a reason for hiding this comment

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

to -> too

@keorn keorn added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Nov 14, 2016
proposed: AtomicBool::new(false)
});
let handler = TransitionHandler { engine: Arc::downgrade(&engine) };
engine.transistion_service.register_handler(Arc::new(handler))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

spoke to @arkpar about this and we decided to hold off until the next release to start using ? to maintain a bit of backwards compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should just port everything over at once using untry.

Copy link
Author

Choose a reason for hiding this comment

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

cool, will change back

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 9d46401 on auth-round into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 9d46401 on auth-round into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 071e66c on auth-round into * on master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fde6ff2 on auth-round into * on master*.

proposed: AtomicBool::new(false)
});
let handler = TransitionHandler { engine: Arc::downgrade(&engine) };
try!(engine.transistion_service.register_handler(Arc::new(handler)));
Copy link
Contributor

Choose a reason for hiding this comment

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

typo with this field name: transistion

}

fn header_signature(header: &Header) -> Result<Signature, ::rlp::DecoderError> {
UntrustedRlp::new(&header.seal()[1]).as_val::<H520>().map(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.

indentation

impl AuthorityRound {
/// Create a new instance of AuthorityRound engine.
pub fn new(params: CommonParams, our_params: AuthorityRoundParams, builtins: BTreeMap<Address, Builtin>) -> Result<Arc<Self>, Error> {
let initial_step = (unix_now().as_secs() / our_params.step_duration.as_secs()) as usize;
Copy link
Contributor

Choose a reason for hiding this comment

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

won't this be different every time you instantiate the engine? what would happen if a few rounds are gone through and the one authority has to restart?

Copy link
Author

@keorn keorn Nov 15, 2016

Choose a reason for hiding this comment

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

Yes, it will be different, all nodes rely on absolute unix time (transition according to it). This means they will always have the same step.

self.proposed.store(true, AtomicOrdering::SeqCst);
return Some(vec![encode(&step).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
} else {
trace!(target: "poa", "generate_seal: FAIL: Accounts secret key unavailable.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and below: If this is a misconfiguration error that user can make, it should be visible with a warn level

/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
fn on_close_block(&self, _block: &mut ExecutedBlock) {}

fn is_sealer(&self, author: &Address) -> Option<bool> {
Copy link
Contributor

Choose a reason for hiding this comment

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

why have this return Option if it's unconditionally Some?

Copy link
Author

Choose a reason for hiding this comment

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

Its part of the trait. This engine always has an answer if the address is a sealer, Ethash never has an answer.

Copy link
Contributor

Choose a reason for hiding this comment

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

couldn't you express it as Ethash always returning true, in that any address may seal a block for the purposes of consensus?

Copy link
Author

Choose a reason for hiding this comment

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

but with Ethash the generate_seal is called when external work is submitted. is_sealer really asks "I have a block here authored by this address, should I expect the Engine to be able to seal it for me now?", maybe should be is_sealer_now.
Ethash should return always false if there is no Option, but what it really should say is "idk", which I think is represented by None.

Copy link
Contributor

@rphmeier rphmeier Nov 15, 2016

Choose a reason for hiding this comment

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

ok, so this is only really valid for engines where seals_internally is true?

just curious :) I think this falls beyond the scope of this PR

Copy link
Author

Choose a reason for hiding this comment

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

yep, It is actually used to determine if miner seals_internally.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8efaf08 on auth-round into * on master*.

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 15, 2016
@gavofyork gavofyork merged commit 1daba38 into master Nov 16, 2016
@gavofyork gavofyork deleted the auth-round branch November 16, 2016 03:18
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.

None yet

5 participants