2019-08-28 12:07:00 +00:00
|
|
|
# beacon_chain
|
2021-06-24 07:11:47 +00:00
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
2019-08-28 12:07:00 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * 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).
|
2019-08-28 12:07:00 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
# Mocking deposits and genesis deposits
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
import
|
|
|
|
# Standard library
|
2020-11-16 16:10:51 +00:00
|
|
|
math,
|
2020-07-07 23:02:14 +00:00
|
|
|
|
2019-08-28 12:07:00 +00:00
|
|
|
# Specs
|
2021-08-12 13:08:20 +00:00
|
|
|
../../beacon_chain/spec/[keystore, signatures],
|
2021-06-24 07:11:47 +00:00
|
|
|
../../beacon_chain/spec/datatypes/base,
|
2020-07-07 23:02:14 +00:00
|
|
|
|
2019-08-28 12:07:00 +00:00
|
|
|
# Internals
|
2021-03-03 06:23:05 +00:00
|
|
|
../../beacon_chain/extras,
|
|
|
|
../../beacon_chain/ssz,
|
|
|
|
../../beacon_chain/eth1/merkle_minimal,
|
2020-07-07 23:02:14 +00:00
|
|
|
|
2019-08-28 12:07:00 +00:00
|
|
|
# Mocking procs
|
2020-04-15 07:59:47 +00:00
|
|
|
./mock_validator_keys
|
2019-08-28 12:07:00 +00:00
|
|
|
|
|
|
|
func mockDepositData(
|
|
|
|
pubkey: ValidatorPubKey,
|
|
|
|
amount: uint64,
|
2020-06-16 05:45:04 +00:00
|
|
|
): DepositData =
|
2019-08-28 12:07:00 +00:00
|
|
|
# Insecurely use pubkey as withdrawal key
|
2020-06-16 05:45:04 +00:00
|
|
|
DepositData(
|
|
|
|
pubkey: pubkey,
|
|
|
|
withdrawal_credentials: makeWithdrawalCredentials(pubkey),
|
|
|
|
amount: amount,
|
|
|
|
)
|
2019-08-28 12:07:00 +00:00
|
|
|
|
|
|
|
func mockDepositData(
|
|
|
|
pubkey: ValidatorPubKey,
|
|
|
|
privkey: ValidatorPrivKey,
|
|
|
|
amount: uint64,
|
|
|
|
# withdrawal_credentials: Eth2Digest,
|
|
|
|
flags: UpdateFlags = {}
|
2020-06-16 05:45:04 +00:00
|
|
|
): DepositData =
|
|
|
|
var ret = mockDepositData(pubkey, amount)
|
2020-03-05 12:52:10 +00:00
|
|
|
if skipBlsValidation notin flags:
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
ret.signature = defaultRuntimeConfig.get_deposit_signature(ret, privkey).toValidatorSig()
|
2020-06-16 05:45:04 +00:00
|
|
|
ret
|
2019-08-28 12:07:00 +00:00
|
|
|
|
|
|
|
template mockGenesisDepositsImpl(
|
2020-11-14 21:43:27 +00:00
|
|
|
result: seq[DepositData],
|
2019-08-28 12:07:00 +00:00
|
|
|
validatorCount: uint64,
|
|
|
|
amount: untyped,
|
|
|
|
flags: UpdateFlags = {},
|
|
|
|
updateAmount: untyped,
|
|
|
|
) =
|
|
|
|
# Genesis deposits with varying amounts
|
|
|
|
|
2020-06-12 16:03:46 +00:00
|
|
|
# NOTE: prefer to er on the side of caution and generate a valid Deposit
|
|
|
|
# (it can still be skipped later).
|
2020-03-05 12:52:10 +00:00
|
|
|
if skipBlsValidation in flags:
|
2019-08-28 12:07:00 +00:00
|
|
|
# 1st loop - build deposit data
|
2020-07-26 18:55:48 +00:00
|
|
|
for valIdx in 0 ..< validatorCount:
|
2019-08-28 12:07:00 +00:00
|
|
|
# Directly build the Deposit in-place for speed
|
|
|
|
result.setLen(valIdx + 1)
|
|
|
|
|
|
|
|
updateAmount
|
|
|
|
|
|
|
|
# DepositData
|
2020-11-14 21:43:27 +00:00
|
|
|
result[valIdx] = mockDepositData(MockPubKeys[valIdx], amount)
|
2019-08-28 12:07:00 +00:00
|
|
|
else: # With signing
|
|
|
|
var depositsDataHash: seq[Eth2Digest]
|
|
|
|
var depositsData: seq[DepositData]
|
|
|
|
|
|
|
|
# 1st loop - build deposit data
|
2020-07-26 18:55:48 +00:00
|
|
|
for valIdx in 0 ..< validatorCount:
|
2019-08-28 12:07:00 +00:00
|
|
|
# Directly build the Deposit in-place for speed
|
|
|
|
result.setLen(valIdx + 1)
|
|
|
|
|
|
|
|
updateAmount
|
|
|
|
|
|
|
|
# DepositData
|
2020-11-14 21:43:27 +00:00
|
|
|
result[valIdx] = mockDepositData(
|
2020-06-16 05:45:04 +00:00
|
|
|
MockPubKeys[valIdx], MockPrivKeys[valIdx], amount, flags)
|
2019-08-28 12:07:00 +00:00
|
|
|
|
2020-11-14 21:43:27 +00:00
|
|
|
depositsData.add result[valIdx]
|
|
|
|
depositsDataHash.add hash_tree_root(result[valIdx])
|
2019-08-28 12:07:00 +00:00
|
|
|
|
|
|
|
proc mockGenesisBalancedDeposits*(
|
|
|
|
validatorCount: uint64,
|
|
|
|
amountInEth: Positive,
|
|
|
|
flags: UpdateFlags = {}
|
2020-11-14 21:43:27 +00:00
|
|
|
): seq[DepositData] =
|
2019-08-28 12:07:00 +00:00
|
|
|
## The amount should be strictly positive
|
|
|
|
## - 1 is the minimum deposit amount (MIN_DEPOSIT_AMOUNT)
|
|
|
|
## - 16 is the ejection balance (EJECTION_BALANCE)
|
|
|
|
## - 32 is the max effective balance (MAX_EFFECTIVE_BALANCE)
|
|
|
|
## ETH beyond do not contribute more for staking.
|
|
|
|
##
|
|
|
|
## Only validators with 32 ETH will be active at genesis
|
|
|
|
|
|
|
|
let amount = amountInEth.uint64 * 10'u64^9
|
|
|
|
mockGenesisDepositsImpl(result, validatorCount,amount,flags):
|
|
|
|
discard
|
|
|
|
|
2021-06-24 07:11:47 +00:00
|
|
|
proc mockUpdateStateForNewDeposit*[T](
|
|
|
|
state: var T,
|
2019-08-28 12:07:00 +00:00
|
|
|
validator_index: uint64,
|
|
|
|
amount: uint64,
|
|
|
|
# withdrawal_credentials: Eth2Digest
|
|
|
|
flags: UpdateFlags
|
|
|
|
): Deposit =
|
|
|
|
|
2019-11-18 16:52:02 +00:00
|
|
|
|
2019-08-28 12:07:00 +00:00
|
|
|
# TODO withdrawal credentials
|
|
|
|
|
2020-06-16 05:45:04 +00:00
|
|
|
result.data = mockDepositData(
|
2019-08-28 12:07:00 +00:00
|
|
|
MockPubKeys[validator_index],
|
|
|
|
MockPrivKeys[validator_index],
|
|
|
|
amount,
|
|
|
|
# withdrawal_credentials: Eth2Digest
|
|
|
|
flags
|
|
|
|
)
|
|
|
|
|
2020-04-10 13:59:17 +00:00
|
|
|
var result_seq = @[result]
|
|
|
|
attachMerkleProofs(result_seq)
|
|
|
|
result.proof = result_seq[0].proof
|
2019-08-28 12:07:00 +00:00
|
|
|
|
|
|
|
# TODO: this logic from the eth2.0-specs test suite seems strange
|
|
|
|
# but confirmed by running it
|
|
|
|
state.eth1_deposit_index = 0
|
2020-04-10 13:59:17 +00:00
|
|
|
state.eth1_data.deposit_root =
|
2020-05-18 17:49:22 +00:00
|
|
|
hash_tree_root(List[DepositData, 2'i64^DEPOSIT_CONTRACT_TREE_DEPTH](@[result.data]))
|
2019-08-28 12:07:00 +00:00
|
|
|
state.eth1_data.deposit_count = 1
|