Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation scheduler params #498

Merged
merged 11 commits into from
Sep 13, 2023
12 changes: 10 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ func VersionFromBytes(b []byte) (Version, int, error) {
return Version(b[0]), 1, nil
}

// VersionSignaling defines the parameters used by signaling protocol parameters upgrade.
type VersionSignaling struct {
WindowSize uint8 `serix:"0,mapKey=windowSize"`
// WindowSize is the size of the window in epochs to find which version of protocol parameters was most signaled, from currentEpoch - windowSize to currentEpoch.
WindowSize uint8 `serix:"0,mapKey=windowSize"`
// WindowTargetRatio is the target number of supporters for a version to win in a windowSize.
WindowTargetRatio uint8 `serix:"1,mapKey=windowTargetRatio"`
ActivationOffset uint8 `serix:"2,mapKey=activationOffset"`
// ActivationOffset is the offset in epochs to activate the new version of protocol parameters.
ActivationOffset uint8 `serix:"2,mapKey=activationOffset"`
}

func (s VersionSignaling) Equals(signaling VersionSignaling) bool {
Expand Down Expand Up @@ -115,6 +119,10 @@ type ProtocolParameters interface {

StakingUnbondingPeriod() EpochIndex

ValidationBlocksPerSlot() uint16

PunishmentEpochs() EpochIndex

LivenessThreshold() SlotIndex

MinCommittableAge() SlotIndex
Expand Down
45 changes: 16 additions & 29 deletions api_protocol_parameters.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package iotago

import (
"github.com/iotaledger/hive.go/lo"
)

type basicProtocolParameters struct {
// Version defines the version of the protocol this protocol parameters are for.
Version Version `serix:"0,mapKey=version"`
Expand All @@ -28,38 +24,32 @@ type basicProtocolParameters struct {
// (2**SlotsPerEpochExponent) == slots in an epoch.
SlotsPerEpochExponent uint8 `serix:"8,mapKey=slotsPerEpochExponent"`

// ManaGenerationRate is the amount of potential Mana generated by 1 IOTA in 1 slot.
ManaGenerationRate uint8 `serix:"9,mapKey=manaGenerationRate"`
// ManaGenerationRateExponent is the scaling of ManaGenerationRate expressed as an exponent of 2.
ManaGenerationRateExponent uint8 `serix:"10,mapKey=manaGenerationRateExponent"`
// ManaDecayFactors is a lookup table of epoch index diff to mana decay factor (slice index 0 = 1 epoch).
ManaDecayFactors []uint32 `serix:"11,lengthPrefixType=uint16,mapKey=manaDecayFactors"`
// ManaDecayFactorsExponent is the scaling of ManaDecayFactors expressed as an exponent of 2.
ManaDecayFactorsExponent uint8 `serix:"12,mapKey=manaDecayFactorsExponent"`
// ManaDecayFactorEpochsSum is an integer approximation of the sum of decay over epochs.
ManaDecayFactorEpochsSum uint32 `serix:"13,mapKey=manaDecayFactorEpochsSum"`
// ManaDecayFactorEpochsSumExponent is the scaling of ManaDecayFactorEpochsSum expressed as an exponent of 2.
ManaDecayFactorEpochsSumExponent uint8 `serix:"14,mapKey=manaDecayFactorEpochsSumExponent"`
// ManaStructure defines the mana parameters used by mana calculation.
ManaStructure ManaStructure `serix:"9,mapKey=manaStructure"`

// StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking.
StakingUnbondingPeriod EpochIndex `serix:"15,mapKey=stakingUnbondingPeriod"`
StakingUnbondingPeriod EpochIndex `serix:"10,mapKey=stakingUnbondingPeriod"`
// ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot.
ValidationBlocksPerSlot uint16 `serix:"11,mapKey=validationBlocksPerSlot"`
// PunishmentEpochs is the number of epochs worth of Mana that a node is punished with for each additional validation block it issues.
PunishmentEpochs EpochIndex `serix:"12,mapKey=punishmentEpochs"`

// LivenessThreshold is used by tip-selection to determine the if a block is eligible by evaluating issuingTimes
// and commitments in its past-cone to ATT and lastCommittedSlot respectively.
LivenessThreshold SlotIndex `serix:"16,mapKey=livenessThreshold"`
LivenessThreshold SlotIndex `serix:"13,mapKey=livenessThreshold"`
// MinCommittableAge is the minimum age relative to the accepted tangle time slot index that a slot can be committed.
// For example, if the last accepted slot is in slot 100, and minCommittableAge=10, then the latest committed slot can be at most 100-10=90.
MinCommittableAge SlotIndex `serix:"17,mapKey=minCommittableAge"`
MinCommittableAge SlotIndex `serix:"14,mapKey=minCommittableAge"`
// MaxCommittableAge is the maximum age for a slot commitment to be included in a block relative to the slot index of the block issuing time.
// For example, if the last accepted slot is in slot 100, and maxCommittableAge=20, then the oldest referencable commitment is 100-20=80.
MaxCommittableAge SlotIndex `serix:"18,mapKey=maxCommittableAge"`
MaxCommittableAge SlotIndex `serix:"15,mapKey=maxCommittableAge"`
// EpochNearingThreshold is used by the epoch orchestrator to detect the slot that should trigger a new committee
// selection for the next and upcoming epoch.
EpochNearingThreshold SlotIndex `serix:"19,mapKey=epochNearingThreshold"`
EpochNearingThreshold SlotIndex `serix:"16,mapKey=epochNearingThreshold"`
// RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC).
CongestionControlParameters CongestionControlParameters `serix:"20,mapKey=congestionControlParameters"`
CongestionControlParameters CongestionControlParameters `serix:"17,mapKey=congestionControlParameters"`

VersionSignaling VersionSignaling `serix:"21,mapKey=versionSignaling"`
VersionSignaling VersionSignaling `serix:"18,mapKey=versionSignaling"`
}

func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
Expand All @@ -72,13 +62,10 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
b.GenesisUnixTimestamp == other.GenesisUnixTimestamp &&
b.SlotDurationInSeconds == other.SlotDurationInSeconds &&
b.SlotsPerEpochExponent == other.SlotsPerEpochExponent &&
b.ManaGenerationRate == other.ManaGenerationRate &&
b.ManaGenerationRateExponent == other.ManaGenerationRateExponent &&
lo.Equal(b.ManaDecayFactors, other.ManaDecayFactors) &&
b.ManaDecayFactorsExponent == other.ManaDecayFactorsExponent &&
b.ManaDecayFactorEpochsSum == other.ManaDecayFactorEpochsSum &&
b.ManaDecayFactorEpochsSumExponent == other.ManaDecayFactorEpochsSumExponent &&
b.ManaStructure.Equals(other.ManaStructure) &&
b.StakingUnbondingPeriod == other.StakingUnbondingPeriod &&
b.ValidationBlocksPerSlot == other.ValidationBlocksPerSlot &&
b.PunishmentEpochs == other.PunishmentEpochs &&
b.LivenessThreshold == other.LivenessThreshold &&
b.MinCommittableAge == other.MinCommittableAge &&
b.MaxCommittableAge == other.MaxCommittableAge &&
Expand Down
9 changes: 6 additions & 3 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
8,
9,
10,
10,
),
iotago.WithWorkScoreOptions(
1,
Expand All @@ -106,14 +107,15 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
13,
),
iotago.WithManaOptions(
1,
1,
27,
[]uint32{10, 20},
32,
1337,
20,
),
iotago.WithStakingOptions(11),
iotago.WithStakingOptions(11, 10, 9),
iotago.WithLivenessOptions(
3,
10,
Expand All @@ -128,12 +130,13 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
5*schedulerRate, // 0.5*slotDurationInSeconds*schedulerRate
schedulerRate,
1,
100*iotago.MaxBlockSize,
1000,
100,
),
iotago.WithVersionSignalingOptions(3, 4, 1),
)

protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","rentStructure":{"vByteCost":6,"vByteFactorData":7,"vByteFactorKey":8,"vByteFactorIssuerKeys":9,"vByteFactorStakingFeature":10},"workScoreStructure":{"dataKilobyte":1,"block":2,"missingParent":3,"input":4,"contextInput":5,"output":6,"nativeToken":7,"staking":8,"blockIssuer":9,"allotment":10,"signatureEd25519":11,"minStrongParentsThreshold":12},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaGenerationRate":1,"manaGenerationRateExponent":27,"manaDecayFactors":[10,20],"manaDecayFactorsExponent":32,"manaDecayFactorEpochsSum":1337,"manaDecayFactorEpochsSumExponent":20,"stakingUnbondingPeriod":"11","livenessThreshold":"3","minCommittableAge":"10","maxCommittableAge":"20","epochNearingThreshold":"24","congestionControlParameters":{"rmcMin":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"minMana":"1","maxBufferSize":3276800},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1}}`
protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","rentStructure":{"vByteCost":6,"vByteFactorData":7,"vByteFactorKey":8,"vByteFactorIssuerKeys":9,"vByteFactorStakingFeature":10,"vByteFactorDelegation":10},"workScoreStructure":{"dataKilobyte":1,"block":2,"missingParent":3,"input":4,"contextInput":5,"output":6,"nativeToken":7,"staking":8,"blockIssuer":9,"allotment":10,"signatureEd25519":11,"minStrongParentsThreshold":12},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"manaBitsCount":1,"manaGenerationRate":1,"manaGenerationRateExponent":27,"manaDecayFactors":[10,20],"manaDecayFactorsExponent":32,"manaDecayFactorEpochsSum":1337,"manaDecayFactorEpochsSumExponent":20},"stakingUnbondingPeriod":"11","validationBlocksPerSlot":10,"punishmentEpochs":"9","livenessThreshold":"3","minCommittableAge":"10","maxCommittableAge":"20","epochNearingThreshold":"24","congestionControlParameters":{"rmcMin":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"minMana":"1","maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1}}`

jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
require.NoError(t, err)
Expand Down
Loading
Loading