db

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2024 License: AGPL-3.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultChainID                      uint64 = 0x90de5e7
	DefaultDepositContractAddressString string = "0xde905175eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
)
View Source
const (
	FarFutureEpoch  uint64 = 0xffffffffffffffff
	StartingBalance uint64 = 32e9
)

Variables

View Source
var (
	// Default config
	DefaultDepositContractAddress common.Address = common.HexToAddress(DefaultDepositContractAddressString)
)

Functions

This section is empty.

Types

type Config

type Config struct {

	// Basic settings
	ChainID                      uint64         `json:"chainID" yaml:"chainID"`
	SecondsPerSlot               uint64         `json:"secondsPerSlot" yaml:"secondsPerSlot"`
	SlotsPerEpoch                uint64         `json:"slotsPerEpoch" yaml:"slotsPerEpoch"`
	EpochsPerSyncCommitteePeriod uint64         `json:"epochsPerSyncCommitteePeriod" yaml:"epochsPerSyncCommitteePeriod"`
	DepositContract              common.Address `json:"depositContract" yaml:"depositContract"`

	// Genesis info
	GenesisTime           time.Time       `json:"genesisTime,omitempty" yaml:"genesisTime,omitempty"`
	GenesisForkVersion    utils.ByteArray `json:"genesisForkVersion" yaml:"genesisForkVersion"`
	GenesisValidatorsRoot utils.ByteArray `json:"genesisValidatorsRoot" yaml:"genesisValidatorsRoot"`

	// Altair info
	AltairForkVersion utils.ByteArray `json:"altairForkVersion" yaml:"altairForkVersion"`
	AltairForkEpoch   uint64          `json:"altairForkEpoch" yaml:"altairForkEpoch"`

	// Bellatrix info
	BellatrixForkVersion utils.ByteArray `json:"bellatrixForkVersion" yaml:"bellatrixForkVersion"`
	BellatrixForkEpoch   uint64          `json:"bellatrixForkEpoch" yaml:"bellatrixForkEpoch"`

	// Capella info
	CapellaForkVersion utils.ByteArray `json:"capellaForkVersion" yaml:"capellaForkVersion"`
	CapellaForkEpoch   uint64          `json:"capellaForkEpoch" yaml:"capellaForkEpoch"`

	// Deneb info
	DenebForkVersion utils.ByteArray `json:"denebForkVersion" yaml:"denebForkVersion"`
	DenebForkEpoch   uint64          `json:"denebForkEpoch" yaml:"denebForkEpoch"`

	// The index of the first execution layer block to be linked to in a Beacon chain slot
	FirstExecutionBlockIndex uint64
}

Basic Beacon Chain configuration

func LoadFromFile added in v0.3.0

func LoadFromFile(path string) (*Config, error)

Creates a new config instance from a file

func NewDefaultConfig

func NewDefaultConfig() *Config

Creates a new default config instance

func (*Config) Clone

func (c *Config) Clone() *Config

Clones a config into a new instance

type Database

type Database struct {
	// contains filtered or unexported fields
}

Beacon mock database

func NewDatabase

func NewDatabase(logger *slog.Logger, firstExecutionBlockIndex uint64) *Database

Create a new database instance

func (*Database) AddValidator

func (db *Database) AddValidator(pubkey beacon.ValidatorPubkey, withdrawalCredentials common.Hash) (*Validator, error)

Add a new validator to the database. Returns an error if the validator already exists.

func (*Database) Clone

func (db *Database) Clone() *Database

Clone the database into a new instance

func (*Database) CommitBlock

func (db *Database) CommitBlock(slotValidated bool)

Add a new block to the chain. Set slotValidated to true to "propose a block" for the current slot, linking it to the next Execution block's index. Set it to false to "miss" the slot, so there was not block proposed for it.

func (*Database) GetAllValidators

func (db *Database) GetAllValidators() []*Validator

Get all validators

func (*Database) GetCurrentSlot

func (db *Database) GetCurrentSlot() uint64

Get the latest local head slot

func (*Database) GetHighestSlot

func (db *Database) GetHighestSlot() uint64

Get the highest slot on the chain (the actual chain head)

func (*Database) GetValidatorByIndex

func (db *Database) GetValidatorByIndex(index uint) *Validator

Get a validator by its index. Returns nil if it doesn't exist.

func (*Database) GetValidatorByPubkey

func (db *Database) GetValidatorByPubkey(pubkey beacon.ValidatorPubkey) *Validator

Get a validator by its pubkey. Returns nil if it doesn't exist.

func (*Database) SetHighestSlot

func (db *Database) SetHighestSlot(slot uint64)

Set the highest slot on the chain - useful for simulating syncing conditions

type Validator

type Validator struct {
	Pubkey                     beacon.ValidatorPubkey
	Index                      uint64
	WithdrawalCredentials      common.Hash
	Balance                    uint64
	Status                     beacon.ValidatorState
	EffectiveBalance           uint64
	Slashed                    bool
	ActivationEligibilityEpoch uint64
	ActivationEpoch            uint64
	ExitEpoch                  uint64
	WithdrawableEpoch          uint64
}

func NewValidator

func NewValidator(pubkey beacon.ValidatorPubkey, withdrawalCredentials common.Hash, index uint64) *Validator

func (*Validator) Clone

func (v *Validator) Clone() *Validator

func (*Validator) GetValidatorMeta

func (v *Validator) GetValidatorMeta() client.Validator

func (*Validator) SetBalance

func (v *Validator) SetBalance(balanceGwei uint64)

func (*Validator) SetStatus

func (v *Validator) SetStatus(status beacon.ValidatorState)

func (*Validator) Slash

func (v *Validator) Slash(penaltyGwei uint64) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL