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
2 changes: 2 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ type ProtocolParameters interface {

StakingUnbondingPeriod() EpochIndex

ValidationBlocksPerSlot() uint16

LivenessThreshold() SlotIndex

MinCommittableAge() SlotIndex
Expand Down
15 changes: 9 additions & 6 deletions api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,25 @@ type basicProtocolParameters struct {

// StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking.
StakingUnbondingPeriod EpochIndex `serix:"15,mapKey=stakingUnbondingPeriod"`
// ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot.
ValidationBlocksPerSlot uint16 `serix:"16,mapKey=validationBlocksPerSlot"`

// 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:"17,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:"18,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:"19,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:"20,mapKey=epochNearingThreshold"`
// RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC).
CongestionControlParameters CongestionControlParameters `serix:"20,mapKey=congestionControlParameters"`
CongestionControlParameters CongestionControlParameters `serix:"21,mapKey=congestionControlParameters"`

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

func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
Expand All @@ -79,6 +81,7 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
b.ManaDecayFactorEpochsSum == other.ManaDecayFactorEpochsSum &&
b.ManaDecayFactorEpochsSumExponent == other.ManaDecayFactorEpochsSumExponent &&
b.StakingUnbondingPeriod == other.StakingUnbondingPeriod &&
b.ValidationBlocksPerSlot == other.ValidationBlocksPerSlot &&
b.LivenessThreshold == other.LivenessThreshold &&
b.MinCommittableAge == other.MinCommittableAge &&
b.MaxCommittableAge == other.MaxCommittableAge &&
Expand Down
4 changes: 2 additions & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
1337,
20,
),
iotago.WithStakingOptions(11),
iotago.WithStakingOptions(11, 10),
iotago.WithLivenessOptions(
3,
10,
Expand All @@ -133,7 +133,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
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},"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","validationBlocksPerSlot":10,"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}}`

jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
require.NoError(t, err)
Expand Down
13 changes: 9 additions & 4 deletions api_v3_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr
),
WithLivenessOptions(3, 10, 20, 24),
WithCongestionControlOptions(1, 0, 0, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1, 100*MaxBlockSize),
WithStakingOptions(10),
WithStakingOptions(10, 10),
WithVersionSignalingOptions(7, 5, 7),
},
opts...,
Expand Down Expand Up @@ -85,6 +85,10 @@ func (p *V3ProtocolParameters) StakingUnbondingPeriod() EpochIndex {
return p.basicProtocolParameters.StakingUnbondingPeriod
}

func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint16 {
return p.basicProtocolParameters.ValidationBlocksPerSlot
}

func (p *V3ProtocolParameters) LivenessThreshold() SlotIndex {
return p.basicProtocolParameters.LivenessThreshold
}
Expand Down Expand Up @@ -123,8 +127,8 @@ func (p *V3ProtocolParameters) Hash() (Identifier, error) {
}

func (p *V3ProtocolParameters) String() string {
return fmt.Sprintf("ProtocolParameters: {\n\tVersion: %d\n\tNetwork Name: %s\n\tBech32 HRP Prefix: %s\n\tRent Structure: %v\n\tWorkScore Structure: %v\n\tToken Supply: %d\n\tGenesis Unix Timestamp: %d\n\tSlot Duration in Seconds: %d\n\tSlots per Epoch Exponent: %d\n\tMana Generation Rate: %d\n\tMana Generation Rate Exponent: %d\t\nMana Decay Factors: %v\n\tMana Decay Factors Exponent: %d\n\tMana Decay Factor Epochs Sum: %d\n\tMana Decay Factor Epochs Sum Exponent: %d\n\tStaking Unbonding Period: %d\n\tLiveness Threshold: %d\n\tMin Committable Age: %d\n\tMax Committable Age: %d\n}",
p.basicProtocolParameters.Version, p.basicProtocolParameters.NetworkName, p.basicProtocolParameters.Bech32HRP, p.basicProtocolParameters.RentStructure, p.basicProtocolParameters.WorkScoreStructure, p.basicProtocolParameters.TokenSupply, p.basicProtocolParameters.GenesisUnixTimestamp, p.basicProtocolParameters.SlotDurationInSeconds, p.basicProtocolParameters.SlotsPerEpochExponent, p.basicProtocolParameters.ManaGenerationRate, p.basicProtocolParameters.ManaGenerationRateExponent, p.basicProtocolParameters.ManaDecayFactors, p.basicProtocolParameters.ManaDecayFactorsExponent, p.basicProtocolParameters.ManaDecayFactorEpochsSum, p.basicProtocolParameters.ManaDecayFactorEpochsSumExponent, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.LivenessThreshold, p.basicProtocolParameters.MinCommittableAge, p.basicProtocolParameters.MaxCommittableAge)
return fmt.Sprintf("ProtocolParameters: {\n\tVersion: %d\n\tNetwork Name: %s\n\tBech32 HRP Prefix: %s\n\tRent Structure: %v\n\tWorkScore Structure: %v\n\tToken Supply: %d\n\tGenesis Unix Timestamp: %d\n\tSlot Duration in Seconds: %d\n\tSlots per Epoch Exponent: %d\n\tMana Generation Rate: %d\n\tMana Generation Rate Exponent: %d\t\nMana Decay Factors: %v\n\tMana Decay Factors Exponent: %d\n\tMana Decay Factor Epochs Sum: %d\n\tMana Decay Factor Epochs Sum Exponent: %d\n\tStaking Unbonding Period: %d\n\tValidation Blocks per Slot: %d\n\tLiveness Threshold: %d\n\tMin Committable Age: %d\n\tMax Committable Age: %d\n}",
p.basicProtocolParameters.Version, p.basicProtocolParameters.NetworkName, p.basicProtocolParameters.Bech32HRP, p.basicProtocolParameters.RentStructure, p.basicProtocolParameters.WorkScoreStructure, p.basicProtocolParameters.TokenSupply, p.basicProtocolParameters.GenesisUnixTimestamp, p.basicProtocolParameters.SlotDurationInSeconds, p.basicProtocolParameters.SlotsPerEpochExponent, p.basicProtocolParameters.ManaGenerationRate, p.basicProtocolParameters.ManaGenerationRateExponent, p.basicProtocolParameters.ManaDecayFactors, p.basicProtocolParameters.ManaDecayFactorsExponent, p.basicProtocolParameters.ManaDecayFactorEpochsSum, p.basicProtocolParameters.ManaDecayFactorEpochsSumExponent, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.ValidationBlocksPerSlot, p.basicProtocolParameters.LivenessThreshold, p.basicProtocolParameters.MinCommittableAge, p.basicProtocolParameters.MaxCommittableAge)
}

func (p *V3ProtocolParameters) ManaDecayProvider() *ManaDecayProvider {
Expand Down Expand Up @@ -239,9 +243,10 @@ func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Man
}
}

func WithStakingOptions(unbondingPeriod EpochIndex) options.Option[V3ProtocolParameters] {
func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint16) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod
p.basicProtocolParameters.ValidationBlocksPerSlot = validationBlocksPerSlot
}
}

Expand Down
Loading