statetransition

package
v0.0.0-...-3b087ab Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OnTransferCost = 10
	AccumulateCost = 10
)

Variables

This section is empty.

Functions

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 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

func PermuteAssignments(entropy crypto.Hash, timeslot jamtime.Timeslot) ([]uint32, error)

PermuteAssignments generates the core assignments for validators. Implements Equation (134 v0.4.5): P(e, t) ≡ R(F([⌊C ⋅ i/V⌋ ∣i ∈ NV], e), ⌊t mod E/R⌋)

func RotateSequence

func RotateSequence(sequence []uint32, n uint32) []uint32

RotateSequence rotates the sequence by n positions modulo C. Implements Equation (133 v.0.4.5): 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

func UpdateState(s *state.State, newBlock block.Block) error

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 NewAccumulator(state *state.State, header *block.Header) *Accumulator

func (*Accumulator) Delta1

func (a *Accumulator) Delta1(
	accumulationState state.AccumulationState,
	workReports []block.WorkReport,
	privilegedGas map[block.ServiceId]uint64,
	serviceIndex block.ServiceId,
) (state.AccumulationState, []service.DeferredTransfer, *crypto.Hash, uint64)

Delta1 implements equation 180 (∆1)

func (*Accumulator) InvokePVM

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,
	privilegedGas map[block.ServiceId]uint64,
) (
	uint64,
	state.AccumulationState,
	[]service.DeferredTransfer,
	ServiceHashPairs,
)

ParallelDelta implements equation 178 (∆*)

func (*Accumulator) SequentialDelta

SequentialDelta implements equation 177 (∆+)

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 ServiceHashPair

type ServiceHashPair struct {
	ServiceId block.ServiceId
	Hash      crypto.Hash
}

type ServiceHashPairs

type ServiceHashPairs []ServiceHashPair

ServiceHashPairs (176) B ≡ {(NS , H)}

Jump to

Keyboard shortcuts

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