Documentation
¶
Overview ¶
Package consensus implements the reputation scoring system for ATLYS
Package consensus implements the validator functionality for ATLYS ¶
Package consensus implements the voting mechanism for ATLYS
Index ¶
- type EpochManager
- type ReputationConfig
- type ReputationScorer
- func (rs *ReputationScorer) GetEpochStats() map[string]interface{}
- func (rs *ReputationScorer) GetHistory(address types.Address) (*ScoreHistory, error)
- func (rs *ReputationScorer) GetScore(address types.Address) (uint32, error)
- func (rs *ReputationScorer) RecoverScore(address types.Address) error
- func (rs *ReputationScorer) RegisterValidator(address types.Address, stake uint64) error
- func (rs *ReputationScorer) SlashValidator(address types.Address, reason string, blockHeight uint64) error
- func (rs *ReputationScorer) StartNewEpoch()
- func (rs *ReputationScorer) UpdateScore(address types.Address, success bool, metrics *ValidationMetrics) error
- type ScoreHistory
- type SlashEvent
- type TimeoutConfig
- type ValidationMetrics
- type Validator
- func (v *Validator) DelegateStake(amount uint64) error
- func (v *Validator) GetAddress() types.Address
- func (v *Validator) GetPublicKey() []byte
- func (v *Validator) GetReputation() uint32
- func (v *Validator) GetStatus() map[string]interface{}
- func (v *Validator) ProposeBlock(transactions []types.Transaction) (*core.Block, error)
- func (v *Validator) Start(ctx context.Context) error
- func (v *Validator) Stop() error
- func (v *Validator) UndelegateStake(amount uint64) error
- func (v *Validator) UpdateReputation(delta int32) error
- func (v *Validator) ValidateBlock(block *core.Block) error
- type ValidatorConfig
- type ValidatorScore
- type ValidatorStats
- type ValidatorStatus
- type Vote
- type VoteOption
- type VoteSet
- type VoteType
- type VotingConfig
- type VotingManager
- func (vm *VotingManager) AddVote(vote *Vote) error
- func (vm *VotingManager) CreateVote(voteType VoteType, height uint64, round uint32, blockHash types.Hash, ...) (*Vote, error)
- func (vm *VotingManager) GetVoteSet(height uint64, round uint32, voteType VoteType) (*VoteSet, error)
- func (vm *VotingManager) GetVotingState() map[string]interface{}
- func (vm *VotingManager) StartVoting(ctx context.Context, height uint64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EpochManager ¶
type EpochManager struct {
// contains filtered or unexported fields
}
EpochManager handles epoch-based score calculations
type ReputationConfig ¶
type ReputationConfig struct {
InitialScore uint32
MinScore uint32
MaxScore uint32
DecayRate float64
DecayInterval time.Duration
UpdateInterval time.Duration
BonusMultiplier float64
PenaltyMultiplier float64
SlashingThreshold uint32
RecoveryRate float64
HistorySize uint32
ConsensusWeight float64
StakeWeight float64
UptimeWeight float64
}
ReputationConfig contains configuration parameters for the reputation system
type ReputationScorer ¶
type ReputationScorer struct {
// contains filtered or unexported fields
}
ReputationScorer manages validator reputation scores
func NewReputationScorer ¶
func NewReputationScorer(config *ReputationConfig) *ReputationScorer
NewReputationScorer creates a new instance of ReputationScorer
func (*ReputationScorer) GetEpochStats ¶
func (rs *ReputationScorer) GetEpochStats() map[string]interface{}
GetEpochStats returns reputation statistics for the current epoch
func (*ReputationScorer) GetHistory ¶
func (rs *ReputationScorer) GetHistory(address types.Address) (*ScoreHistory, error)
GetHistory returns a validator's reputation history
func (*ReputationScorer) GetScore ¶
func (rs *ReputationScorer) GetScore(address types.Address) (uint32, error)
GetScore returns a validator's current reputation score
func (*ReputationScorer) RecoverScore ¶
func (rs *ReputationScorer) RecoverScore(address types.Address) error
RecoverScore allows gradual score recovery after penalties
func (*ReputationScorer) RegisterValidator ¶
func (rs *ReputationScorer) RegisterValidator(address types.Address, stake uint64) error
RegisterValidator initializes reputation tracking for a new validator
func (*ReputationScorer) SlashValidator ¶
func (rs *ReputationScorer) SlashValidator(address types.Address, reason string, blockHeight uint64) error
SlashValidator applies a slashing penalty to a validator
func (*ReputationScorer) StartNewEpoch ¶
func (rs *ReputationScorer) StartNewEpoch()
func (*ReputationScorer) UpdateScore ¶
func (rs *ReputationScorer) UpdateScore(address types.Address, success bool, metrics *ValidationMetrics) error
UpdateScore updates a validator's reputation score based on performance
type ScoreHistory ¶
type ScoreHistory struct {
Scores []uint32 // Historical scores
Updates []time.Time // Update timestamps
SlashEvents []SlashEvent
MaxEntries uint32
}
ScoreHistory tracks historical reputation data
type SlashEvent ¶
SlashEvent records details of a slashing event
type TimeoutConfig ¶
type TimeoutConfig struct {
ProposeTimeout time.Duration
PrevoteTimeout time.Duration
PrecommitTimeout time.Duration
CommitTimeout time.Duration
}
TimeoutConfig contains timeout parameters
type ValidationMetrics ¶
type ValidationMetrics struct {
ConsensusParticipation float64 // 0.0 to 1.0
Uptime float64 // 0.0 to 1.0
ResponseTime time.Duration
ProposedBlocks uint64
ValidatedBlocks uint64
}
ValidationMetrics contains metrics used for score calculation
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator represents a validator node in the ATLYS network
func NewValidator ¶
func NewValidator(config *ValidatorConfig) (*Validator, error)
NewValidator creates a new validator instance
func (*Validator) DelegateStake ¶
DelegateStake adds stake to the validator
func (*Validator) GetAddress ¶
GetAddress returns the validator's address
func (*Validator) GetPublicKey ¶
GetPublicKey returns the validator's public key
func (*Validator) GetReputation ¶
GetReputation returns the current reputation score
func (*Validator) ProposeBlock ¶
ProposeBlock creates a new block proposal
func (*Validator) UndelegateStake ¶
UndelegateStake removes stake from the validator
func (*Validator) UpdateReputation ¶
UpdateReputation updates the validator's reputation score
type ValidatorConfig ¶
type ValidatorConfig struct {
MinStake uint64
MaxStake uint64
UnbondingPeriod time.Duration
SlashingThreshold uint32
ReputationDecay float64
JailDuration time.Duration
MaxMissedBlocks uint32
BlockTimeout time.Duration
}
ValidatorConfig contains configuration parameters for the validator
type ValidatorScore ¶
type ValidatorScore struct {
CurrentScore uint32 // Current reputation score (0-100)
BaseScore uint32 // Base score without penalties
PenaltyScore uint32 // Accumulated penalties
LastUpdate time.Time // Last score update timestamp
ConsecutiveHits uint32 // Consecutive successful validations
StakeWeight float64 // Weight based on staked amount
}
ValidatorScore represents a validator's current reputation metrics
type ValidatorStats ¶
type ValidatorStats struct {
// contains filtered or unexported fields
}
ValidatorStats tracks validator performance metrics
type ValidatorStatus ¶
type ValidatorStatus int
ValidatorStatus represents the current state of a validator
const ( StatusInactive ValidatorStatus = iota StatusActive StatusJailing StatusJailed StatusSlashed )
type Vote ¶
type Vote struct {
Type VoteType
Height uint64
Round uint32
BlockHash types.Hash
Timestamp time.Time
ValidatorID types.Address
Signature []byte
Option VoteOption
}
Vote represents a validator's vote
type VoteOption ¶
type VoteOption int
VoteOption represents voting options
const ( VoteNull VoteOption = iota VoteYes VoteNo VoteAbstain )
type VoteSet ¶
type VoteSet struct {
// contains filtered or unexported fields
}
VoteSet tracks votes for a specific height and round
func (*VoteSet) HasTwoThirdsMajority ¶
type VotingConfig ¶
type VotingConfig struct {
VotingPeriod time.Duration
ProposalTimeout time.Duration
PrevoteTimeout time.Duration
PrecommitTimeout time.Duration
MinVotingPower uint64
MaxRounds uint32
RequiredMajority float64
}
VotingConfig contains configuration for voting
type VotingManager ¶
type VotingManager struct {
// contains filtered or unexported fields
}
VotingManager handles the voting process
func NewVotingManager ¶
func NewVotingManager(validators *ValidatorSet, config *VotingConfig) *VotingManager
NewVotingManager creates a new instance of VotingManager
func (*VotingManager) AddVote ¶
func (vm *VotingManager) AddVote(vote *Vote) error
AddVote adds a vote to the current vote set
func (*VotingManager) CreateVote ¶
func (vm *VotingManager) CreateVote( voteType VoteType, height uint64, round uint32, blockHash types.Hash, option VoteOption, validator types.Address, ) (*Vote, error)
CreateVote creates a new signed vote
func (*VotingManager) GetVoteSet ¶
func (vm *VotingManager) GetVoteSet(height uint64, round uint32, voteType VoteType) (*VoteSet, error)
GetVoteSet returns the vote set for a specific height and round
func (*VotingManager) GetVotingState ¶
func (vm *VotingManager) GetVotingState() map[string]interface{}
GetVotingState returns the current voting state
func (*VotingManager) StartVoting ¶
func (vm *VotingManager) StartVoting(ctx context.Context, height uint64) error
StartVoting begins the voting process for a new height