swcommon

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The size of the interval to use, in blocks, when scanning blocks for deposit events
	// Set to 1/10th of 1 week, assuming 12 seconds per block
	IntervalSize uint64 = 5040

	// The number of blocks to rewind from the chain head when starting a deposit event scan
	// Set to 1 week, assuming 12 seconds per block
	DepositEventLookbackLimit uint64 = 50400
)
View Source
const (
	// Stakewise validators deposit a full 32 ETH
	StakewiseDepositAmount uint64 = 32e9
)

Variables

This section is empty.

Functions

func GenerateDepositData added in v1.2.0

func GenerateDepositData(logger *slog.Logger, resources *swconfig.MergedResources, keys []*eth2types.BLSPrivateKey) ([]beacon.ExtendedDepositData, error)

Generates deposit data for the provided keys

func GetGenesisDepositDomain added in v1.2.0

func GetGenesisDepositDomain(genesisForkVersion []byte) ([]byte, error)

Calculates the deposit domain for Beacon deposits

func ValidateDepositInfo added in v1.2.0

func ValidateDepositInfo(logger *slog.Logger, depositDomain []byte, depositAmount uint64, pubkey []byte, withdrawalCredentials []byte, signature []byte) error

Validates the signature for deposit data

Types

type AvailableKey added in v1.2.0

type AvailableKey struct {
	// The pubkey
	PublicKey beacon.ValidatorPubkey `json:"pubkey"`

	// The private key - not serialized for obvious reasons
	PrivateKey *eth2types.BLSPrivateKey `json:"-"`

	// Flag indicating whether or not a deposit event scan (starting with the lookback limit) has been performed for this key
	HasLookbackScanned bool `json:"hasLookbackScanned"`

	// If this pubkey was used already in a previous deposit attempt, this is the Beacon deposit contract's deposit root during that attempt.
	// It's used to compare against the current deposit root to determine if the deposit was unsuccessful and the key can be reused.
	LastDepositRoot common.Hash `json:"lastDepositRoot"`
}

Info about a key that is available for use in a deposit

type AvailableKeyManager added in v1.2.0

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

AvailableKeyManager manages the keys that have been generated but not yet used for deposits

func NewAvailableKeyManager added in v1.2.0

func NewAvailableKeyManager(sp IStakeWiseServiceProvider) (*AvailableKeyManager, error)

Creates a new manager

func (*AvailableKeyManager) AddNewKey added in v1.2.0

func (m *AvailableKeyManager) AddNewKey(key *eth2types.BLSPrivateKey) error

Add a new key to the list of available keys

func (*AvailableKeyManager) GetAvailableKeys added in v1.2.0

func (m *AvailableKeyManager) GetAvailableKeys(
	ctx context.Context,
	logger *slog.Logger,
	beaconDepositRoot common.Hash,
	currentBlock uint64,
	options GetAvailableKeyOptions,
) (
	eligibleKeys []*AvailableKey,
	ineligibleKeys map[*AvailableKey]IneligibleReason,
	err error,
)

Get the keys that can be used for new deposits from the list of available keys. As a side-effect this refreshes the backing list by filtering out any that have already been used in a deposit and saves it to disk.

func (*AvailableKeyManager) HasKeyCandidates added in v1.2.0

func (m *AvailableKeyManager) HasKeyCandidates() bool

Check if there are any candidate keys ready for validation and potential usage

func (*AvailableKeyManager) HasLoadedKeys added in v1.2.0

func (m *AvailableKeyManager) HasLoadedKeys() bool

Check if the private keys have been loaded yet

func (*AvailableKeyManager) LoadPrivateKeys added in v1.2.0

func (m *AvailableKeyManager) LoadPrivateKeys(logger *slog.Logger)

Regenerate the private key for all available keys.

func (*AvailableKeyManager) Reload added in v1.2.0

func (m *AvailableKeyManager) Reload() error

Reload the available keys from disk

func (*AvailableKeyManager) RequiresLookbackScan added in v1.2.0

func (m *AvailableKeyManager) RequiresLookbackScan(currentBlock uint64) bool

Check if any of the keys in the list require a lookback scan

func (*AvailableKeyManager) SetLastDepositRoot added in v1.2.0

func (m *AvailableKeyManager) SetLastDepositRoot(keys []*AvailableKey, lastDepositRoot common.Hash) error

Set the last deposit root for a list of keys, indicating they will be used in a new deposit

type DepositDataManager

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

DEPRECATED: This was only necessary for StakeWise v1 support and now just creates a blank file. Once StakeWise no longer needs the file at all, this can be removed.

func NewDepositDataManager

func NewDepositDataManager(sp IStakeWiseServiceProvider) (*DepositDataManager, error)

Creates a new manager

type GetAvailableKeyOptions added in v1.2.0

type GetAvailableKeyOptions struct {
	// Skip the sync check for the Beacon and Execution clients (typically used when you already know they are synced)
	SkipSyncCheck bool

	// If false, this starts the deposit event scan from the last block that was scanned.
	// This is the default behavior, and much faster than scanning the entire history - useful if you've already scanned the logs before.
	// If true, this will start the scan at DepositEventLookbackLimit blocks instead.
	// Set this if you have a new key that hasn't had its history checked yet.
	DoLookbackScan bool
}

Options for customizing the behavior of GetAvailableKeys

type IAvailableKeyManagerProvider added in v1.2.0

type IAvailableKeyManagerProvider interface {
	GetAvailableKeyManager() *AvailableKeyManager
}

Provides the manager for keys that can be used for new deposits

type IBeaconDepositContractProvider added in v1.2.0

type IBeaconDepositContractProvider interface {
	// Gets the Constellation manager
	GetBeaconDepositContract() *swcontracts.BeaconDepositContract
}

Provides the Beacon deposit contract

type IDepositDataManagerProvider added in v1.1.0

type IDepositDataManagerProvider interface {
	// Gets the deposit data manager
	GetDepositDataManager() *DepositDataManager
}

Provides the deposit data manager

type IStakeWiseConfigProvider added in v1.1.0

type IStakeWiseConfigProvider interface {
	// Gets the StakeWise config
	GetConfig() *swconfig.StakeWiseConfig

	// Gets the StakeWise resources
	GetResources() *swconfig.MergedResources
}

Provides the StakeWise module config and resources

type IStakeWiseRequirementsProvider added in v1.1.0

type IStakeWiseRequirementsProvider interface {
	RequireStakewiseWalletReady(ctx context.Context, status wallet.WalletStatus) error
	WaitForStakewiseWallet(ctx context.Context) error
}

Provides requirements for the StakeWise daemon

type IStakeWiseServiceProvider added in v1.1.0

func NewStakeWiseServiceProvider added in v1.0.0

func NewStakeWiseServiceProvider(sp services.IModuleServiceProvider, settingsList []*swconfig.StakeWiseSettings) (IStakeWiseServiceProvider, error)

Create a new service provider with Stakewise daemon-specific features

func NewStakeWiseServiceProviderFromCustomServices added in v1.0.0

func NewStakeWiseServiceProviderFromCustomServices(sp services.IModuleServiceProvider, cfg *swconfig.StakeWiseConfig, resources *swconfig.MergedResources) (IStakeWiseServiceProvider, error)

Create a new service provider with Stakewise daemon-specific features, using custom services instead of loading them from the module service provider.

type IStakeWiseWalletProvider added in v1.1.0

type IStakeWiseWalletProvider interface {
	// Gets the wallet
	GetWallet() *Wallet
}

Provides the StakeWise wallet

type IneligibleReason added in v1.2.0

type IneligibleReason int

A reason why a key is ineligible for use in a deposit

const (
	// The key is ineligible because it doesn't have a private key
	IneligibleReason_NoPrivateKey IneligibleReason = iota

	// The key is ineligible because it hasn't been lookback scanned yet
	IneligibleReason_LookbackScanRequired

	// The key is ineligible because it has already been assigned an index on Beacon
	IneligibleReason_OnBeacon

	// The key is ineligible because it has already been used in a deposit contract event
	IneligibleReason_HasDepositEvent

	// The key is ineligible because it has already been used in a deposit contract event with the same deposit root
	IneligibleReason_AlreadyUsedDepositRoot
)

type Wallet

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

Wallet manager for the Stakewise daemon

func NewWallet

func NewWallet(sp IStakeWiseServiceProvider) (*Wallet, error)

Create a new wallet

func (*Wallet) CheckIfStakewiseWalletExists

func (w *Wallet) CheckIfStakewiseWalletExists() (bool, error)

Check if the Stakewise wallet and password files exist

func (*Wallet) DerivePubKeys

func (w *Wallet) DerivePubKeys(privateKeys []*eth2types.BLSPrivateKey) ([]beacon.ValidatorPubkey, error)

Get the private validator key with the corresponding pubkey

func (*Wallet) GenerateNewValidatorKey

func (w *Wallet) GenerateNewValidatorKey() (*eth2types.BLSPrivateKey, error)

Generate a new validator key and save it

func (*Wallet) GetAllPrivateKeys

func (w *Wallet) GetAllPrivateKeys() ([]*eth2types.BLSPrivateKey, error)

Gets all of the validator private keys that are stored in the Stakewise keystore folder

func (*Wallet) GetPrivateKeyForPubkey

func (w *Wallet) GetPrivateKeyForPubkey(pubkey beacon.ValidatorPubkey) (*eth2types.BLSPrivateKey, error)

Get the private validator key with the corresponding pubkey

func (*Wallet) RecoverValidatorKeys added in v1.2.0

func (w *Wallet) RecoverValidatorKeys(
	keysToSearchFor []beacon.ValidatorPubkey,
	startIndex uint64,
	count uint64,
	searchLimit uint64,
) (
	recoveredKeys []swapi.RecoveredKey,
	searchEnd uint64,
	err error,
)

func (*Wallet) Reload added in v1.0.0

func (w *Wallet) Reload() error

Reload the wallet data from disk

func (*Wallet) SaveStakewiseWallet

func (w *Wallet) SaveStakewiseWallet(ethKey []byte, password string) error

Saves the Stakewise wallet and password files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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