rewards

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RewardTypeFee     string = "Fee"
	RewardTypeRent    string = "Rent"
	RewardTypeVoting  string = "Voting"
	RewardTypeStaking string = "Staking"
)
View Source
const PointsSpoolRecordSize = 104

PointsSpoolRecordSize is the binary size of a points spool record. Format: stake_pubkey(32) + vote_pubkey(32) + points_lo(8) + points_hi(8) +

new_credits_observed(8) + stake_lamports(8) + force_credits_update(8) = 104 bytes
View Source
const SpoolRecordSize = 88

SpoolRecordSize is the binary size of a spool record. Format: stake_pubkey(32) + vote_pubkey(32) + stake_lamports(8) +

credits_observed(8) + reward_lamports(8) = 88 bytes

Variables

This section is empty.

Functions

func CalculateNumRewardPartitions

func CalculateNumRewardPartitions(numStakingRewards uint64) uint64

func CalculatePreviousEpochInflationRewards

func CalculatePreviousEpochInflationRewards(epochSchedule *sealevel.SysvarEpochSchedule, inflation *Inflation, prevEpochCapitalization, epoch, prevEpoch uint64, slotsPerYear float64, f *features.Features) uint64

func CalculateRewardPartitionForPubkey

func CalculateRewardPartitionForPubkey(pubkey solana.PublicKey, blockhash [32]byte, numPartitions uint64) uint64

func CleanupPartitionedSpoolFiles

func CleanupPartitionedSpoolFiles(baseDir string, slot uint64, numPartitions uint64)

CleanupPartitionedSpoolFiles removes all partition spool files for a slot.

func CleanupPointsSpoolFile

func CleanupPointsSpoolFile(path string)

CleanupPointsSpoolFile removes a points spool file.

func CleanupTempSpoolFile

func CleanupTempSpoolFile(path string)

CleanupTempSpoolFile removes a temp spool file.

func DistributeStakingRewardsFromSpool

func DistributeStakingRewardsFromSpool(acctsDb *accountsdb.AccountsDb, spoolDir string, spoolSlot uint64, partitionIdx uint64, currentSlot uint64) ([]*accounts.Account, []*accounts.Account, uint64, uint64)

func DistributeVotingRewards

func DistributeVotingRewards(acctsDb *accountsdb.AccountsDb, validatorRewards map[solana.PublicKey]*atomic.Uint64, slot uint64) ([]*accounts.Account, []*accounts.Account, uint64)

func GetInflationNumSlots

func GetInflationNumSlots(epochSchedule *sealevel.SysvarEpochSchedule, epoch uint64, f *features.Features) uint64

func GetInflationStartSlot

func GetInflationStartSlot(f *features.Features) uint64

func IsWithinRewardsPeriod

func IsWithinRewardsPeriod(epoch uint64, slot uint64, epochSchedule *sealevel.SysvarEpochSchedule) bool

func SlotInYearForInflation

func SlotInYearForInflation(epochSchedule *sealevel.SysvarEpochSchedule, slotsPerYear float64, epoch uint64, f *features.Features) float64

Types

type CalculatedStakePoints

type CalculatedStakePoints struct {
	Points                              wide.Uint128
	NewCreditsObserved                  uint64
	ForceCreditsUpdateWithSkippedReward bool
}

type CalculatedStakeRewards

type CalculatedStakeRewards struct {
	StakerRewards      uint64
	VoterRewards       uint64
	VoterPubkey        solana.PublicKey
	NewCreditsObserved uint64
}

func CalculateStakeRewardsForAcct

func CalculateStakeRewardsForAcct(pubkey solana.PublicKey, stakePointsResult *CalculatedStakePoints, delegation *sealevel.Delegation, voteState *sealevel.VoteStateVersions, rewardedEpoch uint64, pointValue PointValue, newRateActivationEpoch *uint64) *CalculatedStakeRewards

type CommissionSplit

type CommissionSplit struct {
	VoterPortion  uint64
	StakerPortion uint64
	IsSplit       bool
}

type Inflation

type Inflation struct {
	Initial        float64
	Terminal       float64
	Taper          float64
	FoundationVal  float64
	FoundationTerm float64
	Unused         float64
}

func (*Inflation) Foundation

func (inflation *Inflation) Foundation(year float64) float64

func (*Inflation) Total

func (inflation *Inflation) Total(year float64) float64

func (*Inflation) UnmarshalWithDecoder

func (inflation *Inflation) UnmarshalWithDecoder(decoder *bin.Decoder) error

func (*Inflation) Validator

func (inflation *Inflation) Validator(year float64) float64

type PartitionReader

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

PartitionReader reads records sequentially from a partition spool file. Uses buffered I/O for efficient sequential reads.

func NewPartitionReader

func NewPartitionReader(baseDir string, slot uint64, partition uint32) (*PartitionReader, error)

NewPartitionReader opens a partition file for sequential reading.

func (*PartitionReader) Close

func (r *PartitionReader) Close() error

Close closes the partition file.

func (*PartitionReader) Next

func (r *PartitionReader) Next() (*SpoolRecord, error)

Next reads the next record. Returns io.EOF when done.

type PartitionedRewardDistributionInfo

type PartitionedRewardDistributionInfo struct {
	TotalStakingRewards          uint64
	FirstStakingRewardSlot       uint64
	NumRewardPartitionsRemaining uint64
	SpoolDir                     string
	SpoolSlot                    uint64
}

func DeterminePartitionedStakingRewardsInfo

func DeterminePartitionedStakingRewardsInfo(epochSchedule *sealevel.SysvarEpochSchedule, inflation *Inflation, prevEpochCapitalization uint64, epoch uint64, prevEpoch uint64, slot uint64, slotsPerYear float64, f *features.Features) *PartitionedRewardDistributionInfo

DeterminePartitionedStakingRewardsInfo calculates the total staking rewards for the epoch.

type PartitionedSpoolWriters

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

PartitionedSpoolWriters manages per-partition spool files. Thread-safe - multiple goroutines can write concurrently. Uses buffered I/O for performance.

func NewPartitionedSpoolWriters

func NewPartitionedSpoolWriters(baseDir string, slot uint64, numPartitions uint64) *PartitionedSpoolWriters

NewPartitionedSpoolWriters creates a new set of per-partition spool writers.

func (*PartitionedSpoolWriters) Close

func (p *PartitionedSpoolWriters) Close() error

Close flushes buffers, syncs, and closes all partition files. Returns the first error encountered.

func (*PartitionedSpoolWriters) Slot

func (p *PartitionedSpoolWriters) Slot() uint64

Slot returns the slot this spool is for.

func (*PartitionedSpoolWriters) SpoolDir

func (p *PartitionedSpoolWriters) SpoolDir() string

SpoolDir returns the base directory for spool files.

func (*PartitionedSpoolWriters) TotalRecords

func (p *PartitionedSpoolWriters) TotalRecords() int

TotalRecords returns the total number of records written across all partitions.

func (*PartitionedSpoolWriters) WriteRecord

func (p *PartitionedSpoolWriters) WriteRecord(rec *SpoolRecord) error

WriteRecord writes a record to the appropriate partition file. Thread-safe - lazily opens partition files as needed.

type PointValue

type PointValue struct {
	Rewards uint64
	Points  wide.Uint128
}

type PointsSpoolReader

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

PointsSpoolReader reads points records sequentially from a points spool file.

func NewPointsSpoolReader

func NewPointsSpoolReader(path string) (*PointsSpoolReader, error)

NewPointsSpoolReader opens a points spool file for sequential reading.

func (*PointsSpoolReader) Close

func (r *PointsSpoolReader) Close() error

Close closes the points spool file.

func (*PointsSpoolReader) Next

Next reads the next record. Returns io.EOF when done.

type PointsSpoolRecord

type PointsSpoolRecord struct {
	StakePubkey                         solana.PublicKey
	VotePubkey                          solana.PublicKey
	Points                              wide.Uint128
	NewCreditsObserved                  uint64
	StakeLamports                       uint64
	ForceCreditsUpdateWithSkippedReward bool
}

PointsSpoolRecord stores intermediate per-stake data from Phase 1 (points calculation) so Phase 2 can compute rewards from sequential file I/O instead of re-scanning AccountsDB. ForceCreditsUpdateWithSkippedReward is fully precomputed in Phase 1 using all three triggers (pcs.ForceCredits, pointValue.Rewards==0, activationEpoch==rewardedEpoch).

type PointsSpoolWriter

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

PointsSpoolWriter writes points records to a single temp file. NOT thread-safe — use with a single-writer goroutine via channel.

func NewPointsSpoolWriter

func NewPointsSpoolWriter(baseDir string, slot uint64) (*PointsSpoolWriter, error)

NewPointsSpoolWriter creates a new points spool writer.

func (*PointsSpoolWriter) Close

func (w *PointsSpoolWriter) Close() error

Close flushes and closes the points spool file. NOTE: No Sync() — points spool is only used in-process and deleted immediately after reading.

func (*PointsSpoolWriter) Count

func (w *PointsSpoolWriter) Count() int

Count returns the number of records written.

func (*PointsSpoolWriter) Path

func (w *PointsSpoolWriter) Path() string

Path returns the points spool file path.

func (*PointsSpoolWriter) WriteRecord

func (w *PointsSpoolWriter) WriteRecord(rec *PointsSpoolRecord) error

WriteRecord writes a record to the points spool.

type SpoolRecord

type SpoolRecord struct {
	StakePubkey     solana.PublicKey
	VotePubkey      solana.PublicKey
	StakeLamports   uint64
	CreditsObserved uint64
	RewardLamports  uint64
	PartitionIndex  uint32 // Only used during calculation, not serialized
}

SpoolRecord represents a single stake reward record.

type StreamingRewardsResult

type StreamingRewardsResult struct {
	SpoolDir         string // Base directory for per-partition spool files
	SpoolSlot        uint64 // Slot for spool file naming
	TotalPoints      wide.Uint128
	ValidatorRewards map[solana.PublicKey]*atomic.Uint64
	NumStakeRewards  uint64
	NumPartitions    uint64
}

StreamingRewardsResult holds the results from streaming rewards calculation.

func CalculateRewardsStreaming

func CalculateRewardsStreaming(
	acctsDb *accountsdb.AccountsDb,
	slot uint64,
	stakeHistory *sealevel.SysvarStakeHistory,
	newWarmupCooldownRateEpoch *uint64,
	voteCache map[solana.PublicKey]*sealevel.VoteStateVersions,
	pointValue PointValue,
	rewardedEpoch uint64,
	blockhash [32]byte,
	slotCtx *sealevel.SlotCtx,
	f *features.Features,
) (*StreamingRewardsResult, error)

CalculateRewardsStreaming performs a streaming calculation of stake rewards. Phase 1: Stream stakes to calculate total points + write points spool (single AccountsDB scan) Phase 2: Replay points spool to compute rewards + write temp spool (sequential file I/O only) Phase 3: Read temp spool, assign partitions, write per-partition spools

type TempSpoolReader

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

TempSpoolReader reads records sequentially from a temp spool file.

func NewTempSpoolReader

func NewTempSpoolReader(path string) (*TempSpoolReader, error)

NewTempSpoolReader opens a temp spool file for sequential reading.

func (*TempSpoolReader) Close

func (r *TempSpoolReader) Close() error

Close closes the temp spool file.

func (*TempSpoolReader) Next

func (r *TempSpoolReader) Next() (*SpoolRecord, error)

Next reads the next record. Returns io.EOF when done.

type TempSpoolWriter

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

TempSpoolWriter writes reward records to a single temp file (no partition separation). Used in the first phase of reward calculation before partition count is known. NOT thread-safe - should be used with a single-writer pattern.

func NewTempSpoolWriter

func NewTempSpoolWriter(baseDir string, slot uint64) (*TempSpoolWriter, error)

NewTempSpoolWriter creates a new temp spool writer.

func (*TempSpoolWriter) Close

func (w *TempSpoolWriter) Close() error

Close flushes and closes the temp spool file. NOTE: No Sync() - temp spool is only used in-process and deleted immediately after reading.

func (*TempSpoolWriter) Count

func (w *TempSpoolWriter) Count() int

Count returns the number of records written.

func (*TempSpoolWriter) Path

func (w *TempSpoolWriter) Path() string

Path returns the temp spool file path.

func (*TempSpoolWriter) WriteRecord

func (w *TempSpoolWriter) WriteRecord(rec *SpoolRecord) error

WriteRecord writes a record to the temp spool.

Jump to

Keyboard shortcuts

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