allow compile-time switching between v0.11.3 and v0.12.1
This commit is contained in:
parent
36f15a3688
commit
8f7541959a
|
@ -95,7 +95,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
||||||
+ merkle_minimal OK
|
+ merkle_minimal OK
|
||||||
```
|
```
|
||||||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
## Official - 0.12.1 - constants & config [Preset: mainnet]
|
## Official - constants & config [Preset: mainnet]
|
||||||
```diff
|
```diff
|
||||||
+ BASE_REWARD_FACTOR 64 [Preset: mainnet] OK
|
+ BASE_REWARD_FACTOR 64 [Preset: mainnet] OK
|
||||||
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: mainnet] OK
|
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: mainnet] OK
|
||||||
|
|
|
@ -101,7 +101,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
||||||
+ merkle_minimal OK
|
+ merkle_minimal OK
|
||||||
```
|
```
|
||||||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
## Official - 0.12.1 - constants & config [Preset: minimal]
|
## Official - constants & config [Preset: minimal]
|
||||||
```diff
|
```diff
|
||||||
+ BASE_REWARD_FACTOR 64 [Preset: minimal] OK
|
+ BASE_REWARD_FACTOR 64 [Preset: minimal] OK
|
||||||
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: minimal] OK
|
+ BLS_WITHDRAWAL_PREFIX "0x00" [Preset: minimal] OK
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
FixtureSSZConsensus-mainnet
|
FixtureSSZConsensus-mainnet
|
||||||
===
|
===
|
||||||
## Official - 0.12.1 - SSZ consensus objects [Preset: mainnet]
|
## Official - SSZ consensus objects [Preset: mainnet]
|
||||||
```diff
|
```diff
|
||||||
+ Testing AggregateAndProof OK
|
+ Testing AggregateAndProof OK
|
||||||
+ Testing Attestation OK
|
+ Testing Attestation OK
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
FixtureSSZConsensus-minimal
|
FixtureSSZConsensus-minimal
|
||||||
===
|
===
|
||||||
## Official - 0.12.1 - SSZ consensus objects [Preset: minimal]
|
## Official - SSZ consensus objects [Preset: minimal]
|
||||||
```diff
|
```diff
|
||||||
+ Testing AggregateAndProof OK
|
+ Testing AggregateAndProof OK
|
||||||
+ Testing Attestation OK
|
+ Testing Attestation OK
|
||||||
|
|
|
@ -49,7 +49,7 @@ proc buildBinary(name: string, srcDir = "./", params = "", cmdParams = "", lang
|
||||||
task moduleTests, "Run all module tests":
|
task moduleTests, "Run all module tests":
|
||||||
buildBinary "beacon_node", "beacon_chain/",
|
buildBinary "beacon_node", "beacon_chain/",
|
||||||
"-d:chronicles_log_level=TRACE " &
|
"-d:chronicles_log_level=TRACE " &
|
||||||
"-d:const_preset=minimal -d:BLS_ETH2_SPEC=\"v0.12.x\" " &
|
"-d:const_preset=minimal -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\" " &
|
||||||
"-d:testutils_test_build"
|
"-d:testutils_test_build"
|
||||||
|
|
||||||
### tasks
|
### tasks
|
||||||
|
@ -59,24 +59,34 @@ task test, "Run all tests":
|
||||||
# price we pay for that.
|
# price we pay for that.
|
||||||
|
|
||||||
# Minimal config
|
# Minimal config
|
||||||
buildBinary "proto_array", "beacon_chain/fork_choice/", "-d:const_preset=minimal -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "proto_array", "beacon_chain/fork_choice/", "-d:const_preset=minimal -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
buildBinary "fork_choice", "beacon_chain/fork_choice/", "-d:const_preset=minimal -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "fork_choice", "beacon_chain/fork_choice/", "-d:const_preset=minimal -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
buildBinary "all_tests", "tests/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "all_tests", "tests/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
# Mainnet config
|
# Mainnet config
|
||||||
buildBinary "proto_array", "beacon_chain/fork_choice/", "-d:const_preset=mainnet -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "proto_array", "beacon_chain/fork_choice/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
buildBinary "fork_choice", "beacon_chain/fork_choice/", "-d:const_preset=mainnet -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "fork_choice", "beacon_chain/fork_choice/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
buildBinary "all_tests", "tests/", "-d:const_preset=mainnet -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "all_tests", "tests/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
|
|
||||||
# Generic SSZ test, doesn't use consensus objects minimal/mainnet presets
|
# Generic SSZ test, doesn't use consensus objects minimal/mainnet presets
|
||||||
buildBinary "test_fixture_ssz_generic_types", "tests/official/", "-d:chronicles_log_level=TRACE"
|
buildBinary "test_fixture_ssz_generic_types", "tests/official/", "-d:chronicles_log_level=TRACE"
|
||||||
|
|
||||||
# Consensus object SSZ tests
|
# Consensus object SSZ tests
|
||||||
buildBinary "test_fixture_ssz_consensus_objects", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
# 0.11.3
|
||||||
buildBinary "test_fixture_ssz_consensus_objects", "tests/official/", "-d:const_preset=mainnet -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "test_fixture_ssz_consensus_objects", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:ETH2_SPEC=\"v0.11.3\""
|
||||||
|
buildBinary "test_fixture_ssz_consensus_objects", "tests/official/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.11.3\""
|
||||||
|
|
||||||
buildBinary "all_fixtures_require_ssz", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
# 0.12.1
|
||||||
buildBinary "all_fixtures_require_ssz", "tests/official/", "-d:const_preset=mainnet -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
buildBinary "test_fixture_ssz_consensus_objects", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
|
buildBinary "test_fixture_ssz_consensus_objects", "tests/official/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
|
|
||||||
|
# 0.11.3
|
||||||
|
buildBinary "all_fixtures_require_ssz", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:ETH2_SPEC=\"v0.11.3\""
|
||||||
|
buildBinary "all_fixtures_require_ssz", "tests/official/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.11.3\""
|
||||||
|
|
||||||
|
# 0.12.1
|
||||||
|
buildBinary "all_fixtures_require_ssz", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=minimal -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
|
buildBinary "all_fixtures_require_ssz", "tests/official/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\""
|
||||||
|
|
||||||
# State sim; getting into 4th epoch useful to trigger consensus checks
|
# State sim; getting into 4th epoch useful to trigger consensus checks
|
||||||
buildBinary "state_sim", "research/", "-d:const_preset=minimal -d:BLS_ETH2_SPEC=\"v0.12.x\"", "--validators=2000 --slots=32"
|
buildBinary "state_sim", "research/", "-d:const_preset=minimal -d:ETH2_SPEC=\"v0.11.3\"", "--validators=2000 --slots=32"
|
||||||
buildBinary "state_sim", "research/", "-d:const_preset=mainnet -d:BLS_ETH2_SPEC=\"v0.12.x\"", "--validators=2000 --slots=128"
|
buildBinary "state_sim", "research/", "-d:const_preset=mainnet -d:ETH2_SPEC=\"v0.12.1\" -d:BLS_ETH2_SPEC=\"v0.12.x\"", "--validators=2000 --slots=128"
|
||||||
|
|
|
@ -654,6 +654,20 @@ proc installAttestationHandlers(node: BeaconNode) =
|
||||||
return false
|
return false
|
||||||
node.attestationPool.isValidAttestation(attestation, slot, ci, {})))
|
node.attestationPool.isValidAttestation(attestation, slot, ci, {})))
|
||||||
|
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#interop-3
|
||||||
|
attestationSubscriptions.add(node.network.subscribe(
|
||||||
|
getInteropAttestationTopic(node.forkDigest), attestationHandler,
|
||||||
|
proc(attestation: Attestation): bool =
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#attestation-subnets
|
||||||
|
let (afterGenesis, slot) = node.beaconClock.now().toSlot()
|
||||||
|
if not afterGenesis:
|
||||||
|
return false
|
||||||
|
# isValidAttestation checks attestation.data.index == topicCommitteeIndex
|
||||||
|
# which doesn't make sense here, so rig that check to vacuously pass.
|
||||||
|
node.attestationPool.isValidAttestation(
|
||||||
|
attestation, slot, attestation.data.index, {})))
|
||||||
|
|
||||||
waitFor allFutures(attestationSubscriptions)
|
waitFor allFutures(attestationSubscriptions)
|
||||||
|
|
||||||
proc stop*(node: BeaconNode) =
|
proc stop*(node: BeaconNode) =
|
||||||
|
|
|
@ -52,8 +52,10 @@ type
|
||||||
next_fork_version*: Version
|
next_fork_version*: Version
|
||||||
next_fork_epoch*: Epoch
|
next_fork_epoch*: Epoch
|
||||||
|
|
||||||
|
# TODO remove InteropAttestations when Altona launches
|
||||||
TopicFilter* {.pure.} = enum
|
TopicFilter* {.pure.} = enum
|
||||||
Blocks, Attestations, Exits, ProposerSlashing, AttesterSlashings
|
Blocks, Attestations, Exits, ProposerSlashing, AttesterSlashings,
|
||||||
|
InteropAttestations
|
||||||
|
|
||||||
BootstrapKind* {.pure.} = enum
|
BootstrapKind* {.pure.} = enum
|
||||||
Enr, MultiAddr
|
Enr, MultiAddr
|
||||||
|
@ -204,6 +206,12 @@ func getTopics(forkDigest: ForkDigest,
|
||||||
of TopicFilter.AttesterSlashings:
|
of TopicFilter.AttesterSlashings:
|
||||||
let topic = getAttesterSlashingsTopic(forkDigest)
|
let topic = getAttesterSlashingsTopic(forkDigest)
|
||||||
@[topic, topic & "_snappy"]
|
@[topic, topic & "_snappy"]
|
||||||
|
of TopicFilter.InteropAttestations:
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
let topic = getInteropAttestationTopic(forkDigest)
|
||||||
|
@[topic, topic & "_snappy"]
|
||||||
|
else:
|
||||||
|
@[]
|
||||||
of TopicFilter.Attestations:
|
of TopicFilter.Attestations:
|
||||||
var topics = newSeq[string](ATTESTATION_SUBNET_COUNT * 2)
|
var topics = newSeq[string](ATTESTATION_SUBNET_COUNT * 2)
|
||||||
var offset = 0
|
var offset = 0
|
||||||
|
@ -538,6 +546,10 @@ proc pubsubLogger(conf: InspectorConf, switch: Switch,
|
||||||
elif topic.endsWith(topicAggregateAndProofsSuffix) or
|
elif topic.endsWith(topicAggregateAndProofsSuffix) or
|
||||||
topic.endsWith(topicAggregateAndProofsSuffix & "_snappy"):
|
topic.endsWith(topicAggregateAndProofsSuffix & "_snappy"):
|
||||||
info "AggregateAndProof", msg = SSZ.decode(buffer, AggregateAndProof)
|
info "AggregateAndProof", msg = SSZ.decode(buffer, AggregateAndProof)
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
if topic.endsWith(topicInteropAttestationSuffix) or
|
||||||
|
topic.endsWith(topicInteropAttestationSuffix & "_snappy"):
|
||||||
|
info "Attestation", msg = SSZ.decode(buffer, Attestation)
|
||||||
|
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
info "Unable to decode message", errMsg = exc.msg
|
info "Unable to decode message", errMsg = exc.msg
|
||||||
|
@ -705,6 +717,8 @@ proc run(conf: InspectorConf) {.async.} =
|
||||||
topics.incl({TopicFilter.Blocks, TopicFilter.Attestations,
|
topics.incl({TopicFilter.Blocks, TopicFilter.Attestations,
|
||||||
TopicFilter.Exits, TopicFilter.ProposerSlashing,
|
TopicFilter.Exits, TopicFilter.ProposerSlashing,
|
||||||
TopicFilter.AttesterSlashings})
|
TopicFilter.AttesterSlashings})
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
topics.incl({TopicFilter.AttesterSlashings})
|
||||||
break
|
break
|
||||||
elif lcitem == "a":
|
elif lcitem == "a":
|
||||||
topics.incl(TopicFilter.Attestations)
|
topics.incl(TopicFilter.Attestations)
|
||||||
|
@ -718,10 +732,16 @@ proc run(conf: InspectorConf) {.async.} =
|
||||||
topics.incl(TopicFilter.AttesterSlashings)
|
topics.incl(TopicFilter.AttesterSlashings)
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
if lcitem == "ia":
|
||||||
|
topics.incl(TopicFilter.InteropAttestations)
|
||||||
else:
|
else:
|
||||||
topics.incl({TopicFilter.Blocks, TopicFilter.Attestations,
|
topics.incl({TopicFilter.Blocks, TopicFilter.Attestations,
|
||||||
TopicFilter.Exits, TopicFilter.ProposerSlashing,
|
TopicFilter.Exits, TopicFilter.ProposerSlashing,
|
||||||
TopicFilter.AttesterSlashings})
|
TopicFilter.AttesterSlashings})
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
topics.incl({TopicFilter.AttesterSlashings})
|
||||||
|
|
||||||
proc pubsubTrampoline(topic: string,
|
proc pubsubTrampoline(topic: string,
|
||||||
data: seq[byte]): Future[void] {.gcsafe.} =
|
data: seq[byte]): Future[void] {.gcsafe.} =
|
||||||
|
|
|
@ -50,15 +50,26 @@ export
|
||||||
# internal state that's gone through sanity checks already.
|
# internal state that's gone through sanity checks already.
|
||||||
|
|
||||||
|
|
||||||
|
const ETH2_SPEC* {.strdefine.} = "v0.11.3"
|
||||||
|
static: doAssert: ETH2_SPEC == "v0.11.3" or ETH2_SPEC == "v0.12.1"
|
||||||
|
|
||||||
# Constant presets
|
# Constant presets
|
||||||
const const_preset* {.strdefine.} = "mainnet"
|
const const_preset* {.strdefine.} = "mainnet"
|
||||||
|
|
||||||
when const_preset == "mainnet":
|
when const_preset == "mainnet":
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
import ./presets/mainnet
|
import ./presets/mainnet
|
||||||
export mainnet
|
export mainnet
|
||||||
|
else:
|
||||||
|
import ./presets/mainnet_v0_11_3
|
||||||
|
export mainnet_v0_11_3
|
||||||
elif const_preset == "minimal":
|
elif const_preset == "minimal":
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
import ./presets/minimal
|
import ./presets/minimal
|
||||||
export minimal
|
export minimal
|
||||||
|
else:
|
||||||
|
import ./presets/minimal_v0_11_3
|
||||||
|
export minimal_v0_11_3
|
||||||
else:
|
else:
|
||||||
type
|
type
|
||||||
Slot* = distinct uint64
|
Slot* = distinct uint64
|
||||||
|
@ -68,7 +79,11 @@ else:
|
||||||
loadCustomPreset const_preset
|
loadCustomPreset const_preset
|
||||||
|
|
||||||
const
|
const
|
||||||
SPEC_VERSION* = "0.12.1" ## \
|
SPEC_VERSION* =
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
|
"0.12.1"
|
||||||
|
else:
|
||||||
|
"0.11.3" ## \
|
||||||
## Spec version we're aiming to be compatible with, right now
|
## Spec version we're aiming to be compatible with, right now
|
||||||
|
|
||||||
GENESIS_SLOT* = Slot(0)
|
GENESIS_SLOT* = Slot(0)
|
||||||
|
@ -238,11 +253,6 @@ type
|
||||||
state_root*: Eth2Digest
|
state_root*: Eth2Digest
|
||||||
body_root*: Eth2Digest
|
body_root*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#signingdata
|
|
||||||
SigningData* = object
|
|
||||||
object_root*: Eth2Digest
|
|
||||||
domain*: Domain
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#beaconblockbody
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#beaconblockbody
|
||||||
BeaconBlockBody* = object
|
BeaconBlockBody* = object
|
||||||
randao_reveal*: ValidatorSig
|
randao_reveal*: ValidatorSig
|
||||||
|
@ -392,13 +402,6 @@ type
|
||||||
message*: AggregateAndProof
|
message*: AggregateAndProof
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/validator.md#eth1block
|
|
||||||
Eth1Block* = object
|
|
||||||
timestamp*: uint64
|
|
||||||
deposit_root*: Eth2Digest
|
|
||||||
deposit_count*: uint64
|
|
||||||
# All other eth1 block fields
|
|
||||||
|
|
||||||
# TODO to be replaced with some magic hash caching
|
# TODO to be replaced with some magic hash caching
|
||||||
HashedBeaconState* = object
|
HashedBeaconState* = object
|
||||||
data*: BeaconState
|
data*: BeaconState
|
||||||
|
@ -412,6 +415,29 @@ type
|
||||||
|
|
||||||
JsonError = jsonTypes.JsonError
|
JsonError = jsonTypes.JsonError
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#signingdata
|
||||||
|
# TODO move back into big `type` block
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
|
type SigningData* = object
|
||||||
|
object_root*: Eth2Digest
|
||||||
|
domain*: Domain
|
||||||
|
else:
|
||||||
|
type SigningRoot* = object
|
||||||
|
object_root*: Eth2Digest
|
||||||
|
domain*: Domain
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/validator.md#eth1block
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
|
type Eth1Block* = object
|
||||||
|
timestamp*: uint64
|
||||||
|
deposit_root*: Eth2Digest
|
||||||
|
deposit_count*: uint64
|
||||||
|
# All other eth1 block fields
|
||||||
|
else:
|
||||||
|
type Eth1Block* = object
|
||||||
|
timestamp*: uint64
|
||||||
|
# All other eth1 block fields
|
||||||
|
|
||||||
func shortValidatorKey*(state: BeaconState, validatorIdx: int): string =
|
func shortValidatorKey*(state: BeaconState, validatorIdx: int): string =
|
||||||
($state.validators[validatorIdx].pubkey)[0..7]
|
($state.validators[validatorIdx].pubkey)[0..7]
|
||||||
|
|
||||||
|
|
|
@ -185,10 +185,16 @@ func get_domain*(
|
||||||
func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest =
|
func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest =
|
||||||
# Return the signing root of an object by calculating the root of the
|
# Return the signing root of an object by calculating the root of the
|
||||||
# object-domain tree.
|
# object-domain tree.
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
let domain_wrapped_object = SigningData(
|
let domain_wrapped_object = SigningData(
|
||||||
object_root: hash_tree_root(ssz_object),
|
object_root: hash_tree_root(ssz_object),
|
||||||
domain: domain
|
domain: domain
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
let domain_wrapped_object = SigningRoot(
|
||||||
|
object_root: hash_tree_root(ssz_object),
|
||||||
|
domain: domain
|
||||||
|
)
|
||||||
hash_tree_root(domain_wrapped_object)
|
hash_tree_root(domain_wrapped_object)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#get_seed
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#get_seed
|
||||||
|
|
|
@ -27,6 +27,9 @@ const
|
||||||
# This is not part of the spec yet!
|
# This is not part of the spec yet!
|
||||||
defaultEth2RpcPort* = 9090
|
defaultEth2RpcPort* = 9090
|
||||||
|
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
const topicInteropAttestationSuffix* = "beacon_attestation/ssz"
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#topics-and-messages
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#topics-and-messages
|
||||||
func getBeaconBlocksTopic*(forkDigest: ForkDigest): string =
|
func getBeaconBlocksTopic*(forkDigest: ForkDigest): string =
|
||||||
try:
|
try:
|
||||||
|
@ -62,6 +65,13 @@ func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string =
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raiseAssert e.msg
|
raiseAssert e.msg
|
||||||
|
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
func getInteropAttestationTopic*(forkDigest: ForkDigest): string =
|
||||||
|
try:
|
||||||
|
&"/eth2/{$forkDigest}/{topicInteropAttestationSuffix}"
|
||||||
|
except ValueError as e:
|
||||||
|
raiseAssert e.msg
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#mainnet-3
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#mainnet-3
|
||||||
func getMainnetAttestationTopic*(forkDigest: ForkDigest, committeeIndex: uint64): string =
|
func getMainnetAttestationTopic*(forkDigest: ForkDigest, committeeIndex: uint64): string =
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -73,12 +73,14 @@ type
|
||||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
||||||
MIN_GASPRICE
|
MIN_GASPRICE
|
||||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
|
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
|
||||||
|
MIN_GENESIS_DELAY # TODO BLS_SPEC == "v0.11.3" remove
|
||||||
MIN_GENESIS_TIME
|
MIN_GENESIS_TIME
|
||||||
MIN_PER_EPOCH_CHURN_LIMIT
|
MIN_PER_EPOCH_CHURN_LIMIT
|
||||||
MIN_SEED_LOOKAHEAD
|
MIN_SEED_LOOKAHEAD
|
||||||
MIN_SLASHING_PENALTY_QUOTIENT
|
MIN_SLASHING_PENALTY_QUOTIENT
|
||||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||||
ONLINE_PERIOD
|
ONLINE_PERIOD
|
||||||
|
PERSISTENT_COMMITTEE_PERIOD # TODO BLS_SPEC == "v0.11.3" remove
|
||||||
PHASE_1_FORK_VERSION
|
PHASE_1_FORK_VERSION
|
||||||
PHASE_1_GENESIS_SLOT
|
PHASE_1_GENESIS_SLOT
|
||||||
PROPOSER_REWARD_QUOTIENT
|
PROPOSER_REWARD_QUOTIENT
|
||||||
|
@ -140,6 +142,7 @@ const
|
||||||
MIN_DEPOSIT_AMOUNT: "'u64",
|
MIN_DEPOSIT_AMOUNT: "'u64",
|
||||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY: "'u64",
|
MIN_EPOCHS_TO_INACTIVITY_PENALTY: "'u64",
|
||||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: "'u64",
|
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: "'u64",
|
||||||
|
PERSISTENT_COMMITTEE_PERIOD: "'u64",
|
||||||
PHASE_1_FORK_VERSION: forkVersionConversionFn,
|
PHASE_1_FORK_VERSION: forkVersionConversionFn,
|
||||||
PROPOSER_REWARD_QUOTIENT: "'u64",
|
PROPOSER_REWARD_QUOTIENT: "'u64",
|
||||||
SECONDS_PER_SLOT: "'u64",
|
SECONDS_PER_SLOT: "'u64",
|
||||||
|
|
|
@ -0,0 +1,211 @@
|
||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
||||||
|
# Licensed and distributed under either of
|
||||||
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
# This file contains constants that are part of the spec and thus subject to
|
||||||
|
# serialization and spec updates.
|
||||||
|
|
||||||
|
import
|
||||||
|
math
|
||||||
|
|
||||||
|
type
|
||||||
|
Slot* = distinct uint64
|
||||||
|
Epoch* = distinct uint64
|
||||||
|
|
||||||
|
{.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec
|
||||||
|
|
||||||
|
const
|
||||||
|
# Misc
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L6
|
||||||
|
|
||||||
|
MAX_COMMITTEES_PER_SLOT* {.intdefine.} = 64
|
||||||
|
|
||||||
|
TARGET_COMMITTEE_SIZE* = 2^7 ##\
|
||||||
|
## Number of validators in the committee attesting to one shard
|
||||||
|
## Per spec:
|
||||||
|
## For the safety of crosslinks `TARGET_COMMITTEE_SIZE` exceeds
|
||||||
|
## [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf);
|
||||||
|
## with sufficient active validators (at least
|
||||||
|
## `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures
|
||||||
|
## committee sizes at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness
|
||||||
|
## with a Verifiable Delay Function (VDF) will improve committee robustness
|
||||||
|
## and lower the safe minimum committee size.)
|
||||||
|
|
||||||
|
MAX_VALIDATORS_PER_COMMITTEE* = 2048 ##\
|
||||||
|
## votes
|
||||||
|
|
||||||
|
MIN_PER_EPOCH_CHURN_LIMIT* = 4
|
||||||
|
CHURN_LIMIT_QUOTIENT* = 2^16
|
||||||
|
SHUFFLE_ROUND_COUNT* = 90
|
||||||
|
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 16384
|
||||||
|
MIN_GENESIS_TIME* {.intdefine.} = 1578009600
|
||||||
|
|
||||||
|
HYSTERESIS_QUOTIENT* = 4
|
||||||
|
HYSTERESIS_DOWNWARD_MULTIPLIER* = 1
|
||||||
|
HYSTERESIS_UPWARD_MULTIPLIER* = 5
|
||||||
|
|
||||||
|
# Gwei values
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L58
|
||||||
|
|
||||||
|
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
|
||||||
|
## Minimum amounth of ETH that can be deposited in one call - deposits can
|
||||||
|
## be used either to top up an existing validator or commit to a new one
|
||||||
|
|
||||||
|
MAX_EFFECTIVE_BALANCE* = 2'u64^5 * 10'u64^9 ##\
|
||||||
|
## Maximum amounth of ETH that can be deposited in one call
|
||||||
|
|
||||||
|
EJECTION_BALANCE* = 2'u64^4 * 10'u64^9 ##\
|
||||||
|
## Once the balance of a validator drops below this, it will be ejected from
|
||||||
|
## the validator pool
|
||||||
|
|
||||||
|
EFFECTIVE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
|
||||||
|
|
||||||
|
# Initial values
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L70
|
||||||
|
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
|
||||||
|
BLS_WITHDRAWAL_PREFIX* = 0'u8
|
||||||
|
|
||||||
|
# Time parameters
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L77
|
||||||
|
MIN_GENESIS_DELAY* = 86400 # 86400 seconds (1 day)
|
||||||
|
|
||||||
|
SECONDS_PER_SLOT*{.intdefine.} = 12'u64 # Compile with -d:SECONDS_PER_SLOT=1 for 12x faster slots
|
||||||
|
## TODO consistent time unit across projects, similar to C++ chrono?
|
||||||
|
|
||||||
|
MIN_ATTESTATION_INCLUSION_DELAY* = 1 ##\
|
||||||
|
## (12 seconds)
|
||||||
|
## Number of slots that attestations stay in the attestation
|
||||||
|
## pool before being added to a block.
|
||||||
|
## The attestation delay exists so that there is time for attestations to
|
||||||
|
## propagate before the block is created.
|
||||||
|
## When creating an attestation, the validator will look at the best
|
||||||
|
## information known to at that time, and may not revise it during the same
|
||||||
|
## slot (see `is_double_vote`) - the delay gives the validator a chance to
|
||||||
|
## wait towards the end of the slot and still have time to publish the
|
||||||
|
## attestation.
|
||||||
|
|
||||||
|
SLOTS_PER_EPOCH* {.intdefine.} = 32 ##\
|
||||||
|
## (~6.4 minutes)
|
||||||
|
## slots that make up an epoch, at the end of which more heavy
|
||||||
|
## processing is done
|
||||||
|
## Compile with -d:SLOTS_PER_EPOCH=4 for shorter epochs
|
||||||
|
|
||||||
|
MIN_SEED_LOOKAHEAD* = 1 ##\
|
||||||
|
## epochs (~6.4 minutes)
|
||||||
|
|
||||||
|
MAX_SEED_LOOKAHEAD* = 4 ##\
|
||||||
|
## epochs (~25.6 minutes)
|
||||||
|
|
||||||
|
EPOCHS_PER_ETH1_VOTING_PERIOD* = 32 ##\
|
||||||
|
## epochs (~3.4 hours)
|
||||||
|
|
||||||
|
SLOTS_PER_HISTORICAL_ROOT* = 8192 ##\
|
||||||
|
## slots (13 hours)
|
||||||
|
|
||||||
|
MIN_VALIDATOR_WITHDRAWABILITY_DELAY* = 2'u64^8 ##\
|
||||||
|
## epochs (~27 hours)
|
||||||
|
|
||||||
|
PERSISTENT_COMMITTEE_PERIOD* = 2'u64^11 ##\
|
||||||
|
## epochs (9 days)
|
||||||
|
|
||||||
|
MAX_EPOCHS_PER_CROSSLINK* = 2'u64^6 ##\
|
||||||
|
## epochs (~7 hours)
|
||||||
|
|
||||||
|
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 ##\
|
||||||
|
## epochs (25.6 minutes)
|
||||||
|
|
||||||
|
# State vector lengths
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L105
|
||||||
|
|
||||||
|
EPOCHS_PER_HISTORICAL_VECTOR* = 65536 ##\
|
||||||
|
## epochs (~0.8 years)
|
||||||
|
|
||||||
|
EPOCHS_PER_SLASHINGS_VECTOR* = 8192 ##\
|
||||||
|
## epochs (~36 days)
|
||||||
|
|
||||||
|
HISTORICAL_ROOTS_LIMIT* = 16777216 ##\
|
||||||
|
## epochs (~26,131 years)
|
||||||
|
|
||||||
|
VALIDATOR_REGISTRY_LIMIT* = 1099511627776
|
||||||
|
|
||||||
|
# Reward and penalty quotients
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L117
|
||||||
|
BASE_REWARD_FACTOR* = 2'u64^6
|
||||||
|
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
|
||||||
|
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
||||||
|
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
|
||||||
|
MIN_SLASHING_PENALTY_QUOTIENT* = 32 # 2^5
|
||||||
|
|
||||||
|
# Max operations per block
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L131
|
||||||
|
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||||
|
MAX_ATTESTER_SLASHINGS* = 2^0
|
||||||
|
MAX_ATTESTATIONS* = 2^7
|
||||||
|
MAX_DEPOSITS* = 2^4
|
||||||
|
MAX_VOLUNTARY_EXITS* = 2^4
|
||||||
|
|
||||||
|
# Fork choice
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L32
|
||||||
|
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds
|
||||||
|
|
||||||
|
# Validators
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L38
|
||||||
|
ETH1_FOLLOW_DISTANCE* = 1024 # blocks ~ 4 hours
|
||||||
|
TARGET_AGGREGATORS_PER_COMMITTEE* = 16 # validators
|
||||||
|
RANDOM_SUBNETS_PER_VALIDATOR* = 1 # subnet
|
||||||
|
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION* = 256 # epochs ~ 27 hours
|
||||||
|
SECONDS_PER_ETH1_BLOCK* = 14 # (estimate from Eth1 mainnet)
|
||||||
|
|
||||||
|
# Phase 1: Upgrade from Phase 0
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L161
|
||||||
|
PHASE_1_FORK_VERSION* = 1
|
||||||
|
INITIAL_ACTIVE_SHARDS* = 64
|
||||||
|
|
||||||
|
# Phase 1: General
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L166
|
||||||
|
MAX_SHARDS* = 1024
|
||||||
|
ONLINE_PERIOD* = 8 # epochs (~51 min)
|
||||||
|
LIGHT_CLIENT_COMMITTEE_SIZE* = 128
|
||||||
|
LIGHT_CLIENT_COMMITTEE_PERIOD* = 256 # epochs (~27 hours)
|
||||||
|
SHARD_COMMITTEE_PERIOD* = 256 # epochs (~27 hours)
|
||||||
|
SHARD_BLOCK_CHUNK_SIZE* = 262144
|
||||||
|
MAX_SHARD_BLOCK_CHUNKS* = 4
|
||||||
|
TARGET_SHARD_BLOCK_SIZE* = 196608
|
||||||
|
MAX_SHARD_BLOCKS_PER_ATTESTATION* = 12
|
||||||
|
MAX_GASPRICE* = 16384 # Gwei
|
||||||
|
MIN_GASPRICE* = 8 # Gwei
|
||||||
|
GASPRICE_ADJUSTMENT_COEFFICIENT* = 8
|
||||||
|
|
||||||
|
# Phase 1: Custody game
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# Time parameters
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L199
|
||||||
|
RANDAO_PENALTY_EPOCHS* = 2 # epochs (12.8 minutes)
|
||||||
|
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS* = 16384 # epochs (~73 days)
|
||||||
|
EPOCHS_PER_CUSTODY_PERIOD* = 2048 # epochs (~9 days)
|
||||||
|
CUSTODY_PERIOD_TO_RANDAO_PADDING* = 2048 # epochs (~9 days)
|
||||||
|
MAX_REVEAL_LATENESS_DECREMENT* = 128 # epochs (~14 hours)
|
||||||
|
|
||||||
|
# Max operations
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L211
|
||||||
|
MAX_CUSTODY_KEY_REVEALS* = 256
|
||||||
|
MAX_EARLY_DERIVED_SECRET_REVEALS* = 1
|
||||||
|
MAX_CUSTODY_SLASHINGS* = 1
|
||||||
|
|
||||||
|
# Reward and penalty quotients
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L217
|
||||||
|
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE* = 2
|
||||||
|
MINOR_REWARD_QUOTIENT* = 256
|
|
@ -0,0 +1,190 @@
|
||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
||||||
|
# Licensed and distributed under either of
|
||||||
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
# This file contains constants that are part of the spec and thus subject to
|
||||||
|
# serialization and spec updates.
|
||||||
|
|
||||||
|
import
|
||||||
|
math
|
||||||
|
|
||||||
|
type
|
||||||
|
Slot* = distinct uint64
|
||||||
|
Epoch* = distinct uint64
|
||||||
|
|
||||||
|
{.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec
|
||||||
|
|
||||||
|
const
|
||||||
|
# Misc
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L4
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
MAX_COMMITTEES_PER_SLOT* = 4
|
||||||
|
TARGET_COMMITTEE_SIZE* = 4
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
MAX_VALIDATORS_PER_COMMITTEE* = 2048
|
||||||
|
MIN_PER_EPOCH_CHURN_LIMIT* = 4
|
||||||
|
CHURN_LIMIT_QUOTIENT* = 2^16
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
SHUFFLE_ROUND_COUNT* = 10
|
||||||
|
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 64
|
||||||
|
MIN_GENESIS_TIME* {.intdefine.} = 1578009600 # 3 Jan, 2020
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
HYSTERESIS_QUOTIENT* = 4
|
||||||
|
HYSTERESIS_DOWNWARD_MULTIPLIER* = 1
|
||||||
|
HYSTERESIS_UPWARD_MULTIPLIER* = 5
|
||||||
|
|
||||||
|
# Gwei values
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L58
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9
|
||||||
|
MAX_EFFECTIVE_BALANCE* = 2'u64^5 * 10'u64^9
|
||||||
|
EJECTION_BALANCE* = 2'u64^4 * 10'u64^9
|
||||||
|
EFFECTIVE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
|
||||||
|
|
||||||
|
# Initial values
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L70
|
||||||
|
|
||||||
|
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 1'u8]
|
||||||
|
BLS_WITHDRAWAL_PREFIX* = 0'u8
|
||||||
|
|
||||||
|
# Time parameters
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L77
|
||||||
|
# Changed: Faster to spin up testnets, but does not give validator
|
||||||
|
# reasonable warning time for genesis
|
||||||
|
MIN_GENESIS_DELAY* = 300
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
SECONDS_PER_SLOT*{.intdefine.} = 6'u64
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
MIN_ATTESTATION_INCLUSION_DELAY* = 1
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
SLOTS_PER_EPOCH* {.intdefine.} = 8
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
MIN_SEED_LOOKAHEAD* = 1
|
||||||
|
MAX_SEED_LOOKAHEAD* = 4
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
EPOCHS_PER_ETH1_VOTING_PERIOD* = 2
|
||||||
|
SLOTS_PER_HISTORICAL_ROOT* = 64
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
MIN_VALIDATOR_WITHDRAWABILITY_DELAY* = 2'u64^8
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
PERSISTENT_COMMITTEE_PERIOD* = 128
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
MAX_EPOCHS_PER_CROSSLINK* = 4
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2
|
||||||
|
|
||||||
|
# State vector lengths
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L105
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
EPOCHS_PER_HISTORICAL_VECTOR* = 64
|
||||||
|
EPOCHS_PER_SLASHINGS_VECTOR* = 64
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
HISTORICAL_ROOTS_LIMIT* = 16777216
|
||||||
|
VALIDATOR_REGISTRY_LIMIT* = 1099511627776
|
||||||
|
|
||||||
|
# Reward and penalty quotients
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L117
|
||||||
|
|
||||||
|
BASE_REWARD_FACTOR* = 2'u64^6
|
||||||
|
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
|
||||||
|
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
||||||
|
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
|
||||||
|
MIN_SLASHING_PENALTY_QUOTIENT* = 32 # 2^5
|
||||||
|
|
||||||
|
# Max operations per block
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L131
|
||||||
|
|
||||||
|
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||||
|
MAX_ATTESTER_SLASHINGS* = 2^0
|
||||||
|
MAX_ATTESTATIONS* = 2^7
|
||||||
|
MAX_DEPOSITS* = 2^4
|
||||||
|
MAX_VOLUNTARY_EXITS* = 2^4
|
||||||
|
|
||||||
|
# Fork choice
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L32
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 2
|
||||||
|
|
||||||
|
# Validators
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L38
|
||||||
|
|
||||||
|
# Changed
|
||||||
|
ETH1_FOLLOW_DISTANCE* = 16 # blocks
|
||||||
|
|
||||||
|
# Unchanged
|
||||||
|
TARGET_AGGREGATORS_PER_COMMITTEE* = 16 # validators
|
||||||
|
RANDOM_SUBNETS_PER_VALIDATOR* = 1 # subnet
|
||||||
|
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION* = 256 # epochs ~ 27 hours
|
||||||
|
SECONDS_PER_ETH1_BLOCK* = 14 # estimate from Eth1 mainnet)
|
||||||
|
|
||||||
|
# Phase 1: Upgrade from Phase 0
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L161
|
||||||
|
PHASE_1_FORK_VERSION* = 16777217
|
||||||
|
INITIAL_ACTIVE_SHARDS* = 4
|
||||||
|
|
||||||
|
# Phase 1: General
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L169
|
||||||
|
MAX_SHARDS* = 8
|
||||||
|
ONLINE_PERIOD* = 8 # epochs ~ 51 minutes
|
||||||
|
LIGHT_CLIENT_COMMITTEE_SIZE* = 128
|
||||||
|
LIGHT_CLIENT_COMMITTEE_PERIOD* = 256 # epochs
|
||||||
|
SHARD_COMMITTEE_PERIOD* = 256 # epochs
|
||||||
|
SHARD_BLOCK_CHUNK_SIZE* = 262144
|
||||||
|
MAX_SHARD_BLOCK_CHUNKS* = 4
|
||||||
|
TARGET_SHARD_BLOCK_SIZE* = 196608
|
||||||
|
MAX_SHARD_BLOCKS_PER_ATTESTATION* = 12
|
||||||
|
MAX_GASPRICE* = 16384 # Gwei
|
||||||
|
MIN_GASPRICE* = 8 # Gwei
|
||||||
|
GASPRICE_ADJUSTMENT_COEFFICIENT* = 8
|
||||||
|
|
||||||
|
# Phase 1 - Custody game
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
# Time parameters
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L202
|
||||||
|
RANDAO_PENALTY_EPOCHS* = 2
|
||||||
|
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS* = 4096 # epochs
|
||||||
|
EPOCHS_PER_CUSTODY_PERIOD* = 2048
|
||||||
|
CUSTODY_PERIOD_TO_RANDAO_PADDING* = 2048
|
||||||
|
MAX_REVEAL_LATENESS_DECREMENT* = 128
|
||||||
|
|
||||||
|
# Max operations
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L214
|
||||||
|
MAX_CUSTODY_KEY_REVEALS* = 256
|
||||||
|
MAX_EARLY_DERIVED_SECRET_REVEALS* = 1
|
||||||
|
MAX_CUSTODY_SLASHINGS* = 1
|
||||||
|
|
||||||
|
# Reward and penalty quotients
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L220
|
||||||
|
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE* = 2
|
||||||
|
MINOR_REWARD_QUOTIENT* = 256
|
|
@ -285,10 +285,16 @@ proc process_voluntary_exit*(
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# Verify the validator has been active long enough
|
# Verify the validator has been active long enough
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
if not (get_current_epoch(state) >= validator.activation_epoch +
|
if not (get_current_epoch(state) >= validator.activation_epoch +
|
||||||
SHARD_COMMITTEE_PERIOD):
|
SHARD_COMMITTEE_PERIOD):
|
||||||
notice "Exit: not in validator set long enough"
|
notice "Exit: not in validator set long enough"
|
||||||
return false
|
return false
|
||||||
|
else:
|
||||||
|
if not (get_current_epoch(state) >= validator.activation_epoch +
|
||||||
|
PERSISTENT_COMMITTEE_PERIOD):
|
||||||
|
notice "Exit: not in validator set long enough"
|
||||||
|
return false
|
||||||
|
|
||||||
# Verify signature
|
# Verify signature
|
||||||
if skipBlsValidation notin flags:
|
if skipBlsValidation notin flags:
|
||||||
|
|
|
@ -393,8 +393,9 @@ func get_inactivity_penalty_deltas(state: BeaconState, cache: var StateCache):
|
||||||
# Spec constructs rewards anyway; this doesn't
|
# Spec constructs rewards anyway; this doesn't
|
||||||
penalties
|
penalties
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_attestation_deltas
|
when ETH2_SPEC == "v0.12.1":
|
||||||
func get_attestation_deltas(state: BeaconState, cache: var StateCache): tuple[a: seq[Gwei], b: seq[Gwei]] =
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_attestation_deltas
|
||||||
|
func get_attestation_deltas(state: BeaconState, cache: var StateCache): tuple[a: seq[Gwei], b: seq[Gwei]] =
|
||||||
# Return attestation reward/penalty deltas for each validator.
|
# Return attestation reward/penalty deltas for each validator.
|
||||||
let
|
let
|
||||||
(source_rewards, source_penalties) = get_source_deltas(state, cache)
|
(source_rewards, source_penalties) = get_source_deltas(state, cache)
|
||||||
|
@ -412,6 +413,102 @@ func get_attestation_deltas(state: BeaconState, cache: var StateCache): tuple[a:
|
||||||
inactivity_penalties[it])
|
inactivity_penalties[it])
|
||||||
|
|
||||||
(rewards, penalties)
|
(rewards, penalties)
|
||||||
|
else:
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||||
|
func get_attestation_deltas(state: BeaconState, stateCache: var StateCache):
|
||||||
|
tuple[a: seq[Gwei], b: seq[Gwei]] {.nbench.}=
|
||||||
|
let
|
||||||
|
previous_epoch = get_previous_epoch(state)
|
||||||
|
total_balance = get_total_active_balance(state, stateCache)
|
||||||
|
var
|
||||||
|
rewards = repeat(0'u64, len(state.validators))
|
||||||
|
penalties = repeat(0'u64, len(state.validators))
|
||||||
|
eligible_validator_indices : seq[ValidatorIndex] = @[]
|
||||||
|
|
||||||
|
for index, v in state.validators:
|
||||||
|
if is_active_validator(v, previous_epoch) or
|
||||||
|
(v.slashed and previous_epoch + 1 < v.withdrawable_epoch):
|
||||||
|
eligible_validator_indices.add index.ValidatorIndex
|
||||||
|
|
||||||
|
# Micro-incentives for matching FFG source, FFG target, and head
|
||||||
|
let
|
||||||
|
matching_source_attestations =
|
||||||
|
get_matching_source_attestations(state, previous_epoch)
|
||||||
|
matching_target_attestations =
|
||||||
|
get_matching_target_attestations(state, previous_epoch)
|
||||||
|
matching_head_attestations =
|
||||||
|
get_matching_head_attestations(state, previous_epoch)
|
||||||
|
|
||||||
|
for attestations in
|
||||||
|
[matching_source_attestations, matching_target_attestations,
|
||||||
|
matching_head_attestations]:
|
||||||
|
let
|
||||||
|
unslashed_attesting_indices =
|
||||||
|
get_unslashed_attesting_indices(state, attestations, stateCache)
|
||||||
|
attesting_balance = get_total_balance(state, unslashed_attesting_indices)
|
||||||
|
for index in eligible_validator_indices:
|
||||||
|
if index in unslashed_attesting_indices:
|
||||||
|
# Factored out from balance totals to avoid uint64 overflow
|
||||||
|
const increment = EFFECTIVE_BALANCE_INCREMENT
|
||||||
|
let reward_numerator = get_base_reward(state, index, total_balance) *
|
||||||
|
(attesting_balance div increment)
|
||||||
|
rewards[index] += reward_numerator div (total_balance div increment)
|
||||||
|
else:
|
||||||
|
penalties[index] += get_base_reward(state, index, total_balance)
|
||||||
|
|
||||||
|
# Proposer and inclusion delay micro-rewards
|
||||||
|
## This depends on matching_source_attestations being an indexable seq, not a
|
||||||
|
## set, hash table, etc.
|
||||||
|
let source_attestation_attesting_indices =
|
||||||
|
mapIt(
|
||||||
|
matching_source_attestations,
|
||||||
|
get_attesting_indices(state, it.data, it.aggregation_bits, stateCache))
|
||||||
|
|
||||||
|
for index in get_unslashed_attesting_indices(
|
||||||
|
state, matching_source_attestations, stateCache):
|
||||||
|
# Translation of attestation = min([...])
|
||||||
|
doAssert matching_source_attestations.len > 0
|
||||||
|
|
||||||
|
# Start by filtering the right attestations
|
||||||
|
var filtered_matching_source_attestations: seq[PendingAttestation]
|
||||||
|
|
||||||
|
for source_attestation_index, a in matching_source_attestations:
|
||||||
|
if index notin
|
||||||
|
source_attestation_attesting_indices[source_attestation_index]:
|
||||||
|
continue
|
||||||
|
filtered_matching_source_attestations.add a
|
||||||
|
|
||||||
|
# The first filtered attestation serves as min until we find something
|
||||||
|
# better
|
||||||
|
var attestation = filtered_matching_source_attestations[0]
|
||||||
|
for source_attestation_index, a in filtered_matching_source_attestations:
|
||||||
|
if a.inclusion_delay < attestation.inclusion_delay:
|
||||||
|
attestation = a
|
||||||
|
|
||||||
|
let
|
||||||
|
base_reward = get_base_reward(state, index, total_balance)
|
||||||
|
proposer_reward = (base_reward div PROPOSER_REWARD_QUOTIENT).Gwei
|
||||||
|
|
||||||
|
rewards[attestation.proposer_index.int] += proposer_reward
|
||||||
|
let max_attester_reward = base_reward - proposer_reward
|
||||||
|
|
||||||
|
rewards[index] += max_attester_reward div attestation.inclusion_delay
|
||||||
|
|
||||||
|
# Inactivity penalty
|
||||||
|
let finality_delay = previous_epoch - state.finalized_checkpoint.epoch
|
||||||
|
if finality_delay > MIN_EPOCHS_TO_INACTIVITY_PENALTY:
|
||||||
|
let matching_target_attesting_indices =
|
||||||
|
get_unslashed_attesting_indices(
|
||||||
|
state, matching_target_attestations, stateCache)
|
||||||
|
for index in eligible_validator_indices:
|
||||||
|
penalties[index] +=
|
||||||
|
BASE_REWARDS_PER_EPOCH.uint64 * get_base_reward(state, index, total_balance)
|
||||||
|
if index notin matching_target_attesting_indices:
|
||||||
|
penalties[index] +=
|
||||||
|
state.validators[index].effective_balance *
|
||||||
|
finality_delay div INACTIVITY_PENALTY_QUOTIENT
|
||||||
|
|
||||||
|
(rewards, penalties)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||||
func process_rewards_and_penalties(
|
func process_rewards_and_penalties(
|
||||||
|
|
|
@ -10,6 +10,7 @@ import
|
||||||
os, strutils, typetraits,
|
os, strutils, typetraits,
|
||||||
# Internals
|
# Internals
|
||||||
../../beacon_chain/ssz,
|
../../beacon_chain/ssz,
|
||||||
|
../../beacon_chain/spec/datatypes,
|
||||||
# Status libs
|
# Status libs
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
serialization, json_serialization
|
serialization, json_serialization
|
||||||
|
@ -40,7 +41,11 @@ type
|
||||||
|
|
||||||
const
|
const
|
||||||
FixturesDir* = currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
|
FixturesDir* = currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
|
||||||
SszTestsDir* = FixturesDir/"tests-v0.12.1"
|
SszTestsDir* =
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
|
FixturesDir/"tests-v0.12.1"
|
||||||
|
else:
|
||||||
|
FixturesDir/"tests-v0.11.3"
|
||||||
|
|
||||||
proc parseTest*(path: string, Format: typedesc[Json or SSZ], T: typedesc): T =
|
proc parseTest*(path: string, Format: typedesc[Json or SSZ], T: typedesc): T =
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -125,5 +125,5 @@ proc checkConfig() =
|
||||||
else:
|
else:
|
||||||
check: ConstsToCheck[constant] == value.getBiggestInt().uint64()
|
check: ConstsToCheck[constant] == value.getBiggestInt().uint64()
|
||||||
|
|
||||||
suiteReport "Official - 0.12.1 - constants & config " & preset():
|
suiteReport "Official - constants & config " & preset():
|
||||||
checkConfig()
|
checkConfig()
|
||||||
|
|
|
@ -116,13 +116,18 @@ proc runSSZtests() =
|
||||||
of "SignedBeaconBlockHeader":
|
of "SignedBeaconBlockHeader":
|
||||||
checkSSZ(SignedBeaconBlockHeader, path, hash)
|
checkSSZ(SignedBeaconBlockHeader, path, hash)
|
||||||
of "SignedVoluntaryExit": checkSSZ(SignedVoluntaryExit, path, hash)
|
of "SignedVoluntaryExit": checkSSZ(SignedVoluntaryExit, path, hash)
|
||||||
of "SigningData": checkSSZ(SigningData, path, hash)
|
of "SigningData":
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
|
checkSSZ(SigningData, path, hash)
|
||||||
|
of "SigningRoot":
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
checkSSZ(SigningRoot, path, hash)
|
||||||
of "Validator": checkSSZ(Validator, path, hash)
|
of "Validator": checkSSZ(Validator, path, hash)
|
||||||
of "VoluntaryExit": checkSSZ(VoluntaryExit, path, hash)
|
of "VoluntaryExit": checkSSZ(VoluntaryExit, path, hash)
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError, "Unsupported test: " & sszType)
|
raise newException(ValueError, "Unsupported test: " & sszType)
|
||||||
|
|
||||||
suiteReport "Official - 0.12.1 - SSZ consensus objects " & preset():
|
suiteReport "Official - SSZ consensus objects " & preset():
|
||||||
runSSZtests()
|
runSSZtests()
|
||||||
|
|
||||||
summarizeLongTests("FixtureSSZConsensus")
|
summarizeLongTests("FixtureSSZConsensus")
|
||||||
|
|
|
@ -13,6 +13,10 @@ suiteReport "Honest validator":
|
||||||
getVoluntaryExitsTopic(forkDigest) == "/eth2/00000000/voluntary_exit/ssz"
|
getVoluntaryExitsTopic(forkDigest) == "/eth2/00000000/voluntary_exit/ssz"
|
||||||
getProposerSlashingsTopic(forkDigest) == "/eth2/00000000/proposer_slashing/ssz"
|
getProposerSlashingsTopic(forkDigest) == "/eth2/00000000/proposer_slashing/ssz"
|
||||||
getAttesterSlashingsTopic(forkDigest) == "/eth2/00000000/attester_slashing/ssz"
|
getAttesterSlashingsTopic(forkDigest) == "/eth2/00000000/attester_slashing/ssz"
|
||||||
|
when ETH2_SPEC == "v0.11.3":
|
||||||
|
getInteropAttestationTopic(forkDigest) == "/eth2/00000000/beacon_attestation/ssz"
|
||||||
|
else:
|
||||||
|
true
|
||||||
getAggregateAndProofsTopic(forkDigest) == "/eth2/00000000/beacon_aggregate_and_proof/ssz"
|
getAggregateAndProofsTopic(forkDigest) == "/eth2/00000000/beacon_aggregate_and_proof/ssz"
|
||||||
|
|
||||||
timedTest "Mainnet attestation topics":
|
timedTest "Mainnet attestation topics":
|
||||||
|
|
|
@ -158,6 +158,7 @@ suiteReport "Interop":
|
||||||
# https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state
|
# https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state
|
||||||
initialState.genesis_time = genesis_time
|
initialState.genesis_time = genesis_time
|
||||||
|
|
||||||
|
when ETH2_SPEC == "v0.12.1":
|
||||||
let expected =
|
let expected =
|
||||||
when const_preset == "minimal":
|
when const_preset == "minimal":
|
||||||
"051d1a9c0fb61fce627e3990b930791fd17cb9fa7fb84a9a0051e55bf1759ec8"
|
"051d1a9c0fb61fce627e3990b930791fd17cb9fa7fb84a9a0051e55bf1759ec8"
|
||||||
|
@ -165,5 +166,13 @@ suiteReport "Interop":
|
||||||
"ffe85e9b0e3af1b86a177e5b9dc28d5e1237ff5a046482cb45cbd036e918c676"
|
"ffe85e9b0e3af1b86a177e5b9dc28d5e1237ff5a046482cb45cbd036e918c676"
|
||||||
else:
|
else:
|
||||||
"unimplemented"
|
"unimplemented"
|
||||||
|
else:
|
||||||
|
let expected =
|
||||||
|
when const_preset == "minimal":
|
||||||
|
"410c8758710155b49208d52c9e4bd2f11aa16a7c7521e560a2d05dcd69a023b3"
|
||||||
|
elif const_preset == "mainnet":
|
||||||
|
"95a0b1e7b0b77d0cbe2bcd12c90469e68edb141424b1a6126f1d55498afe3ae6"
|
||||||
|
else:
|
||||||
|
"unimplemented"
|
||||||
check:
|
check:
|
||||||
hash_tree_root(initialState[]).data.toHex() == expected
|
hash_tree_root(initialState[]).data.toHex() == expected
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 149b663a0c268e67c5cfa60c565a0d4991b13eb8
|
Subproject commit 3a8b4dacd08814d0afa6731ea53cc282b78c6854
|
Loading…
Reference in New Issue