state

package
v1.20.4 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStaticMode = errors.New("operation not supported in static network state mode")

ErrStaticMode is returned by static EC/BC backends when a method is invoked that cannot be answered from a pre-loaded NetworkState snapshot. Handlers that have not yet been ported to consume NetworkStateProvider directly will surface this error instead of attempting a live EC/CC call.

Functions

This section is empty.

Types

type CriticalDutiesEpochs added in v1.15.0

type CriticalDutiesEpochs struct {
	// Map of epoch uint64 to a list of validator indices
	CriticalDuties map[uint64][]string
}

func NewCriticalDutiesEpochs added in v1.15.0

func NewCriticalDutiesEpochs(epochs uint64, state *NetworkState) *CriticalDutiesEpochs

Gets the critical duties slots for a given state as if it were the final state in a epochs epoch interval

type CriticalDutiesSlots added in v1.15.0

type CriticalDutiesSlots struct {
	// Map of validator index to a list of critical duties slots
	CriticalDuties map[string][]uint64
}

func NewCriticalDutiesSlots added in v1.15.0

func NewCriticalDutiesSlots(criticalDutiesEpochs *CriticalDutiesEpochs, bc beacon.Client) (*CriticalDutiesSlots, error)

For each validator in criticalDutiesEpochs, map the epochs to the slot the attestation duty assignment was for

type NetworkState

type NetworkState struct {

	// Block / slot for this state
	ElBlockNumber    uint64            `json:"el_block_number"`
	BeaconSlotNumber uint64            `json:"beacon_slot_number"`
	BeaconConfig     beacon.Eth2Config `json:"beacon_config"`

	// Network details
	NetworkDetails *rpstate.NetworkDetails `json:"network_details"`

	// Node details
	NodeDetails []rpstate.NativeNodeDetails `json:"node_details"`
	// NodeDetailsByAddress is an index over NodeDetails and is ignored when marshaling to JSON
	// it is rebuilt when unmarshaling from JSON.
	NodeDetailsByAddress map[common.Address]*rpstate.NativeNodeDetails `json:"-"`

	// Minipool details
	MinipoolDetails []rpstate.NativeMinipoolDetails `json:"minipool_details"`

	// Stores validator details from all megapools
	MegapoolValidatorGlobalIndex []megapool.ValidatorInfoFromGlobalIndex `json:"megapool_validator_global_index"`

	// Map megapool addresses to the pubkeys of its validators
	MegapoolToPubkeysMap map[common.Address][]types.ValidatorPubkey `json:"-"`

	MegapoolDetails map[common.Address]rpstate.NativeMegapoolDetails `json:"megapool_details"`

	// These next two fields are indexes over MinipoolDetails and are ignored when marshaling to JSON
	// they are rebuilt when unmarshaling from JSON.
	MinipoolDetailsByAddress map[common.Address]*rpstate.NativeMinipoolDetails   `json:"-"`
	MinipoolDetailsByNode    map[common.Address][]*rpstate.NativeMinipoolDetails `json:"-"`

	// Validator details
	// NetworkState was updated to support megapools, so the old json tag "validator_details" is needed to decode rp-network-state-mainnet-20.json.gz
	MinipoolValidatorDetails ValidatorDetailsMap `json:"validator_details"`
	MegapoolValidatorDetails ValidatorDetailsMap `json:"megapool_validator_details"`

	MegapoolValidatorInfo map[types.ValidatorPubkey]*megapool.ValidatorInfoFromGlobalIndex `json:"-"`

	// Oracle DAO details
	OracleDaoMemberDetails []rpstate.OracleDaoMemberDetails `json:"oracle_dao_member_details"`

	// Protocol DAO proposals
	ProtocolDaoProposalDetails []protocol.ProtocolDaoProposalDetails `json:"protocol_dao_proposal_details,omitempty"`
}

func (*NetworkState) CalculateNodeWeights added in v1.11.3

func (s *NetworkState) CalculateNodeWeights() (map[common.Address]*big.Int, *big.Int, error)

Starting in v8, RPL stake is phased out and replaced with weight. scaleByParticipation and allowRplForUnstartedValidators are hard-coded true here, since only v8 cares about weight.

func (*NetworkState) GetMegapoolEligibleBorrowedEth added in v1.19.0

func (s *NetworkState) GetMegapoolEligibleBorrowedEth(node *rpstate.NativeNodeDetails) *big.Int

func (*NetworkState) GetMinipoolEligibleBorrowedEth added in v1.19.0

func (s *NetworkState) GetMinipoolEligibleBorrowedEth(node *rpstate.NativeNodeDetails) *big.Int

func (*NetworkState) GetNodeWeight added in v1.12.0

func (s *NetworkState) GetNodeWeight(eligibleBorrowedEth *big.Int, nodeStake *big.Int) *big.Int

func (*NetworkState) GetStakedRplValueInEthAndPercentOfBorrowedEth added in v1.15.0

func (s *NetworkState) GetStakedRplValueInEthAndPercentOfBorrowedEth(eligibleBorrowedEth *big.Int, nodeStake *big.Int) (*big.Int, *big.Int)

func (NetworkState) MarshalJSON added in v1.15.0

func (s NetworkState) MarshalJSON() ([]byte, error)

func (*NetworkState) UnmarshalJSON added in v1.15.0

func (s *NetworkState) UnmarshalJSON(data []byte) error

type NetworkStateManager

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

func NewNetworkStateManager

func NewNetworkStateManager(
	rp *rocketpool.RocketPool,
	contracts config.StateManagerContracts,
	bc beacon.Client,
	log *log.ColorLogger,
) *NetworkStateManager

Create a new manager for the network state

func (*NetworkStateManager) GetHeadState

func (m *NetworkStateManager) GetHeadState() (*NetworkState, error)

Get the state of the network using the latest Execution layer block

func (*NetworkStateManager) GetHeadStateForNode

func (m *NetworkStateManager) GetHeadStateForNode(nodeAddress common.Address) (*NetworkState, error)

Get the state of the network for a single node using the latest Execution layer block, along with the total effective RPL stake for the network

func (*NetworkStateManager) GetLatestBeaconBlock

func (m *NetworkStateManager) GetLatestBeaconBlock() (beacon.BeaconBlock, error)

Gets the latest valid block

func (*NetworkStateManager) GetLatestFinalizedBeaconBlock

func (m *NetworkStateManager) GetLatestFinalizedBeaconBlock() (beacon.BeaconBlock, error)

Gets the latest valid finalized block

func (*NetworkStateManager) GetStateForSlot

func (m *NetworkStateManager) GetStateForSlot(slotNumber uint64) (*NetworkState, error)

Get the state of the network at the provided Beacon slot

type NetworkStateProvider added in v1.20.4

type NetworkStateProvider interface {
	GetHeadState() (*NetworkState, error)
	GetHeadStateForNode(nodeAddress common.Address) (*NetworkState, error)
	GetStateForSlot(slotNumber uint64) (*NetworkState, error)
	GetLatestBeaconBlock() (beacon.BeaconBlock, error)
	GetLatestFinalizedBeaconBlock() (beacon.BeaconBlock, error)
}

NetworkStateProvider abstracts the retrieval of network state snapshots NetworkStateManager satisfies this interface using live EC/CC connections StaticNetworkStateProvider satisfies it using a pre-loaded NetworkState

type StaticBeaconClient added in v1.20.4

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

StaticBeaconClient serves consensus-layer reads from a pre-loaded NetworkState snapshot. Anything not modelled in the snapshot (attestations, committees, sync duties, BLS domain data, arbitrary SSZ state or block data) returns ErrStaticMode.

func NewStaticBeaconClient added in v1.20.4

func NewStaticBeaconClient(ns *NetworkState) *StaticBeaconClient

NewStaticBeaconClient wires the given NetworkState into a static beacon.Client implementation.

func (*StaticBeaconClient) ChangeWithdrawalCredentials added in v1.20.4

func (c *StaticBeaconClient) ChangeWithdrawalCredentials(_ string, _ types.ValidatorPubkey, _ common.Address, _ types.ValidatorSignature) error

func (*StaticBeaconClient) Close added in v1.20.4

func (c *StaticBeaconClient) Close() error

func (*StaticBeaconClient) ExitValidator added in v1.20.4

func (c *StaticBeaconClient) ExitValidator(_ string, _ uint64, _ types.ValidatorSignature) error

func (*StaticBeaconClient) GetAllValidators added in v1.20.4

func (c *StaticBeaconClient) GetAllValidators() ([]beacon.ValidatorStatus, error)

func (*StaticBeaconClient) GetAttestations added in v1.20.4

func (c *StaticBeaconClient) GetAttestations(_ string) ([]beacon.AttestationInfo, bool, error)

func (*StaticBeaconClient) GetBeaconBlock added in v1.20.4

func (c *StaticBeaconClient) GetBeaconBlock(blockId string) (beacon.BeaconBlock, bool, error)

GetBeaconBlock honours the symbolic "head" / "finalized" / "genesis" identifiers and any numeric slot equal to the snapshot's slot. Anything else returns ErrStaticMode.

func (*StaticBeaconClient) GetBeaconBlockHeader added in v1.20.4

func (c *StaticBeaconClient) GetBeaconBlockHeader(blockId string) (beacon.BeaconBlockHeader, bool, error)

func (*StaticBeaconClient) GetBeaconBlockSSZ added in v1.20.4

func (c *StaticBeaconClient) GetBeaconBlockSSZ(_ uint64) (*beacon.BeaconBlockSSZ, bool, error)

func (*StaticBeaconClient) GetBeaconHead added in v1.20.4

func (c *StaticBeaconClient) GetBeaconHead() (beacon.BeaconHead, error)

GetBeaconHead is synthesised from the snapshot's slot. The finalized and justified epochs are taken to be the epoch of the snapshot slot itself since a snapshot, by definition, represents a settled view of the chain.

func (*StaticBeaconClient) GetBeaconStateSSZ added in v1.20.4

func (c *StaticBeaconClient) GetBeaconStateSSZ(_ uint64) (*beacon.BeaconStateSSZ, error)

func (*StaticBeaconClient) GetClientType added in v1.20.4

func (c *StaticBeaconClient) GetClientType() (beacon.BeaconClientType, error)

func (*StaticBeaconClient) GetCommitteesForEpoch added in v1.20.4

func (c *StaticBeaconClient) GetCommitteesForEpoch(_ *uint64) (beacon.Committees, error)

func (*StaticBeaconClient) GetDomainData added in v1.20.4

func (c *StaticBeaconClient) GetDomainData(_ []byte, _ uint64, _ bool) ([]byte, error)

func (*StaticBeaconClient) GetEth1DataForEth2Block added in v1.20.4

func (c *StaticBeaconClient) GetEth1DataForEth2Block(_ string) (beacon.Eth1Data, bool, error)

func (*StaticBeaconClient) GetEth2Config added in v1.20.4

func (c *StaticBeaconClient) GetEth2Config() (beacon.Eth2Config, error)

func (*StaticBeaconClient) GetEth2DepositContract added in v1.20.4

func (c *StaticBeaconClient) GetEth2DepositContract() (beacon.Eth2DepositContract, error)

func (*StaticBeaconClient) GetSyncStatus added in v1.20.4

func (c *StaticBeaconClient) GetSyncStatus() (beacon.SyncStatus, error)

GetSyncStatus always reports "fully synced" since the snapshot is a single point in time by definition.

func (*StaticBeaconClient) GetValidatorBalances added in v1.20.4

func (c *StaticBeaconClient) GetValidatorBalances(indices []string, _ *beacon.ValidatorStatusOptions) (map[string]*big.Int, error)

func (*StaticBeaconClient) GetValidatorBalancesSafe added in v1.20.4

func (c *StaticBeaconClient) GetValidatorBalancesSafe(indices []string, opts *beacon.ValidatorStatusOptions) (map[string]*big.Int, error)

func (*StaticBeaconClient) GetValidatorIndex added in v1.20.4

func (c *StaticBeaconClient) GetValidatorIndex(pubkey types.ValidatorPubkey) (string, error)

func (*StaticBeaconClient) GetValidatorProposerDuties added in v1.20.4

func (c *StaticBeaconClient) GetValidatorProposerDuties(_ []string, _ uint64) (map[string]uint64, error)

func (*StaticBeaconClient) GetValidatorStatus added in v1.20.4

func (*StaticBeaconClient) GetValidatorStatusByIndex added in v1.20.4

func (c *StaticBeaconClient) GetValidatorStatusByIndex(index string, _ *beacon.ValidatorStatusOptions) (beacon.ValidatorStatus, error)

func (*StaticBeaconClient) GetValidatorStatuses added in v1.20.4

func (*StaticBeaconClient) GetValidatorSyncDuties added in v1.20.4

func (c *StaticBeaconClient) GetValidatorSyncDuties(_ []string, _ uint64) (map[string]bool, error)

type StaticExecutionClient added in v1.20.4

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

StaticExecutionClient serves execution-layer reads from a pre-loaded NetworkState snapshot. Read methods that can be answered from the snapshot return synthetic values; anything that would require a live eth_call (contract reads, transaction submission, receipts, logs, …) returns ErrStaticMode so that callers fail loudly instead of silently stalling on a non-existent client.

func NewStaticExecutionClient added in v1.20.4

func NewStaticExecutionClient(ns *NetworkState, chainID *big.Int) *StaticExecutionClient

NewStaticExecutionClient wires the given NetworkState + chain ID into a static ExecutionClient implementation.

func (*StaticExecutionClient) BalanceAt added in v1.20.4

func (c *StaticExecutionClient) BalanceAt(_ context.Context, _ common.Address, _ *big.Int) (*big.Int, error)

func (*StaticExecutionClient) BlockNumber added in v1.20.4

func (c *StaticExecutionClient) BlockNumber(_ context.Context) (uint64, error)

func (*StaticExecutionClient) CallContract added in v1.20.4

func (c *StaticExecutionClient) CallContract(_ context.Context, _ ethereum.CallMsg, _ *big.Int) ([]byte, error)

func (*StaticExecutionClient) ChainID added in v1.20.4

func (c *StaticExecutionClient) ChainID(_ context.Context) (*big.Int, error)

func (*StaticExecutionClient) CodeAt added in v1.20.4

func (c *StaticExecutionClient) CodeAt(_ context.Context, _ common.Address, _ *big.Int) ([]byte, error)

CodeAt returns a single placeholder byte for any address so that bind.go's "no code at address" detection passes. Real bytecode reads cannot be answered from the snapshot.

func (*StaticExecutionClient) EstimateGas added in v1.20.4

func (*StaticExecutionClient) FilterLogs added in v1.20.4

func (*StaticExecutionClient) HeaderByHash added in v1.20.4

func (c *StaticExecutionClient) HeaderByHash(_ context.Context, _ common.Hash) (*types.Header, error)

func (*StaticExecutionClient) HeaderByNumber added in v1.20.4

func (c *StaticExecutionClient) HeaderByNumber(_ context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber synthesizes a minimal header for the snapshot's EL block. Any other block number returns ErrStaticMode since the snapshot only covers a single point in time.

func (*StaticExecutionClient) LatestBlockTime added in v1.20.4

func (c *StaticExecutionClient) LatestBlockTime(_ context.Context) (time.Time, error)

func (*StaticExecutionClient) NetworkID added in v1.20.4

func (c *StaticExecutionClient) NetworkID(_ context.Context) (*big.Int, error)

NetworkID mirrors ChainID and exists so that the static client can be used in places (like checkEcStatus) where the underlying ethclient.Client's NetworkID method is invoked directly.

func (*StaticExecutionClient) NonceAt added in v1.20.4

func (*StaticExecutionClient) PendingCodeAt added in v1.20.4

func (c *StaticExecutionClient) PendingCodeAt(_ context.Context, _ common.Address) ([]byte, error)

func (*StaticExecutionClient) PendingNonceAt added in v1.20.4

func (c *StaticExecutionClient) PendingNonceAt(_ context.Context, _ common.Address) (uint64, error)

func (*StaticExecutionClient) SendTransaction added in v1.20.4

func (c *StaticExecutionClient) SendTransaction(_ context.Context, _ *types.Transaction) error

func (*StaticExecutionClient) SubscribeFilterLogs added in v1.20.4

func (c *StaticExecutionClient) SubscribeFilterLogs(_ context.Context, _ ethereum.FilterQuery, _ chan<- types.Log) (ethereum.Subscription, error)

func (*StaticExecutionClient) SuggestGasPrice added in v1.20.4

func (c *StaticExecutionClient) SuggestGasPrice(_ context.Context) (*big.Int, error)

func (*StaticExecutionClient) SuggestGasTipCap added in v1.20.4

func (c *StaticExecutionClient) SuggestGasTipCap(_ context.Context) (*big.Int, error)

func (*StaticExecutionClient) SyncProgress added in v1.20.4

SyncProgress returns nil to signal that the client is fully synced. The snapshot is, by definition, a single fixed point, so "not syncing" is the correct answer.

func (*StaticExecutionClient) TransactionByHash added in v1.20.4

func (c *StaticExecutionClient) TransactionByHash(_ context.Context, _ common.Hash) (*types.Transaction, bool, error)

func (*StaticExecutionClient) TransactionReceipt added in v1.20.4

func (c *StaticExecutionClient) TransactionReceipt(_ context.Context, _ common.Hash) (*types.Receipt, error)

type StaticNetworkStateProvider added in v1.20.4

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

StaticNetworkStateProvider serves a pre-loaded NetworkState without any EC/CC connections. Useful for deterministic tests driven by previously serialized state snapshots

func NewStaticNetworkStateProvider added in v1.20.4

func NewStaticNetworkStateProvider(ns *NetworkState) *StaticNetworkStateProvider

func NewStaticNetworkStateProviderFromFile added in v1.20.4

func NewStaticNetworkStateProviderFromFile(path string) (*StaticNetworkStateProvider, error)

NewStaticNetworkStateProviderFromFile loads a NetworkState from a JSON file. If the path ends in ".gz", the file is transparently decompressed with gzip.

func NewStaticNetworkStateProviderFromJSON added in v1.20.4

func NewStaticNetworkStateProviderFromJSON(r io.Reader) (*StaticNetworkStateProvider, error)

func (*StaticNetworkStateProvider) GetHeadState added in v1.20.4

func (p *StaticNetworkStateProvider) GetHeadState() (*NetworkState, error)

func (*StaticNetworkStateProvider) GetHeadStateForNode added in v1.20.4

func (p *StaticNetworkStateProvider) GetHeadStateForNode(_ common.Address) (*NetworkState, error)

func (*StaticNetworkStateProvider) GetLatestBeaconBlock added in v1.20.4

func (p *StaticNetworkStateProvider) GetLatestBeaconBlock() (beacon.BeaconBlock, error)

func (*StaticNetworkStateProvider) GetLatestFinalizedBeaconBlock added in v1.20.4

func (p *StaticNetworkStateProvider) GetLatestFinalizedBeaconBlock() (beacon.BeaconBlock, error)

func (*StaticNetworkStateProvider) GetStateForSlot added in v1.20.4

func (p *StaticNetworkStateProvider) GetStateForSlot(_ uint64) (*NetworkState, error)

type ValidatorDetailsMap added in v1.15.0

type ValidatorDetailsMap map[types.ValidatorPubkey]beacon.ValidatorStatus

func (ValidatorDetailsMap) MarshalJSON added in v1.15.0

func (vdm ValidatorDetailsMap) MarshalJSON() ([]byte, error)

func (*ValidatorDetailsMap) UnmarshalJSON added in v1.15.0

func (vdm *ValidatorDetailsMap) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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