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

EIP-1011: Hybrid Casper FFG / Ethash #7162

Closed
5chdn opened this issue Nov 29, 2017 · 17 comments
Closed

EIP-1011: Hybrid Casper FFG / Ethash #7162

5chdn opened this issue Nov 29, 2017 · 17 comments
Assignees
Labels
F8-enhancement 🎊 An additional feature request. M4-core ⛓ Core client code / Rust. P2-asap 🌊 No need to stop dead in your tracks, however issue should be addressed as soon as possible.
Milestone

Comments

@5chdn
Copy link
Contributor

5chdn commented Nov 29, 2017

http://eips.ethereum.org/EIPS/eip-1011

@5chdn 5chdn added F8-enhancement 🎊 An additional feature request. M4-core ⛓ Core client code / Rust. P5-sometimesoon 🌲 Issue is worth doing soon. labels Nov 29, 2017
@5chdn 5chdn added this to the 1.10 milestone Nov 29, 2017
@rphmeier
Copy link
Contributor

rphmeier commented Nov 30, 2017

I can take it (edit: busy with Polkadot stuff; can mentor implementation)

@5chdn
Copy link
Contributor Author

5chdn commented Nov 30, 2017

I'm on it to figure out the specs.

@vbuterin
Copy link

vbuterin commented Dec 1, 2017

Would be happy to provide any assistance or support.

We will try to prioritize improving documentation asap. In the mean time, there's the paper and the python code:

http://github.com/karlfloersch/docker-pyeth-dev
https://github.com/karlfloersch/pyethereum
https://github.com/karlfloersch/pyethereum/tree/develop/ethereum/hybrid_casper
http://github.com/ethereum/casper

I recommend starting with the fork choice rule (priority 1: highest justified epoch #, priority 2: max total diff) and the validator logic.

@5chdn
Copy link
Contributor Author

5chdn commented Dec 1, 2017

cc @pipermerriam

@5chdn
Copy link
Contributor Author

5chdn commented Jan 1, 2018

@5chdn 5chdn added P2-asap 🌊 No need to stop dead in your tracks, however issue should be addressed as soon as possible. and removed P5-sometimesoon 🌲 Issue is worth doing soon. labels Jan 1, 2018
@rphmeier
Copy link
Contributor

rphmeier commented Jan 1, 2018

The paper is pretty good documentation for a start.

Initial engineering concerns:

  • BlockChain currently holds the whole fork-choice decision, based only on total difficulty. Parts of this will need to be deferred to the Engine.
  • Engine needs to get a persistent data store to keep track of any votes targeting non-finalized checkpoints to avoid violating slashing conditions. This brings complication due to snapshot restoration replacing the DB in-place.

@vbuterin
Copy link

vbuterin commented Jan 2, 2018 via email

@rphmeier
Copy link
Contributor

Probably via a special-purpose protocol, like randomly selecting 50
validator indices and verifying that valid votes for enough of those
validators exist.

@vbuterin
This does imply that light clients would require lots of old state to be available. the way we architecture Parity right now, we model dynasty changes as a signal (log event) which is applied automatically upon finality. State proofs of a new validator set are kept in a compressed form by full nodes to ensure general availability. For engines like Aura or Tendermint this is fairly easy because finality is determined outside of the chain's state.

In CasperFFG this will definitely be more difficult and it seems that light clients will have to download lots of state data progressively to follow the fork-choice rule correctly. It would probably be simpler to give light clients a batch of proofs for all finalized dynasty changes (i.e. a warp sync) than to have it try and follow the header chain from genesis.

@rphmeier
Copy link
Contributor

rphmeier commented Jan 18, 2018

As far as implementing the fork-choice rule, I think this will be fairly easy to do (will provide the skeleton for that in an upcoming PR) through the introduction of arbitrary engine metadata being allowed to be stored in the blockchain-db.

trait Metadata {
    // set and get engine-specific metadata
    fn set_key(&mut self, key: &[u8], val: &[u8]);
    fn get(&self, key: &[u8]) -> Option<Vec<u8>>;

    // set a reversion limit: the block indicated by this hash will never be reverted
    fn set_reversion_limit(&mut self, block_hash: H256);

    // epoch transition stuff can be merged into here also.
}

The consensus engine gets two new functions:

  • fn update_metadata(header: &Header, ancestry: &Ancestry, metadata: &mut Metadata)
  • fn fork_choice(prospective: &Header, current_best: &Header, metadata: &Metadata)

The fork_choice function always called after the update_metadata function, and never if the prospective block would reorganize past a set reversion limit.

Here are some example fork choice implementations:

    // Ethash
    fn total_diff_fork_choice(prospective, current_best, metadata_store) -> H256 {
	let new_total_diff = metadata_store.get_total_difficulty(prospective);
	let current_best_diff = metadata_store.get_total_difficulty(current_best);

	if current_best_diff > new_total_diff {
		current_best.hash()
	} else {
		prospective.hash()
	}
    }

    // a casperFFG fork choice
    fn casperFFG_fork_choice(prospective, current_best, metadata_store) -> H256 { 
	let left_justified_height = get_justified_height(prospective);
	let right_justified_height = get_justified_height(current_best);

	// Note that there exists at most one justified checkpoint at a height `n`.
	// the last justified checkpoint must have been cast as such according to the best block
	match left_justified_height.cmp(right_justified_height) {
		Ordering::Equal => total_diff_fork_choice_rule(prospective, current_best, metadata_store)
		Ordering::Less => current_best.hash(),
		Ordering::Greater => prospective.hash(),
	}
    }

The respective update_metadata functions would set the new total difficulty and justified/finalized epochs based on chain or state data.

@5chdn 5chdn modified the milestones: 1.10, 1.11 Jan 23, 2018
@rphmeier
Copy link
Contributor

@vbuterin when you say "highest justified epoch #", should that be the highest witnessed at any contract-state or only at the contract state of either chain head in the fork choice?

@vbuterin
Copy link

vbuterin commented Jan 23, 2018 via email

@5chdn 5chdn modified the milestones: 1.11, 1.12 Mar 1, 2018
@5chdn
Copy link
Contributor Author

5chdn commented Apr 3, 2018

Copy-pasty from Gitter:

Danny Ryan @djrtwo Apr 01 06:14
Hey client implementers. We’re working on some casper contract updates and rebooting the casper testnet soon. We’d like to get more (all) clients involved this time around. We’ve updated the implementation guide and an EIP is coming soon. We are working on porting the validator service to web3.py to be able to plug into different backends, so the client/forkchoice/gas changes are the top priority. DM me and let me know where you’re at in terms of implementation, etc, and I’ll keep you updated in the coming weeks on testnet next steps.

Note: if you have already begun implementation, there have been a couple of tweaks to the gas/vote-transaction rules recently. I can help you identify the changes. Just let me know.

Danny Ryan @djrtwo Apr 02 06:35
Last site got DoS’d because someone posted the link to reddit. Moved it to the casper github repo
https://github.com/ethereum/casper/blob/master/IMPLEMENTATION.md

@5chdn
Copy link
Contributor Author

5chdn commented Apr 9, 2018

@sorpaas
Copy link
Collaborator

sorpaas commented Apr 13, 2018

I would like to help out on this issue.

@sorpaas sorpaas self-assigned this Apr 13, 2018
@rphmeier rphmeier assigned ascjones and andresilva and unassigned sorpaas Apr 13, 2018
@5chdn
Copy link
Contributor Author

5chdn commented Apr 20, 2018

ethereum/EIPs#1011

@5chdn 5chdn changed the title Implement Casper FFG test-network EIP-1011: Hybrid Casper FFG / Ethash Apr 20, 2018
@5chdn 5chdn modified the milestones: 1.12, 1.13 Apr 24, 2018
@sorpaas
Copy link
Collaborator

sorpaas commented May 16, 2018

Discussed with @ascjones. I'll take over the Casper ABI work and try to see whether we can use the fork choice and metadata framework to make an implementation to connect to the Casper testnet.

@djrtwo
Copy link

djrtwo commented May 16, 2018

Just fyi, vyper is soon moving to fixedMxN rather than decimal. Casper contract will move to a subtype of this when vyper releases the update.

Relevant issue here vyperlang/vyper#566

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
F8-enhancement 🎊 An additional feature request. M4-core ⛓ Core client code / Rust. P2-asap 🌊 No need to stop dead in your tracks, however issue should be addressed as soon as possible.
Projects
None yet
Development

No branches or pull requests

7 participants