Documentation
¶
Index ¶
- func NullifyOffenders(queuedValidators safrole.ValidatorsData, offenders []ed25519.PublicKey) safrole.ValidatorsData
- func RandomListOfValidators(t *testing.T) safrole.ValidatorsData
- func RandomTicket(t *testing.T) block.Ticket
- type ActivityStatisticsState
- type CoreStatistics
- type GridMapper
- func (m GridMapper) FindValidatorIndex(key ed25519.PublicKey) (uint16, bool)
- func (m GridMapper) FindValidatorIndexInArchived(key ed25519.PublicKey) (uint16, bool)
- func (m GridMapper) FindValidatorIndexInQueued(key ed25519.PublicKey) (uint16, bool)
- func (m GridMapper) GetAllEpochsNeighborValidators(index uint16) ([]crypto.ValidatorKey, error)
- func (m GridMapper) GetCurrentEpochNeighborValidators(index uint16) ([]crypto.ValidatorKey, error)
- func (m GridMapper) IsNeighbor(key1, key2 ed25519.PublicKey, sameEpoch bool) bool
- type ServiceActivityRecord
- type ServiceStatistics
- type ValidatorKeys
- type ValidatorManager
- func (vm *ValidatorManager) DetermineProxyValidatorIndex(hash crypto.BandersnatchOutputHash) uint32
- func (vm *ValidatorManager) GetNeighbors() ([]crypto.ValidatorKey, error)
- func (vm *ValidatorManager) IsNeighbor(key ed25519.PublicKey) bool
- func (vm *ValidatorManager) IsProxyValidatorFor(hash crypto.BandersnatchOutputHash) bool
- func (vm *ValidatorManager) IsSlotLeader(fallbackKeys crypto.EpochKeys) bool
- type ValidatorService
- type ValidatorServiceMock
- func (v *ValidatorServiceMock) AuditShardRequest(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16) (bundleShard []byte, justification [][]byte, err error)
- func (v *ValidatorServiceMock) SegmentShardRequest(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16, ...) (segmentShards [][]byte, err error)
- func (v *ValidatorServiceMock) SegmentShardRequestJustification(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16, ...) (segmentShards [][]byte, justification [][][]byte, err error)
- func (v *ValidatorServiceMock) ShardDistribution(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16) (bundleShard []byte, segmentShard [][]byte, justification [][]byte, err error)
- func (v *ValidatorServiceMock) StoreAllShards(ctx context.Context, erasureRoot crypto.Hash, bundle [][]byte, ...) error
- type ValidatorState
- type ValidatorStatistics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NullifyOffenders ¶
func NullifyOffenders(queuedValidators safrole.ValidatorsData, offenders []ed25519.PublicKey) safrole.ValidatorsData
Implements equation 59 from the graypaper, i.e Φ(k). If any of the queued validator data matches the offenders list (ψ′), all the keys for that validator are zero'd out.
func RandomListOfValidators ¶
func RandomListOfValidators(t *testing.T) safrole.ValidatorsData
Types ¶
type ActivityStatisticsState ¶
type ActivityStatisticsState struct {
ValidatorsCurrent [common.NumberOfValidators]ValidatorStatistics // Present validator statistics (π_v) - The activity statistics for the validators which are currently being accumulated.
ValidatorsLast [common.NumberOfValidators]ValidatorStatistics // Completed validator statistics (π_l) - The activity statistics for the validators which have completed their work.
Cores [common.TotalNumberOfCores]CoreStatistics // Core statistics (π_c) - The activity statistics for each core.
Services ServiceStatistics // Service statistics (π_s) - The activity statistics for each service.
}
ActivityStatisticsState represents the statistics related to validators.
type CoreStatistics ¶
type CoreStatistics struct {
// DALoad (d) is the amount of bytes placed into either Audits or Segments DA.
// This includes the work-bundle (including all extrinsics and imports) as well as all
// (exported) segments.
DALoad uint32 `jam:"encoding=compact"`
Popularity uint16 `jam:"encoding=compact"` // Popularity (p) is the number of validators which formed super-majority for assurance.
Imports uint16 `jam:"encoding=compact"` // Imports (i) is the number of segments imported from DA made by core for reported work.
Exports uint16 `jam:"encoding=compact"` // Exports (e) is the number of segments exported into DA made by core for reported work.
ExtrinsicSize uint32 `jam:"encoding=compact"` // ExtrinsicSize (x) is the total size of extrinsics used by core for reported work.
ExtrinsicCount uint16 `jam:"encoding=compact"` // ExtrinsicCount (z) is the total number of extrinsics used by core for reported work.
BundleSize uint32 `jam:"encoding=compact"` // BundleSize (b) is the work-bundle size. This is the size of data being placed into Audits DA by the core.
GasUsed uint64 `jam:"encoding=compact"` // GasUsed (g) is the total gas consumed by core for reported work. Includes all refinement and authorizations.
}
type GridMapper ¶
type GridMapper struct {
// contains filtered or unexported fields
}
GridMapper manages the mapping between grid indices and validator information across epochs. It maintains data for three sets of validators: - Current validators: The active set in the current epoch - Archived validators: The set from the previous epoch - Queued validators: The set for the next epoch
The grid structure arranges validators in a square-like grid where validators are considered neighbors if they share the same row or column. This structure is used primarily for block announcements and other network communications.
func NewGridMapper ¶
func NewGridMapper(state ValidatorState) GridMapper
NewGridMapper creates a new mapper instance using the provided validator state. The state must contain information about current, archived, and queued validators.
func (GridMapper) FindValidatorIndex ¶
func (m GridMapper) FindValidatorIndex(key ed25519.PublicKey) (uint16, bool)
FindValidatorIndex searches for a validator's grid index in the current validator set by their Ed25519 public key. Returns the index and true if found, or 0 and false if not found.
func (GridMapper) FindValidatorIndexInArchived ¶
func (m GridMapper) FindValidatorIndexInArchived(key ed25519.PublicKey) (uint16, bool)
FindValidatorIndexInArchived searches for a validator's grid index in the previous epoch's validator set by their Ed25519 public key. Returns the index and true if found, or 0 and false if not found.
func (GridMapper) FindValidatorIndexInQueued ¶
func (m GridMapper) FindValidatorIndexInQueued(key ed25519.PublicKey) (uint16, bool)
FindValidatorIndexInQueued searches for a validator's grid index in the next epoch's validator set by their Ed25519 public key. Returns the index and true if found, or 0 and false if not found.
func (GridMapper) GetAllEpochsNeighborValidators ¶
func (m GridMapper) GetAllEpochsNeighborValidators(index uint16) ([]crypto.ValidatorKey, error)
GetAllEpochsNeighborValidators returns all neighbor validators across epochs for a given index. This includes: - All grid neighbors from the current epoch (same row or column) - The validator with the same index from the previous epoch - The validator with the same index from the next epoch
func (GridMapper) GetCurrentEpochNeighborValidators ¶
func (m GridMapper) GetCurrentEpochNeighborValidators(index uint16) ([]crypto.ValidatorKey, error)
GetCurrentEpochNeighborValidators returns all grid neighbors for a validator within the current epoch. Grid neighbors are validators that share either the same row or column in the grid structure.
func (GridMapper) IsNeighbor ¶
func (m GridMapper) IsNeighbor(key1, key2 ed25519.PublicKey, sameEpoch bool) bool
IsNeighbor determines if two validators are neighbors based on their public keys. Two validators are considered neighbors if either: - They are in the same epoch and share the same row or column in the grid - They are in different epochs but have the same grid index Parameters:
- key1, key2: The Ed25519 public keys of the two validators
- sameEpoch: Whether both validators are from the same epoch
type ServiceActivityRecord ¶
type ServiceActivityRecord struct {
ProvidedCount uint16 `jam:"encoding=compact"` // ProvidedCount (p.0) is the number of preimages provided to this service.
ProvidedSize uint32 `jam:"encoding=compact"` // ProvidedSize (p.1) is the total size of preimages provided to this service.
RefinementCount uint32 `jam:"encoding=compact"` // RefinementCount (r.0) is the number of work-items refined by service for reported work.
RefinementGasUsed uint64 `jam:"encoding=compact"` // RefinementGasUsed (r.1) is the amount of gas used for refinement by service for reported work.
Imports uint32 `jam:"encoding=compact"` // Imports (i) is the number of segments imported from the DL by service for reported work.
Exports uint32 `jam:"encoding=compact"` // Exports (e) is the number of segments exported into the DL by service for reported work.
ExtrinsicSize uint32 `jam:"encoding=compact"` // ExtrinsicSize (x) is the total size of extrinsics used by service for reported work.
ExtrinsicCount uint32 `jam:"encoding=compact"` // ExtrinsicCount (z) is the total number of extrinsics used by service for reported work.
AccumulateCount uint32 `jam:"encoding=compact"` // AccumulateCount (a.0) is the number of work-items accumulated by service.
AccumulateGasUsed uint64 `jam:"encoding=compact"` // AccumulateGasUsed (a.1) is the amount of gas used for accumulation by service.
OnTransfersCount uint32 `jam:"encoding=compact"` // OnTransfersCount (t.0) is the number of transfers processed by service.
OnTransfersGasUsed uint64 `jam:"encoding=compact"` // OnTransfersGasUsed (t.1) is the amount of gas used for processing transfers by service.
}
type ServiceStatistics ¶
type ServiceStatistics map[block.ServiceId]ServiceActivityRecord
type ValidatorKeys ¶
type ValidatorKeys struct {
EdPrv ed25519.PrivateKey
EdPub ed25519.PublicKey
BanderPrv crypto.BandersnatchPrivateKey
BanderPub crypto.BandersnatchPublicKey
Bls crypto.BlsKey
}
ValidatorKeys holds the cryptographic keys required for a validator node. These keys are used for signing messages, participating in consensus, and establishing secure connections with other nodes.
type ValidatorManager ¶
type ValidatorManager struct {
GridMapper GridMapper
Index uint16
Keys ValidatorKeys
State ValidatorState
}
ValidatorManager handles all validator-related operations including grid neighbor management, validator identity, and slot leadership checks. It implements the connectivity rules defined in the JAMNP-S.
func NewValidatorManager ¶
func NewValidatorManager(keys ValidatorKeys, state ValidatorState, validatorIdx uint16) *ValidatorManager
NewValidatorManager creates a new validator manager with the given keys, state, and validator index. It initializes the grid mapper to manage neighbor connections according to the JAM protocol grid structure.
func (*ValidatorManager) DetermineProxyValidatorIndex ¶
func (vm *ValidatorManager) DetermineProxyValidatorIndex(hash crypto.BandersnatchOutputHash) uint32
DetermineProxyValidatorIndex calculates which validator will serve as the proxy for distributing a Safrole ticket based on the VRF output
func (*ValidatorManager) GetNeighbors ¶
func (vm *ValidatorManager) GetNeighbors() ([]crypto.ValidatorKey, error)
GetNeighbors returns the list of validators that this validator should connect to according to the JAM protocol grid structure. This includes: - Validators in the same row or column in the current epoch - Validators with the same index in the previous and next epochs The function filters out this validator's own key from the returned list.
func (*ValidatorManager) IsNeighbor ¶
func (vm *ValidatorManager) IsNeighbor(key ed25519.PublicKey) bool
IsNeighbor checks if the given validator key represents a neighbor in the grid structure. The third parameter 'true' indicates we're checking within the same epoch, where validators are considered neighbors if they share the same row or column in the grid.
func (*ValidatorManager) IsProxyValidatorFor ¶
func (vm *ValidatorManager) IsProxyValidatorFor(hash crypto.BandersnatchOutputHash) bool
func (*ValidatorManager) IsSlotLeader ¶
func (vm *ValidatorManager) IsSlotLeader(fallbackKeys crypto.EpochKeys) bool
IsSlotLeader determines if this validator is the designated leader for the current time slot. It compares the validator's Bandersnatch public key with the key assigned to the current slot. The fallbackKeys parameter provides the mapping of time slots to designated leader keys. TODO: Probably need to have a way to termine the slot leader without the fallbackKeys.
type ValidatorService ¶
type ValidatorService interface {
ShardDistribution(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16) (bundleShard []byte, segmentShard [][]byte, justification [][]byte, err error)
AuditShardRequest(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16) (bundleShard []byte, justification [][]byte, err error)
SegmentShardRequest(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16, segmentIndexes []uint16) (segmentShards [][]byte, err error)
SegmentShardRequestJustification(ctx context.Context, erasureRoot crypto.Hash, shardIndex uint16, segmentIndexes []uint16) (segmentShards [][]byte, justification [][][]byte, err error)
StoreAllShards(ctx context.Context, erasureRoot crypto.Hash, bundle [][]byte, segments [][][]byte, bundleHashAndSegmentsRoot [][]byte) error
}
ValidatorService holds the logic for storing DA shards for availability purposes, and distributing the shards with justifications after the guarantors finished processing
func NewService ¶
func NewService(availabilityStore *store.Shards) ValidatorService
NewService creates a new validator service that implements ValidatorService interface
type ValidatorServiceMock ¶
func NewValidatorServiceMock ¶
func NewValidatorServiceMock() *ValidatorServiceMock
func (*ValidatorServiceMock) AuditShardRequest ¶
func (*ValidatorServiceMock) SegmentShardRequest ¶
func (*ValidatorServiceMock) SegmentShardRequestJustification ¶
func (*ValidatorServiceMock) ShardDistribution ¶
type ValidatorState ¶
type ValidatorState struct {
CurrentValidators safrole.ValidatorsData // CurrentValidators mapping (κ) Validator keys and metadata currently active.
ArchivedValidators safrole.ValidatorsData // Archived validators (λ) Validator keys and metadata which were active in the prior epoch.
QueuedValidators safrole.ValidatorsData // Enqueued validators (ι) Validator keys and metadata to be drawn from next.
SafroleState safrole.State // Safrole State (𝛾) (state of block-production algorithm)
}
ValidatorState represents the state related to validators
func SetupValidatorState ¶
func SetupValidatorState(t *testing.T) *ValidatorState
type ValidatorStatistics ¶
type ValidatorStatistics struct {
NumOfBlocks uint32 // Number of blocks (b) - The number of blocks produced by the validator.
NumOfTickets uint32 // Number of tickets (t) - The number of tickets introduced by the validator.
NumOfPreimages uint32 // Number of preimages (p) - The number of preimages introduced by the validator.
NumOfBytesAllPreimages uint32 // Number of bytes across all preimages (d) - The total number of octets across all preimages introduced by the validator.
NumOfGuaranteedReports uint32 // Number of guaranteed reports (g) - The number of reports guaranteed by the validator.
NumOfAvailabilityAssurances uint32 // Number of availability assurances (a) - The number of assurances of availability made by the validator.
}