mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
130 lines
3.5 KiB
Go
130 lines
3.5 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package state
|
|
|
|
import (
|
|
"bytes"
|
|
"time"
|
|
|
|
"github.com/google/btree"
|
|
|
|
"github.com/luxfi/crypto/bls"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/node/vms/platformvm/txs"
|
|
)
|
|
|
|
// StakerIterator is an iterator for Staker objects.
|
|
// Iterators should be released when they are no longer needed.
|
|
type StakerIterator interface {
|
|
// Next advances the iterator to the next staker.
|
|
// Returns false if there are no more stakers.
|
|
Next() bool
|
|
|
|
// Value returns the current staker.
|
|
// Should only be called after Next() returns true.
|
|
Value() *Staker
|
|
|
|
// Release frees any resources associated with the iterator.
|
|
// Must be called when the iterator is no longer needed.
|
|
Release()
|
|
}
|
|
|
|
var _ btree.LessFunc[*Staker] = (*Staker).Less
|
|
|
|
// Staker contains all information required to represent a validator or
|
|
// delegator in the current and pending validator sets.
|
|
// Invariant: Staker's size is bounded to prevent OOM DoS attacks.
|
|
type Staker struct {
|
|
TxID ids.ID
|
|
NodeID ids.NodeID
|
|
PublicKey *bls.PublicKey
|
|
ChainID ids.ID
|
|
Weight uint64
|
|
StartTime time.Time
|
|
EndTime time.Time
|
|
PotentialReward uint64
|
|
|
|
// NextTime is the next time this staker will be moved from a validator set.
|
|
// If the staker is in the pending validator set, NextTime will equal
|
|
// StartTime. If the staker is in the current validator set, NextTime will
|
|
// equal EndTime.
|
|
NextTime time.Time
|
|
|
|
// Priority specifies how to break ties between stakers with the same
|
|
// NextTime. This ensures that stakers created by the same transaction type
|
|
// are grouped together. The ordering of these groups is documented in
|
|
// [priorities.go] and depends on if the stakers are in the pending or
|
|
// current validator set.
|
|
Priority txs.Priority
|
|
}
|
|
|
|
// A *Staker is considered to be less than another *Staker when:
|
|
//
|
|
// 1. If its NextTime is before the other's.
|
|
// 2. If the NextTimes are the same, the *Staker with the lesser priority is the
|
|
// lesser one.
|
|
// 3. If the priorities are also the same, the one with the lesser txID is
|
|
// lesser.
|
|
func (s *Staker) Less(than *Staker) bool {
|
|
if s.NextTime.Before(than.NextTime) {
|
|
return true
|
|
}
|
|
if than.NextTime.Before(s.NextTime) {
|
|
return false
|
|
}
|
|
|
|
if s.Priority < than.Priority {
|
|
return true
|
|
}
|
|
if than.Priority < s.Priority {
|
|
return false
|
|
}
|
|
|
|
return bytes.Compare(s.TxID[:], than.TxID[:]) == -1
|
|
}
|
|
|
|
func NewCurrentStaker(
|
|
txID ids.ID,
|
|
staker txs.Staker,
|
|
startTime time.Time,
|
|
potentialReward uint64,
|
|
) (*Staker, error) {
|
|
publicKey, _, err := staker.PublicKey()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
endTime := staker.EndTime()
|
|
return &Staker{
|
|
TxID: txID,
|
|
NodeID: staker.NodeID(),
|
|
PublicKey: publicKey,
|
|
ChainID: staker.ChainID(),
|
|
Weight: staker.Weight(),
|
|
StartTime: startTime,
|
|
EndTime: endTime,
|
|
PotentialReward: potentialReward,
|
|
NextTime: endTime,
|
|
Priority: staker.CurrentPriority(),
|
|
}, nil
|
|
}
|
|
|
|
func NewPendingStaker(txID ids.ID, staker txs.ScheduledStaker) (*Staker, error) {
|
|
publicKey, _, err := staker.PublicKey()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
startTime := staker.StartTime()
|
|
return &Staker{
|
|
TxID: txID,
|
|
NodeID: staker.NodeID(),
|
|
PublicKey: publicKey,
|
|
ChainID: staker.ChainID(),
|
|
Weight: staker.Weight(),
|
|
StartTime: startTime,
|
|
EndTime: staker.EndTime(),
|
|
NextTime: startTime,
|
|
Priority: staker.PendingPriority(),
|
|
}, nil
|
|
}
|