Updated the custom preset loader to the latest spec; Working makefile target for connecting to the Schlesi testnet

This commit is contained in:
Zahary Karadjov 2020-04-27 22:03:03 +03:00 committed by zah
parent dcc70c5259
commit 80b538452e
7 changed files with 83 additions and 44 deletions

View File

@ -123,7 +123,10 @@ clean-testnet1:
# - try SCRIPT_PARAMS="--skipGoerliKey"
testnet0 testnet1: | build deps
source scripts/$@.env; \
NIM_PARAMS="$(NIM_PARAMS) -d:const_preset=$$CONST_PRESET" LOG_LEVEL="$(LOG_LEVEL)" $(ENV_SCRIPT) nim $(NIM_PARAMS) scripts/connect_to_testnet.nims $(SCRIPT_PARAMS) $@
NIM_PARAMS="$(NIM_PARAMS)" LOG_LEVEL="$(LOG_LEVEL)" $(ENV_SCRIPT) nim $(NIM_PARAMS) scripts/connect_to_testnet.nims $(SCRIPT_PARAMS) --const-preset=$$CONST_PRESET $@
schlesi: | build deps
LOG_LEVEL="DEBUG" $(ENV_SCRIPT) nim $(NIM_PARAMS) scripts/connect_to_testnet.nims $(SCRIPT_PARAMS) shared/schlesi
clean: | clean-common
rm -rf build/{$(TOOLS_CSV),all_tests,*_node,*ssz*,beacon_node_testnet*,state_sim,transition*}

View File

@ -102,8 +102,8 @@ func voting_period_start_time*(state: BeaconState): uint64 =
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#get_eth1_data
func is_candidate_block(blk: Eth1Block, period_start: uint64): bool =
(blk.timestamp <= period_start - SECONDS_PER_ETH1_BLOCK * ETH1_FOLLOW_DISTANCE) and
(blk.timestamp >= period_start - SECONDS_PER_ETH1_BLOCK * ETH1_FOLLOW_DISTANCE * 2)
(blk.timestamp + SECONDS_PER_ETH1_BLOCK.uint64 * ETH1_FOLLOW_DISTANCE.uint64 <= period_start) and
(blk.timestamp + SECONDS_PER_ETH1_BLOCK.uint64 * ETH1_FOLLOW_DISTANCE.uint64 * 2 >= period_start)
func asEth2Digest(x: BlockHash): Eth2Digest =
Eth2Digest(data: array[32, byte](x))

View File

@ -65,7 +65,8 @@ const
SPEC_VERSION* = "0.11.1" ## \
## Spec version we're aiming to be compatible with, right now
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
GENESIS_SLOT* = Slot(0)
GENESIS_EPOCH* = (GENESIS_SLOT.int div SLOTS_PER_EPOCH).Epoch ##\
## compute_epoch_at_slot(GENESIS_SLOT)
FAR_FUTURE_EPOCH* = (not 0'u64).Epoch # 2^64 - 1 in spec
@ -84,6 +85,9 @@ const
SLOTS_PER_ETH1_VOTING_PERIOD* = Slot(EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH)
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
BASE_REWARDS_PER_EPOCH* = 4
template maxSize*(n: int) {.pragma.}
type

View File

@ -1,5 +1,9 @@
import
macros, strutils, tables
macros, strutils, tables,
stew/endians2
export
toBytesBE
type
BeaconChainConstants* {.pure.} = enum
@ -7,21 +11,33 @@ type
BASE_REWARD_FACTOR
BLS_WITHDRAWAL_PREFIX
CHURN_LIMIT_QUOTIENT
CUSTODY_PERIOD_TO_RANDAO_PADDING
DEPOSIT_CONTRACT_ADDRESS
DEPOSIT_CONTRACT_TREE_DEPTH
DOMAIN_AGGREGATE_AND_PROOF
DOMAIN_BEACON_ATTESTER
DOMAIN_BEACON_PROPOSER
DOMAIN_CUSTODY_BIT_SLASHING
DOMAIN_DEPOSIT
DOMAIN_LIGHT_CLIENT
DOMAIN_RANDAO
DOMAIN_SELECTION_PROOF
DOMAIN_SHARD_COMMITTEE
DOMAIN_SHARD_PROPOSAL
DOMAIN_VOLUNTARY_EXIT
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE
EFFECTIVE_BALANCE_INCREMENT
EJECTION_BALANCE
EPOCHS_PER_CUSTODY_PERIOD
EPOCHS_PER_ETH1_VOTING_PERIOD
EPOCHS_PER_HISTORICAL_VECTOR
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION
EPOCHS_PER_SLASHINGS_VECTOR
ETH1_FOLLOW_DISTANCE
GASPRICE_ADJUSTMENT_COEFFICIENT
GENESIS_EPOCH
GENESIS_FORK_VERSION
GENESIS_SLOT
HISTORICAL_ROOTS_LIMIT
HYSTERESIS_DOWNWARD_MULTIPLIER
@ -41,6 +57,7 @@ type
MAX_DEPOSITS
MAX_EARLY_DERIVED_SECRET_REVEALS
MAX_EFFECTIVE_BALANCE
MAX_EPOCHS_PER_CROSSLINK
MAX_GASPRICE
MAX_PROPOSER_SLASHINGS
MAX_REVEAL_LATENESS_DECREMENT
@ -56,6 +73,7 @@ type
MIN_EPOCHS_TO_INACTIVITY_PENALTY
MIN_GASPRICE
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
MIN_GENESIS_DELAY
MIN_GENESIS_TIME
MIN_PER_EPOCH_CHURN_LIMIT
MIN_SEED_LOOKAHEAD
@ -66,14 +84,18 @@ type
PHASE_1_FORK_VERSION
PROPOSER_REWARD_QUOTIENT
RANDAO_PENALTY_EPOCHS
RANDOM_SUBNETS_PER_VALIDATOR
SAFE_SLOTS_TO_UPDATE_JUSTIFIED
SECONDS_PER_DAY
SECONDS_PER_ETH1_BLOCK
SECONDS_PER_SLOT
SHARD_BLOCK_CHUNK_SIZE
SHARD_BLOCK_OFFSETS
SHARD_COMMITTEE_PERIOD
SHUFFLE_ROUND_COUNT
SLOTS_PER_EPOCH
SLOTS_PER_HISTORICAL_ROOT
TARGET_AGGREGATORS_PER_COMMITTEE
TARGET_COMMITTEE_SIZE
TARGET_SHARD_BLOCK_SIZE
VALIDATOR_REGISTRY_LIMIT
@ -88,30 +110,42 @@ const
SECONDS_PER_DAY,
# These are defined as an enum in datatypes.nim:
DOMAIN_BEACON_ATTESTER,
DOMAIN_BEACON_PROPOSER,
DOMAIN_DEPOSIT,
DOMAIN_BEACON_ATTESTER,
DOMAIN_RANDAO,
DOMAIN_DEPOSIT,
DOMAIN_VOLUNTARY_EXIT,
DOMAIN_SELECTION_PROOF,
DOMAIN_AGGREGATE_AND_PROOF,
DOMAIN_SHARD_PROPOSAL,
DOMAIN_SHARD_COMMITTEE,
DOMAIN_LIGHT_CLIENT,
DOMAIN_CUSTODY_BIT_SLASHING,
}
const
forkVersionConversionFn = "'u32.toBytesBE"
# The fork version appears as a number in the preset,
# but our codebase works with a byte array.
customTypes = {
GENESIS_SLOT: "Slot",
BLS_WITHDRAWAL_PREFIX: "byte",
BASE_REWARD_FACTOR: "uint64",
EFFECTIVE_BALANCE_INCREMENT: "uint64",
EJECTION_BALANCE: "uint64",
EPOCHS_PER_SLASHINGS_VECTOR: "uint64",
INACTIVITY_PENALTY_QUOTIENT: "uint64",
MAX_EFFECTIVE_BALANCE: "uint64",
MIN_DEPOSIT_AMOUNT: "uint64",
MIN_EPOCHS_TO_INACTIVITY_PENALTY: "uint64",
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: "uint64",
PERSISTENT_COMMITTEE_PERIOD: "uint64",
PROPOSER_REWARD_QUOTIENT: "uint64",
SECONDS_PER_SLOT: "uint64",
WHISTLEBLOWER_REWARD_QUOTIENT: "uint64",
BASE_REWARD_FACTOR: "'u64",
BLS_WITHDRAWAL_PREFIX: ".byte",
EFFECTIVE_BALANCE_INCREMENT: "'u64",
EJECTION_BALANCE: "'u64",
EPOCHS_PER_SLASHINGS_VECTOR: "'u64",
GENESIS_FORK_VERSION: forkVersionConversionFn,
GENESIS_SLOT: ".Slot",
INACTIVITY_PENALTY_QUOTIENT: "'u64",
MAX_EFFECTIVE_BALANCE: "'u64",
MIN_DEPOSIT_AMOUNT: "'u64",
MIN_EPOCHS_TO_INACTIVITY_PENALTY: "'u64",
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: "'u64",
PERSISTENT_COMMITTEE_PERIOD: "'u64",
PHASE_1_FORK_VERSION: forkVersionConversionFn,
PROPOSER_REWARD_QUOTIENT: "'u64",
SECONDS_PER_SLOT: "'u64",
WHISTLEBLOWER_REWARD_QUOTIENT: "'u64",
}.toTable
template entireSet(T: type enum): untyped =
@ -139,13 +173,17 @@ macro loadCustomPreset*(path: static string): untyped =
try:
let constant = parseEnum[BeaconChainConstants](constParts[0])
if constant in dubiousConstants: continue
constParts.add customTypes.getOrDefault(constant, "int")
if customTypes.hasKey(constant):
constParts.add customTypes[constant]
presetConstants.incl constant
except ValueError:
warning lineinfo & "Unrecognized constant in a preset: " & constParts[0]
continue
result.add parseStmt("const $1* {.intdefine.} = $3($2)" % constParts)
if constParts.len == 3:
result.add parseStmt("const $1* {.intdefine.} = $2$3" % constParts)
else:
result.add parseStmt("const $1* {.intdefine.} = $2" % constParts)
let missingConstants = BeaconChainConstants.entireSet - presetConstants
if missingConstants.card > 0:

View File

@ -48,12 +48,6 @@ const
HYSTERESIS_DOWNWARD_MULTIPLIER* = 1
HYSTERESIS_UPWARD_MULTIPLIER* = 5
# Constants (TODO: not actually configurable)
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#constants
BASE_REWARDS_PER_EPOCH* = 4
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
# Gwei values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/mainnet.yaml#L58
@ -74,7 +68,6 @@ const
# Initial values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/mainnet.yaml#L70
GENESIS_SLOT* = 0.Slot
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
BLS_WITHDRAWAL_PREFIX* = 0'u8

View File

@ -41,15 +41,6 @@ const
HYSTERESIS_DOWNWARD_MULTIPLIER* = 1
HYSTERESIS_UPWARD_MULTIPLIER* = 5
# Constants
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#constants
# TODO "The following values are (non-configurable) constants" ...
# Unchanged
BASE_REWARDS_PER_EPOCH* = 4
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
# Gwei values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L58
@ -64,7 +55,6 @@ const
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L70
GENESIS_SLOT* = 0.Slot
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 1'u8]
BLS_WITHDRAWAL_PREFIX* = 0'u8

View File

@ -7,6 +7,7 @@ const
bootstrapYamlFileName = "boot_enr.yaml"
depositContractFileName = "deposit_contract.txt"
genesisFile = "genesis.ssz"
configFile = "config.yaml"
testnetsRepo = "eth2-testnets"
web3Url = "wss://goerli.infura.io/ws/v3/809a18497dd74102b5f37d25aae3c85a"
@ -24,8 +25,13 @@ proc validateTestnetName(parts: openarray[string]): auto =
cli do (skipGoerliKey {.
desc: "Don't prompt for an Eth1 Goerli key to become a validator" .}: bool,
testnetName {.
argument .}: string):
constPreset {.
defaultValue: ""
desc: "The Ethereum 2.0 const preset of the network (optional)"
name: "const-preset" .}: string,
testnetName {.argument .}: string):
let
nameParts = testnetName.split "/"
(team, testnet) = if nameParts.len > 1: validateTestnetName nameParts
@ -67,6 +73,11 @@ cli do (skipGoerliKey {.
else:
echo "Warning: the network metadata doesn't include a bootstrap file"
var preset = testnetDir / configFile
if not system.fileExists(preset):
preset = constPreset
if preset.len == 0: preset = "minimal"
let
dataDirName = testnetName.replace("/", "_")
.replace("(", "_")
@ -96,7 +107,7 @@ cli do (skipGoerliKey {.
rmDir dataDir
cd rootDir
exec &"""nim c {nimFlags} -o:"{beaconNodeBinary}" beacon_chain/beacon_node.nim"""
exec &"""nim c {nimFlags} -d:"const_preset={preset}" -o:"{beaconNodeBinary}" beacon_chain/beacon_node.nim"""
mkDir dumpDir