Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateIntermediateCoreAssignmentsFromAvailability(assurances block.AssurancesExtrinsic, coreAssignments state.CoreAssignments, ...) (state.CoreAssignments, []*block.WorkReport, error)
- func CalculateIntermediateCoreAssignmentsFromExtrinsics(disputes block.DisputeExtrinsic, coreAssignments state.CoreAssignments) state.CoreAssignments
- func CalculateIntermediateCoreFromAssurances(validators safrole.ValidatorsData, assignments state.CoreAssignments, ...) (state.CoreAssignments, []*block.WorkReport, error)
- func CalculateIntermediateServiceState(preimages block.PreimageExtrinsic, serviceState service.ServiceState, ...) (service.ServiceState, error)
- func CalculateNewCoreAssignments(guarantees block.GuaranteesExtrinsic, ...) (newAssignments state.CoreAssignments, reporters crypto.ED25519PublicKeySet, ...)
- func CalculateNewCoreAuthorizations(header block.Header, guarantees block.GuaranteesExtrinsic, ...) state.CoreAuthorizersPool
- func CalculateNewJudgements(newTimeslot jamtime.Timeslot, disputes block.DisputeExtrinsic, ...) (state.Judgements, error)
- func CalculateNewTimeState(header block.Header) jamtime.Timeslot
- func CalculateNewValidatorStatistics(block block.Block, timeslot jamtime.Timeslot, ...) validator.ValidatorStatisticsState
- func GetAvailableWorkReports(coreAssignments state.CoreAssignments) (workReports []block.WorkReport)
- func InvokePVMOnTransfer(serviceState service.ServiceState, serviceIndex block.ServiceId, ...) service.ServiceAccount
- func PermuteAssignments(entropy crypto.Hash, timeslot jamtime.Timeslot) ([]uint32, error)
- func RotateSequence(sequence []uint32, n uint32) []uint32
- func UpdateRecentBlocks(headerHash crypto.Hash, priorStateRoot crypto.Hash, ...) (newRecentBlocks []state.BlockState, err error)
- func UpdateState(s *state.State, newBlock block.Block, chain *store.Chain) error
- func ValidateExtrinsicGuarantees(header block.Header, currentState *state.State, ...) error
- type Accumulator
- func (a *Accumulator) Delta1(accumulationState state.AccumulationState, workReports []block.WorkReport, ...) (state.AccumulationState, []service.DeferredTransfer, *crypto.Hash, uint64)
- func (a *Accumulator) InvokePVM(accState state.AccumulationState, newTime jamtime.Timeslot, ...) (state.AccumulationState, []service.DeferredTransfer, *crypto.Hash, uint64)
- func (a *Accumulator) ParallelDelta(initialAccState state.AccumulationState, workReports []block.WorkReport, ...) (uint64, state.AccumulationState, []service.DeferredTransfer, ServiceHashPairs)
- func (a *Accumulator) SequentialDelta(gasLimit uint64, workReports []block.WorkReport, ctx state.AccumulationState, ...) (uint32, state.AccumulationState, []service.DeferredTransfer, ServiceHashPairs)
- type SafroleInput
- type SafroleOutput
- type ServiceHashPair
- type ServiceHashPairs
Constants ¶
const ( OnTransferCost = 10 AccumulateCost = 10 )
Variables ¶
var ( ErrTimeslotOutOfRange = errors.New("timeslot out of range") ErrWrongAssignment = errors.New("wrong assignment") ErrBadSignature = errors.New("bad signature") ErrReportTimeout = errors.New("report timeout") ErrBadAttestationParent = errors.New("bad attestation parent") ErrBadOrder = errors.New("bad order") ErrCoreNotEngaged = errors.New("core not engaged") ErrBadValidatorIndex = errors.New("bad validator index") )
Functions ¶
func CalculateIntermediateCoreAssignmentsFromAvailability ¶
func CalculateIntermediateCoreAssignmentsFromAvailability(assurances block.AssurancesExtrinsic, coreAssignments state.CoreAssignments, header block.Header) (state.CoreAssignments, []*block.WorkReport, error)
CalculateIntermediateCoreAssignmentsFromAvailability implements equation 26: ρ‡ ≺ (EA, ρ†) It calculates the intermediate core assignments based on availability assurances.
func CalculateIntermediateCoreAssignmentsFromExtrinsics ¶
func CalculateIntermediateCoreAssignmentsFromExtrinsics(disputes block.DisputeExtrinsic, coreAssignments state.CoreAssignments) state.CoreAssignments
CalculateIntermediateCoreAssignmentsFromExtrinsics Equation 25: ρ† ≺ (ED , ρ)
func CalculateIntermediateCoreFromAssurances ¶
func CalculateIntermediateCoreFromAssurances(validators safrole.ValidatorsData, assignments state.CoreAssignments, header block.Header, assurances block.AssurancesExtrinsic) (state.CoreAssignments, []*block.WorkReport, error)
func CalculateIntermediateServiceState ¶
func CalculateIntermediateServiceState( preimages block.PreimageExtrinsic, serviceState service.ServiceState, newTimeslot jamtime.Timeslot, ) (service.ServiceState, error)
CalculateIntermediateServiceState implements Equations 12.28–12.33 v0.6.3 This function calculates the intermediate service state δ† based on: - The current service state δ (serviceState) - The preimage extrinsic EP (preimages) - The new timeslot τ′ (newTimeslot)
For each preimage in EP:
- It adds the preimage p to the PreimageLookup of service s, keyed by its hash H(p)
- It adds a new entry to the PreimageMeta of service s, keyed by the hash H(p) and length |p|, with the value being the new timeslot τ′
The function returns a new ServiceState without modifying the input state.
func CalculateNewCoreAssignments ¶
func CalculateNewCoreAssignments( guarantees block.GuaranteesExtrinsic, intermediateAssignments state.CoreAssignments, validatorState validator.ValidatorState, newTimeslot jamtime.Timeslot, entropyPool state.EntropyPool, ) (newAssignments state.CoreAssignments, reporters crypto.ED25519PublicKeySet, err error)
CalculateNewCoreAssignments updates the core assignments based on new guarantees. This implements equation 27: ρ′ ≺ (EG, ρ‡, κ, τ′)
It also implements part of equation 11.26 v0.6.2 regarding timeslot validation: R(⌊τ′/R⌋ - 1) ≤ t ≤ τ′
func CalculateNewCoreAuthorizations ¶
func CalculateNewCoreAuthorizations(header block.Header, guarantees block.GuaranteesExtrinsic, pendingAuthorizations state.PendingAuthorizersQueues, currentAuthorizations state.CoreAuthorizersPool) state.CoreAuthorizersPool
CalculateNewCoreAuthorizations implements equation 4.19: α' ≺ (H, EG, φ', α) . Graypaper 0.5.4
func CalculateNewJudgements ¶
func CalculateNewJudgements(newTimeslot jamtime.Timeslot, disputes block.DisputeExtrinsic, stateJudgements state.Judgements, validators validator.ValidatorState) (state.Judgements, error)
calculateNewJudgements Equation 23: ψ′ ≺ (ED, ψ) Equations 112-115:(v0.4.5) ψ'g ≡ ψg ∪ {r | {r, ⌊2/3V⌋ + 1} ∈ V} ψ'b ≡ ψb ∪ {r | {r, 0} ∈ V} ψ'w ≡ ψw ∪ {r | {r, ⌊1/3V⌋} ∈ V} ψ'o ≡ ψo ∪ {k | (r, k, s) ∈ c} ∪ {k | (r, v, k, s) ∈ f}
func CalculateNewTimeState ¶
CalculateNewTimeState Equation 16: τ′ ≺ H
func CalculateNewValidatorStatistics ¶
func CalculateNewValidatorStatistics(block block.Block, timeslot jamtime.Timeslot, validatorStatistics validator.ValidatorStatisticsState, reporters crypto.ED25519PublicKeySet, currValidators safrole.ValidatorsData) validator.ValidatorStatisticsState
CalculateNewValidatorStatistics implements equation 30: π′ ≺ (EG, EP, EA, ET, τ, κ′, π, H)
func GetAvailableWorkReports ¶
func GetAvailableWorkReports(coreAssignments state.CoreAssignments) (workReports []block.WorkReport)
W ≡ [ ρ†[c]w | c <− N_C, ∑ [a∈E_A] a_f [c] > 2/3 V ]
func InvokePVMOnTransfer ¶
func InvokePVMOnTransfer(serviceState service.ServiceState, serviceIndex block.ServiceId, transfers []service.DeferredTransfer) service.ServiceAccount
InvokePVMOnTransfer On-Transfer service-account invocation (ΨT). The only state alteration it facilitates are basic alteration to the storage of the subject account
func PermuteAssignments ¶
PermuteAssignments generates the core assignments for validators. Implements Equation (11.20 v0.6.2): P(e, t) ≡ R(F([⌊C ⋅ i/V⌋ ∣i ∈ NV], e), ⌊t mod E/R⌋)
func RotateSequence ¶
RotateSequence rotates the sequence by n positions modulo C. Implements Equation (11.18 v.0.5.0): R(c, n) ≡ [(x + n) mod C ∣ x ∈ shuffledSequence]
func UpdateRecentBlocks ¶
func UpdateRecentBlocks( headerHash crypto.Hash, priorStateRoot crypto.Hash, accumulationRoot crypto.Hash, intermediateRecentBlocks []state.BlockState, workPackageMapping map[crypto.Hash]crypto.Hash) (newRecentBlocks []state.BlockState, err error)
UpdateRecentBlocks updates β. It takes the final inputs from Equation 83: let n = {p, h ▸▸ H(H), b, s ▸▸ H_0} and produces Equation 84: β′ ≡ ←────── β† n_H. We separate out this logic for ease of testing aganist the recent history test vectors.
func UpdateState ¶
UpdateState updates the state TODO: all the calculations which are not dependent on intermediate / new state can be done in parallel
it might be worth making State immutable and make it so that UpdateState returns a new State with all the updated fields
Types ¶
type Accumulator ¶
type Accumulator struct {
// contains filtered or unexported fields
}
func NewAccumulator ¶
func (*Accumulator) Delta1 ¶
func (a *Accumulator) Delta1( accumulationState state.AccumulationState, workReports []block.WorkReport, alwaysAccumulate map[block.ServiceId]uint64, serviceIndex block.ServiceId, ) (state.AccumulationState, []service.DeferredTransfer, *crypto.Hash, uint64)
Delta1 implements equation 12.19 ∆1 (U, ⟦W⟧, D⟨NS → NG⟩, NS ) → (U, ⟦T⟧, H?, NG)
func (*Accumulator) InvokePVM ¶
func (a *Accumulator) InvokePVM(accState state.AccumulationState, newTime jamtime.Timeslot, serviceIndex block.ServiceId, gas uint64, accOperand []state.AccumulationOperand) (state.AccumulationState, []service.DeferredTransfer, *crypto.Hash, uint64)
InvokePVM ΨA(U, N_S , N_G, ⟦O⟧) → (U, ⟦T⟧, H?, N_G) Equation (B.8)
func (*Accumulator) ParallelDelta ¶
func (a *Accumulator) ParallelDelta( initialAccState state.AccumulationState, workReports []block.WorkReport, alwaysAccumulate map[block.ServiceId]uint64, ) ( uint64, state.AccumulationState, []service.DeferredTransfer, ServiceHashPairs, )
ParallelDelta implements equation 12.17 (∆*)
func (*Accumulator) SequentialDelta ¶
func (a *Accumulator) SequentialDelta( gasLimit uint64, workReports []block.WorkReport, ctx state.AccumulationState, alwaysAccumulate map[block.ServiceId]uint64, ) ( uint32, state.AccumulationState, []service.DeferredTransfer, ServiceHashPairs, )
SequentialDelta implements equation 12.16 (∆+)
type SafroleInput ¶
type SafroleInput struct { // Next timeslot. TimeSlot jamtime.Timeslot // Ticket extrinsic (E_T). Tickets []block.TicketProof // Y(Hv) Entropy crypto.BandersnatchOutputHash // ψ′ Offenders []ed25519.PublicKey }
Input to UpdateSafroleState. Derived from the incoming block.
func NewSafroleInputFromBlock ¶
func NewSafroleInputFromBlock(block block.Block) (SafroleInput, error)
type SafroleOutput ¶
type SafroleOutput struct { // H_e EpochMark *block.EpochMarker // H_w WinningTicketMark *block.WinningTicketMarker }
Output from UpdateSafroleState.
func UpdateSafroleState ¶
func UpdateSafroleState( input SafroleInput, preTimeSlot jamtime.Timeslot, entropyPool state.EntropyPool, validatorState validator.ValidatorState, ) (state.EntropyPool, validator.ValidatorState, SafroleOutput, error)
Implements section 6 of the graypaper. Updates all state associated with the SAFROLE protocol. Implements key equations (v.0.4.5) γ′k ≡ Φ(ι) if e′ > e (58) γ′s ≡ Z(γa) if e′ = e + 1 ∧ m ≥ Y ∧ |γa| = E
γs if e′ = e F(η′2, κ′) otherwise (69)
He ≡ (η′1, [kb S k <− γ′k]) if e′ > e
∅ otherwise (72)
Hw ≡ Z(γa) if e′ = e ∧ m < Y ≤ m′ ∧ |γa| = E
∅ otherwise (73)
type ServiceHashPairs ¶
type ServiceHashPairs []ServiceHashPair
ServiceHashPairs B ≡ {(NS , H)} (eq. 12.15)
func CalculateWorkReportsAndAccumulate ¶
func CalculateWorkReportsAndAccumulate(header *block.Header, currentState *state.State, newTimeslot jamtime.Timeslot, workReports []block.WorkReport) ( newAccumulationQueue state.AccumulationQueue, newAccumulationHistory state.AccumulationHistory, postAccumulationServiceState service.ServiceState, newPrivilegedServices service.PrivilegedServices, newValidatorKeys safrole.ValidatorsData, newPendingAuthorizersQueues state.PendingAuthorizersQueues, hashPairs ServiceHashPairs, )
CalculateWorkReportsAndAccumulate implements equation 29: (ϑ′, ξ′, δ′, χ′, ι′, φ′, C) ≺ (W*, ϑ, ξ, δ†, χ, ι, φ) with the only difference that we take in available work reports and calculate the accumulatable WR eq. 4.16 W* ≺ (EA, ρ′) and eq. 4.17: (ϑ′, ξ′, δ‡, χ′, ι′, φ′, C) ≺ (W*, ϑ, ξ, δ, χ, ι, φ)