diff --git a/README.md b/README.md index f71b2ef1..06f867e6 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ eth-genesis-state-generator beaconchain \ balance: 32000000000 # effective balance wd_address: "0x1234567890123456789012345678901234567890" # withdrawal address wd_prefix: "0x02" # withdrawal credentials prefix + status: 0 # validator status: 0=active, 1=slashed, 2=exited ``` ## Development diff --git a/beaconutils/validators.go b/beaconutils/validators.go index 6be1e5f0..68b796c7 100644 --- a/beaconutils/validators.go +++ b/beaconutils/validators.go @@ -55,9 +55,18 @@ func GetGenesisValidators(cfg *beaconconfig.Config, vals []*validators.Validator WithdrawableEpoch: phase0.Epoch(cfg.GetUintDefault("FAR_FUTURE_EPOCH", 18446744073709551615)), } - if effectiveBalance >= maxEffectiveBalance { + switch val.Status { + case validators.ValidatorStatusActive: + if effectiveBalance >= maxEffectiveBalance { + validator.ActivationEligibilityEpoch = phase0.Epoch(0) + validator.ActivationEpoch = phase0.Epoch(0) + } + case validators.ValidatorStatusSlashed, validators.ValidatorStatusExited: + validator.Slashed = val.Status == validators.ValidatorStatusSlashed validator.ActivationEligibilityEpoch = phase0.Epoch(0) validator.ActivationEpoch = phase0.Epoch(0) + validator.ExitEpoch = phase0.Epoch(0) + validator.WithdrawableEpoch = phase0.Epoch(0) } clValidators = append(clValidators, validator) diff --git a/validators/mnemonic.go b/validators/mnemonic.go index 94454b10..aa22b61f 100644 --- a/validators/mnemonic.go +++ b/validators/mnemonic.go @@ -60,6 +60,7 @@ func GenerateValidatorsByMnemonic(mnemonicsConfigPath string) ([]*Validator, err data := &Validator{ PublicKey: phase0.BLSPubKey(signingSK.PublicKey().Marshal()), WithdrawalCredentials: make([]byte, 32), + Status: mnemonicSrc.Status, } if mnemonicSrc.WdPrefix != "" && mnemonicSrc.WdPrefix != "0x00" && mnemonicSrc.WdAddress != "" { @@ -143,13 +144,14 @@ func seedFromMnemonic(mnemonic string) (seed []byte, err error) { } type MnemonicSrc struct { - Mnemonic string `yaml:"mnemonic"` - Start uint64 `yaml:"start"` - Count uint64 `yaml:"count"` - Balance uint64 `yaml:"balance"` - WdAddress string `yaml:"wd_address"` - WdPrefix string `yaml:"wd_prefix"` - WdKeyPath string `yaml:"wd_key_path"` + Mnemonic string `yaml:"mnemonic"` + Start uint64 `yaml:"start"` + Count uint64 `yaml:"count"` + Balance uint64 `yaml:"balance"` + WdAddress string `yaml:"wd_address"` + WdPrefix string `yaml:"wd_prefix"` + WdKeyPath string `yaml:"wd_key_path"` + Status ValidatorStatus `yaml:"status"` } func loadMnemonics(srcPath string) ([]MnemonicSrc, error) { diff --git a/validators/validators.go b/validators/validators.go index f8e08c50..56e353c7 100644 --- a/validators/validators.go +++ b/validators/validators.go @@ -4,8 +4,17 @@ import ( "github.com/attestantio/go-eth2-client/spec/phase0" ) +type ValidatorStatus uint8 + +const ( + ValidatorStatusActive ValidatorStatus = iota + ValidatorStatusSlashed + ValidatorStatusExited +) + type Validator struct { PublicKey phase0.BLSPubKey WithdrawalCredentials []byte Balance *uint64 + Status ValidatorStatus }