2018-11-18 16:39:35 +00:00
// Package params defines important constants that are essential to the
// Ethereum 2.0 services.
2018-07-14 02:15:37 +00:00
package params
2018-07-11 22:29:31 +00:00
2018-09-22 20:15:39 +00:00
import (
2019-01-28 08:45:28 +00:00
"math/big"
2018-09-27 02:34:35 +00:00
"time"
2018-09-22 20:15:39 +00:00
)
2018-12-25 06:47:07 +00:00
func makeEmptySignature ( ) [ ] [ ] byte {
signature := make ( [ ] [ ] byte , 2 )
signature [ 0 ] = make ( [ ] byte , 48 )
signature [ 1 ] = make ( [ ] byte , 48 )
return signature
}
2019-01-06 04:36:05 +00:00
// BeaconChainConfig contains constant configs for node to participate in beacon chain.
2018-11-21 01:41:20 +00:00
type BeaconChainConfig struct {
2019-01-06 04:36:05 +00:00
// Misc constants.
2019-01-30 10:11:13 +00:00
ShardCount uint64 // ShardCount is the number of shard chains in Ethereum 2.0.
TargetCommitteeSize uint64 // TargetCommitteeSize is the number of validators in a committee when the chain is healthy.
MaxBalanceChurnQuotient uint64 // MaxBalanceChurnQuotient is used to determine how many validators can rotate per epoch.
BeaconChainShardNumber uint64 // BeaconChainShardNumber is the shard number of the beacon chain.
MaxIndicesPerSlashableVote uint64 // MaxIndicesPerSlashableVote is used to determine how many validators can be slashed per vote.
LatestBlockRootsLength uint64 // LatestBlockRootsLength is the number of block roots kept in the beacon state.
LatestRandaoMixesLength uint64 // LatestRandaoMixesLength is the number of randao mixes kept in the beacon state.
LatestPenalizedExitLength uint64 // LatestPenalizedExitLength is used to track penalized exit balances per time interval.
2019-02-01 21:22:52 +00:00
LatestIndexRootsLength uint64 // LatestIndexRootsLength is the number of index roots kept in beacon state, used by light client.
2019-01-30 10:11:13 +00:00
MaxWithdrawalsPerEpoch uint64 // MaxWithdrawalsPerEpoch is the max withdrawals can happen for a single epoch.
2019-02-13 18:08:25 +00:00
BLSPubkeyLength int // BLSPubkeyLength defines the expected length of BLS public keys in bytes.
2019-01-06 04:36:05 +00:00
// Deposit contract constants.
DepositContractAddress [ ] byte // DepositContractAddress is the address of the deposit contract in PoW chain.
DepositContractTreeDepth uint64 // Depth of the Merkle trie of deposits in the validator deposit contract on the PoW chain.
2019-02-09 13:09:09 +00:00
// Gwei Values
MinDepositAmount uint64 // MinDepositAmount is the maximal amount of Gwei a validator can send to the deposit contract at once.
MaxDepositAmount uint64 // MaxDepositAmount is the maximal amount of Gwei a validator can send to the deposit contract at once.
EjectionBalance uint64 // EjectionBalance is the minimal GWei a validator needs to have before ejected.
2019-01-06 04:36:05 +00:00
// Initial value constants.
GenesisForkVersion uint64 // GenesisForkVersion is used to track fork version between state transitions.
2019-01-20 18:26:33 +00:00
GenesisSlot uint64 // GenesisSlot is used to initialize the genesis state fields.
2019-02-04 20:34:33 +00:00
GenesisEpoch uint64 // GenesisEpoch is used to initialize epoch.
2019-01-20 18:26:33 +00:00
GenesisStartShard uint64 // GenesisStartShard is the first shard to assign validators.
2019-01-06 04:36:05 +00:00
ZeroHash [ 32 ] byte // ZeroHash is used to represent a zeroed out 32 byte array.
EmptySignature [ ] [ ] byte // EmptySignature is used to represent a zeroed out BLS Signature.
BLSWithdrawalPrefixByte byte // BLSWithdrawalPrefixByte is used for BLS withdrawal and it's the first byte.
// Time parameters constants.
SlotDuration uint64 // SlotDuration is how many seconds are in a single slot.
MinAttestationInclusionDelay uint64 // MinAttestationInclusionDelay defines how long validator has to wait to include attestation for beacon block.
EpochLength uint64 // EpochLength is the number of slots in an epoch.
SeedLookahead uint64 // SeedLookahead is the duration of randao look ahead seed.
2019-02-04 20:34:33 +00:00
EntryExitDelay uint64 // EntryExitDelay is the duration a validator has to wait for entry and exit in epoch.
Eth1DataVotingPeriod uint64 // Eth1DataVotingPeriod defines how often the merkle root of deposit receipts get updated in beacon node.
2019-02-03 19:21:18 +00:00
Eth1FollowDistance uint64 // Eth1FollowDistance is the number of eth1.0 blocks to wait before considering a new deposit for voting. This only applies after the chain as been started.
2019-02-04 20:34:33 +00:00
MinValidatorWithdrawalEpochs uint64 // MinValidatorWithdrawalEpochs is the shortest amount of time a validator can get the deposit out.
FarFutureEpoch uint64 // FarFutureEpoch represents a epoch extremely far away in the future used as the default penalization slot for validators.
2019-01-06 04:36:05 +00:00
// Reward and penalty quotients constants.
BaseRewardQuotient uint64 // BaseRewardQuotient is used to calculate validator per-slot interest rate.
WhistlerBlowerRewardQuotient uint64 // WhistlerBlowerRewardQuotient is used to calculate whistler blower reward.
IncluderRewardQuotient uint64 // IncluderRewardQuotient defines the reward quotient of proposer for including attestations..
InactivityPenaltyQuotient uint64 // InactivityPenaltyQuotient defines how much validator leaks out balances for offline.
// Max operations per block constants.
MaxExits uint64 // MaxExits determines the maximum number of validator exits in a block.
MaxDeposits uint64 // MaxExits determines the maximum number of validator deposits in a block.
MaxAttestations uint64 // MaxAttestations defines the maximum allowed attestations in a beacon block.
MaxProposerSlashings uint64 // MaxProposerSlashings defines the maximum number of slashings of proposers possible in a block.
2019-01-30 10:11:13 +00:00
MaxAttesterSlashings uint64 // MaxAttesterSlashings defines the maximum number of casper FFG slashings possible in a block.
2019-01-06 04:36:05 +00:00
// Prysm constants.
2019-01-11 08:29:30 +00:00
DepositsForChainStart uint64 // DepositsForChainStart defines how many validator deposits needed to kick off beacon chain.
SimulatedBlockRandao [ 32 ] byte // SimulatedBlockRandao is a RANDAO seed stubbed in simulated block for advancing local beacon chain.
RandBytes uint64 // RandBytes is the number of bytes used as entropy to shuffle validators.
SyncPollingInterval int64 // SyncPollingInterval queries network nodes for sync status.
GenesisTime time . Time // GenesisTime used by the protocol.
MaxNumLog2Validators uint64 // MaxNumLog2Validators is the Max number of validators in Log2 exists given total ETH supply.
2018-09-28 06:48:39 +00:00
}
2019-01-28 08:45:28 +00:00
// DepositContractConfig contains the deposits for
type DepositContractConfig struct {
DepositsForChainStart * big . Int // DepositsForChainStart defines how many validator deposits needed to kick off beacon chain.
MinDepositAmount * big . Int // MinDepositAmount defines the minimum deposit amount in gwei that is required in the deposit contract.
MaxDepositAmount * big . Int // // MaxDepositAmount defines the minimum deposit amount in gwei that is required in the deposit contract.
}
2018-11-21 01:41:20 +00:00
// ShardChainConfig contains configs for node to participate in shard chains.
type ShardChainConfig struct {
ChunkSize uint64 // ChunkSize defines the size of each chunk in bytes.
MaxShardBlockSize uint64 // MaxShardBlockSize defines the max size of each shard block in bytes.
}
var defaultBeaconConfig = & BeaconChainConfig {
2019-01-06 04:36:05 +00:00
// Misc constant.
2019-01-30 10:11:13 +00:00
ShardCount : 1024 ,
TargetCommitteeSize : 128 ,
MaxBalanceChurnQuotient : 32 ,
BeaconChainShardNumber : 1 << 64 - 1 ,
MaxIndicesPerSlashableVote : 1 ,
LatestBlockRootsLength : 8192 ,
LatestRandaoMixesLength : 8192 ,
LatestPenalizedExitLength : 8192 ,
2019-02-01 21:22:52 +00:00
LatestIndexRootsLength : 8192 ,
2019-01-30 10:11:13 +00:00
MaxWithdrawalsPerEpoch : 4 ,
2019-02-13 18:08:25 +00:00
BLSPubkeyLength : 96 ,
2019-01-06 04:36:05 +00:00
// Deposit contract constants.
DepositContractTreeDepth : 32 ,
2019-02-09 13:09:09 +00:00
// Gwei values:
MinDepositAmount : 1 * 1e9 ,
MaxDepositAmount : 32 * 1e9 ,
EjectionBalance : 16 * 1e9 ,
2019-01-06 04:36:05 +00:00
// Initial value constants.
GenesisForkVersion : 0 ,
2019-02-10 22:09:35 +00:00
GenesisSlot : 1 << 63 ,
GenesisEpoch : 1 << 63 / 64 ,
2019-01-20 18:26:33 +00:00
GenesisStartShard : 0 ,
2019-02-04 20:34:33 +00:00
FarFutureEpoch : 1 << 64 - 1 ,
2019-01-06 04:36:05 +00:00
ZeroHash : [ 32 ] byte { } ,
EmptySignature : makeEmptySignature ( ) ,
// Time parameter constants.
2019-01-29 04:16:50 +00:00
SlotDuration : 6 ,
2019-01-06 04:36:05 +00:00
MinAttestationInclusionDelay : 4 ,
EpochLength : 64 ,
2019-02-06 02:18:55 +00:00
SeedLookahead : 1 ,
2019-02-04 20:34:33 +00:00
EntryExitDelay : 4 ,
2019-02-03 19:21:18 +00:00
Eth1DataVotingPeriod : 16 ,
Eth1FollowDistance : 1024 ,
2019-01-06 04:36:05 +00:00
// Reward and penalty quotients constants.
2019-01-29 04:16:50 +00:00
BaseRewardQuotient : 32 ,
2019-01-06 04:36:05 +00:00
WhistlerBlowerRewardQuotient : 512 ,
IncluderRewardQuotient : 8 ,
InactivityPenaltyQuotient : 1 << 24 ,
// Max operations per block constants.
MaxExits : 16 ,
MaxDeposits : 16 ,
MaxAttestations : 128 ,
MaxProposerSlashings : 16 ,
2019-01-30 10:11:13 +00:00
MaxAttesterSlashings : 1 ,
2019-01-06 04:36:05 +00:00
// Prysm constants.
DepositsForChainStart : 16384 ,
RandBytes : 3 ,
2019-01-29 04:16:50 +00:00
SyncPollingInterval : 6 * 4 , // Query nodes over the network every 4 slots for sync status.
2019-01-06 04:36:05 +00:00
GenesisTime : time . Date ( 2018 , 9 , 0 , 0 , 0 , 0 , 0 , time . UTC ) ,
MaxNumLog2Validators : 24 ,
2018-09-28 06:48:39 +00:00
}
2018-11-21 01:41:20 +00:00
var defaultShardConfig = & ShardChainConfig {
ChunkSize : uint64 ( 256 ) ,
MaxShardBlockSize : uint64 ( 32768 ) ,
}
2019-01-28 08:45:28 +00:00
var defaultDepositContractConfig = & DepositContractConfig {
DepositsForChainStart : big . NewInt ( 16384 ) ,
MinDepositAmount : big . NewInt ( 1e9 ) ,
MaxDepositAmount : big . NewInt ( 32e9 ) ,
}
2018-11-18 16:39:35 +00:00
var beaconConfig = defaultBeaconConfig
2018-11-21 01:41:20 +00:00
var shardConfig = defaultShardConfig
2019-01-28 08:45:28 +00:00
var contractConfig = defaultDepositContractConfig
2018-11-18 16:39:35 +00:00
2018-11-21 01:41:20 +00:00
// BeaconConfig retrieves beacon chain config.
func BeaconConfig ( ) * BeaconChainConfig {
2018-11-18 16:39:35 +00:00
return beaconConfig
}
2019-02-13 14:34:58 +00:00
// DemoBeaconConfig retrieves the demo beacon chain config.
func DemoBeaconConfig ( ) * BeaconChainConfig {
demoConfig := * defaultBeaconConfig
demoConfig . ShardCount = 5
demoConfig . TargetCommitteeSize = 3
demoConfig . SlotDuration = 2
demoConfig . SyncPollingInterval = 2 * 4 // Query nodes over the network every 4 slots for sync status.
demoConfig . GenesisTime = time . Now ( )
demoConfig . SimulatedBlockRandao = [ 32 ] byte { 'S' , 'I' , 'M' , 'U' , 'L' , 'A' , 'T' , 'O' , 'R' }
return & demoConfig
}
2018-11-21 01:41:20 +00:00
// ShardConfig retrieves shard chain config.
func ShardConfig ( ) * ShardChainConfig {
return shardConfig
}
2019-01-28 08:45:28 +00:00
// ContractConfig retrieves the deposit contract config
func ContractConfig ( ) * DepositContractConfig {
return contractConfig
}
// DemoContractConfig uses the argument provided to initialize a fresh config.
func DemoContractConfig ( depositsReq * big . Int , minDeposit * big . Int , maxDeposit * big . Int ) * DepositContractConfig {
return & DepositContractConfig {
DepositsForChainStart : depositsReq ,
MinDepositAmount : minDeposit ,
MaxDepositAmount : maxDeposit ,
}
}
2018-11-18 16:39:35 +00:00
// UseDemoBeaconConfig for beacon chain services.
func UseDemoBeaconConfig ( ) {
2019-02-13 14:34:58 +00:00
beaconConfig = DemoBeaconConfig ( )
2018-11-18 16:39:35 +00:00
}
// OverrideBeaconConfig by replacing the config. The preferred pattern is to
// call BeaconConfig(), change the specific parameters, and then call
// OverrideBeaconConfig(c). Any subsequent calls to params.BeaconConfig() will
// return this new configuration.
2018-11-21 01:41:20 +00:00
func OverrideBeaconConfig ( c * BeaconChainConfig ) {
2018-11-18 16:39:35 +00:00
beaconConfig = c
}