Skip to content

Commit

Permalink
Remove ValidatorBlockPerSlot from RewardParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Oct 17, 2023
1 parent a9e95d5 commit 2098f74
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type ProtocolParameters interface {

StakingUnbondingPeriod() EpochIndex

ValidationBlocksPerSlot() uint16
ValidationBlocksPerSlot() uint8

PunishmentEpochs() EpochIndex

Expand Down
2 changes: 1 addition & 1 deletion api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type basicProtocolParameters struct {
// StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking.
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"`
ValidationBlocksPerSlot uint8 `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"`

Expand Down
4 changes: 2 additions & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
100,
),
iotago.WithVersionSignalingOptions(3, 4, 1),
iotago.WithRewardsOptions(10, 8, 8, 31, 1154, 2, 1),
iotago.WithRewardsOptions(8, 8, 31, 1154, 2, 1),
)

protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","rentParameters":{"storageCost":"6","storageScoreFactorData":7,"storageScoreOffsetOutput":"8","storageScoreOffsetEd25519BlockIssuerKey":"9","storageScoreOffsetStakingFeature":"10","storageScoreOffsetDelegation":"10"},"workScoreStructure":{"dataByte":1,"block":2,"input":3,"contextInput":4,"output":5,"nativeToken":6,"staking":7,"blockIssuer":8,"allotment":9,"signatureEd25519":10},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"bitsCount":1,"generationRate":1,"generationRateExponent":27,"decayFactors":[10,20],"decayFactorsExponent":32,"decayFactorEpochsSum":1337,"decayFactorEpochsSumExponent":20},"stakingUnbondingPeriod":11,"validationBlocksPerSlot":10,"punishmentEpochs":9,"livenessThresholdLowerBound":15,"livenessThresholdUpperBound":30,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1},"rewardsParameters":{"validatorBlocksPerSlot":10,"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}`
protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","rentParameters":{"storageCost":"6","storageScoreFactorData":7,"storageScoreOffsetOutput":"8","storageScoreOffsetEd25519BlockIssuerKey":"9","storageScoreOffsetStakingFeature":"10","storageScoreOffsetDelegation":"10"},"workScoreStructure":{"dataByte":1,"block":2,"input":3,"contextInput":4,"output":5,"nativeToken":6,"staking":7,"blockIssuer":8,"allotment":9,"signatureEd25519":10},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"bitsCount":1,"generationRate":1,"generationRateExponent":27,"decayFactors":[10,20],"decayFactorsExponent":32,"decayFactorEpochsSum":1337,"decayFactorEpochsSumExponent":20},"stakingUnbondingPeriod":11,"validationBlocksPerSlot":10,"punishmentEpochs":9,"livenessThresholdLowerBound":15,"livenessThresholdUpperBound":30,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1},"rewardsParameters":{"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}`

jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
require.NoError(t, err)
Expand Down
9 changes: 4 additions & 5 deletions api_v3_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr
WithCongestionControlOptions(1, 0, 0, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1000, 100),
WithStakingOptions(10, 10, 10),
WithVersionSignalingOptions(7, 5, 7),
WithRewardsOptions(10, 8, 8, 31, 1154, 2, 1),
WithRewardsOptions(8, 8, 31, 1154, 2, 1),
},
opts...,
),
Expand Down Expand Up @@ -87,7 +87,7 @@ func (p *V3ProtocolParameters) StakingUnbondingPeriod() EpochIndex {
return p.basicProtocolParameters.StakingUnbondingPeriod
}

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

Expand Down Expand Up @@ -277,7 +277,7 @@ func WithCongestionControlOptions(minReferenceManaCost Mana, rmcIncrease Mana, r
}
}

func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint16, punishmentEpochs EpochIndex) options.Option[V3ProtocolParameters] {
func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint8, punishmentEpochs EpochIndex) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod
p.basicProtocolParameters.ValidationBlocksPerSlot = validationBlocksPerSlot
Expand All @@ -295,9 +295,8 @@ func WithVersionSignalingOptions(windowSize uint8, windowTargetRatio uint8, acti
}
}

func WithRewardsOptions(validatorBlocksPerSlot, profitMarginExponent, decayBalancingConstantExponent, poolCoefficientExponent uint8, bootstrappingDuration EpochIndex, manaShareCoefficient, decayBalancingConstant uint64) options.Option[V3ProtocolParameters] {
func WithRewardsOptions(profitMarginExponent, decayBalancingConstantExponent, poolCoefficientExponent uint8, bootstrappingDuration EpochIndex, manaShareCoefficient, decayBalancingConstant uint64) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.RewardsParameters.ValidatorBlocksPerSlot = validatorBlocksPerSlot
p.basicProtocolParameters.RewardsParameters.ProfitMarginExponent = profitMarginExponent
p.basicProtocolParameters.RewardsParameters.BootstrappingDuration = bootstrappingDuration
p.basicProtocolParameters.RewardsParameters.ManaShareCoefficient = manaShareCoefficient
Expand Down
17 changes: 7 additions & 10 deletions mana.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,22 @@ func (m ManaStructure) Equals(other ManaStructure) bool {
}

type RewardsParameters struct {
// ValidatorBlocksPerSlot is the number of validation blocks that should be issued by a selected validator per slot during its epoch duties.
ValidatorBlocksPerSlot uint8 `serix:"0,mapKey=validatorBlocksPerSlot"`
// ProfitMarginExponent is used for shift operation for calculation of profit margin.
ProfitMarginExponent uint8 `serix:"1,mapKey=profitMarginExponent"`
ProfitMarginExponent uint8 `serix:"0,mapKey=profitMarginExponent"`
// BootstrappingDuration is the length in epochs of the bootstrapping phase, (approx 3 years).
BootstrappingDuration EpochIndex `serix:"2,mapKey=bootstrappingDuration"`
BootstrappingDuration EpochIndex `serix:"1,mapKey=bootstrappingDuration"`
// ManaShareCoefficient is the coefficient used for calculation of initial rewards, relative to the term theta/(1-theta) from the Whitepaper, with theta = 2/3.
ManaShareCoefficient uint64 `serix:"3,mapKey=manaShareCoefficient"`
ManaShareCoefficient uint64 `serix:"2,mapKey=manaShareCoefficient"`
// DecayBalancingConstantExponent is the exponent used for calculation of the initial reward.
DecayBalancingConstantExponent uint8 `serix:"4,mapKey=decayBalancingConstantExponent"`
DecayBalancingConstantExponent uint8 `serix:"3,mapKey=decayBalancingConstantExponent"`
// DecayBalancingConstant needs to be an integer approximation calculated based on chosen DecayBalancingConstantExponent.
DecayBalancingConstant uint64 `serix:"5,mapKey=decayBalancingConstant"`
DecayBalancingConstant uint64 `serix:"4,mapKey=decayBalancingConstant"`
// PoolCoefficientExponent is the exponent used for shifting operation in the pool rewards calculations.
PoolCoefficientExponent uint8 `serix:"6,mapKey=poolCoefficientExponent"`
PoolCoefficientExponent uint8 `serix:"5,mapKey=poolCoefficientExponent"`
}

func (r RewardsParameters) Equals(other RewardsParameters) bool {
return r.ValidatorBlocksPerSlot == other.ValidatorBlocksPerSlot &&
r.ProfitMarginExponent == other.ProfitMarginExponent && r.BootstrappingDuration == other.BootstrappingDuration &&
return r.ProfitMarginExponent == other.ProfitMarginExponent && r.BootstrappingDuration == other.BootstrappingDuration &&
r.ManaShareCoefficient == other.ManaShareCoefficient &&
r.DecayBalancingConstantExponent == other.DecayBalancingConstantExponent &&
r.DecayBalancingConstant == other.DecayBalancingConstant &&
Expand Down
Loading

0 comments on commit 2098f74

Please sign in to comment.