From e6a89d4bccc96cca0f6765e178b77ad388c1283e Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 5 Sep 2023 17:06:12 +0100 Subject: [PATCH 1/7] add committee size and validation blocks per slot to protocol params --- api_protocol_parameters.go | 18 ++++++++++++------ api_test.go | 4 ++-- api_v3_protocol_parameters.go | 18 ++++++++++++++---- nodeclient/apimodels/core_test.go | 2 +- vm/stardust/vm_stardust_test.go | 2 +- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index e5e3bb687..c5f4e8e60 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -43,23 +43,27 @@ type basicProtocolParameters struct { // StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking. StakingUnbondingPeriod EpochIndex `serix:"15,mapKey=stakingUnbondingPeriod"` + // CommitteeSize is the number of validators in the validator committee. + CommitteeSize uint16 `serix:"16,mapKey=committeeSize"` + // ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot. + ValidationBlocksPerSlot uint8 `serix:"17,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:"18,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:"19,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:"20,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:"21,mapKey=epochNearingThreshold"` // RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC). - CongestionControlParameters CongestionControlParameters `serix:"20,mapKey=congestionControlParameters"` + CongestionControlParameters CongestionControlParameters `serix:"22,mapKey=congestionControlParameters"` - VersionSignaling VersionSignaling `serix:"21,mapKey=versionSignaling"` + VersionSignaling VersionSignaling `serix:"23,mapKey=versionSignaling"` } func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { @@ -79,6 +83,8 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { b.ManaDecayFactorEpochsSum == other.ManaDecayFactorEpochsSum && b.ManaDecayFactorEpochsSumExponent == other.ManaDecayFactorEpochsSumExponent && b.StakingUnbondingPeriod == other.StakingUnbondingPeriod && + b.CommitteeSize == other.CommitteeSize && + b.ValidationBlocksPerSlot == other.ValidationBlocksPerSlot && b.LivenessThreshold == other.LivenessThreshold && b.MinCommittableAge == other.MinCommittableAge && b.MaxCommittableAge == other.MaxCommittableAge && diff --git a/api_test.go b/api_test.go index 7d01584c8..b9fd31040 100644 --- a/api_test.go +++ b/api_test.go @@ -113,7 +113,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) { 1337, 20, ), - iotago.WithStakingOptions(11), + iotago.WithStakingOptions(11, 32, 10), iotago.WithLivenessOptions( 3, 10, @@ -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","committeeSize":32,"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) diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index d987c3954..7c957b2c5 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -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, 32, 10), WithVersionSignalingOptions(7, 5, 7), }, opts..., @@ -85,6 +85,14 @@ func (p *V3ProtocolParameters) StakingUnbondingPeriod() EpochIndex { return p.basicProtocolParameters.StakingUnbondingPeriod } +func (p *V3ProtocolParameters) CommitteeSize() uint16 { + return p.basicProtocolParameters.CommitteeSize +} + +func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint8 { + return p.basicProtocolParameters.ValidationBlocksPerSlot +} + func (p *V3ProtocolParameters) LivenessThreshold() SlotIndex { return p.basicProtocolParameters.LivenessThreshold } @@ -123,8 +131,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\tCommittee Size: %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.CommitteeSize, p.basicProtocolParameters.ValidationBlocksPerSlot, p.basicProtocolParameters.LivenessThreshold, p.basicProtocolParameters.MinCommittableAge, p.basicProtocolParameters.MaxCommittableAge) } func (p *V3ProtocolParameters) ManaDecayProvider() *ManaDecayProvider { @@ -239,9 +247,11 @@ func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Man } } -func WithStakingOptions(unbondingPeriod EpochIndex) options.Option[V3ProtocolParameters] { +func WithStakingOptions(unbondingPeriod EpochIndex, committeeSize uint16, validationBlocksPerSlot uint8) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod + p.basicProtocolParameters.CommitteeSize = committeeSize + p.basicProtocolParameters.ValidationBlocksPerSlot = validationBlocksPerSlot } } diff --git a/nodeclient/apimodels/core_test.go b/nodeclient/apimodels/core_test.go index b8730c8a9..ecdafbf62 100644 --- a/nodeclient/apimodels/core_test.go +++ b/nodeclient/apimodels/core_test.go @@ -61,7 +61,7 @@ func Test_InfoResponse(t *testing.T) { jsonResponse, err := api.JSONEncode(response) require.NoError(t, err) - expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21,\"stakingUnbondingPeriod\":\"10\",\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":3276800},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" + expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21,\"stakingUnbondingPeriod\":\"10\",\"committeeSize\":32,\"validationBlocksPerSlot\":10,\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":3276800},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" require.Equal(t, expected, string(jsonResponse)) decoded := new(apimodels.InfoResponse) diff --git a/vm/stardust/vm_stardust_test.go b/vm/stardust/vm_stardust_test.go index f502ef525..be280ae27 100644 --- a/vm/stardust/vm_stardust_test.go +++ b/vm/stardust/vm_stardust_test.go @@ -43,7 +43,7 @@ var ( tpkg.ManaDecayFactorEpochsSum(betaPerYear, 1< Date: Tue, 5 Sep 2023 18:42:29 +0100 Subject: [PATCH 2/7] add methods to interface --- api.go | 4 ++++ api_protocol_parameters.go | 2 +- api_v3_protocol_parameters.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index 0f5146583..eb0203299 100644 --- a/api.go +++ b/api.go @@ -115,6 +115,10 @@ type ProtocolParameters interface { StakingUnbondingPeriod() EpochIndex + CommitteeSize() uint16 + + ValidationBlocksPerSlot() uint16 + LivenessThreshold() SlotIndex MinCommittableAge() SlotIndex diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index c5f4e8e60..4610ca34f 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -46,7 +46,7 @@ type basicProtocolParameters struct { // CommitteeSize is the number of validators in the validator committee. CommitteeSize uint16 `serix:"16,mapKey=committeeSize"` // ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot. - ValidationBlocksPerSlot uint8 `serix:"17,mapKey=validationBlocksPerSlot"` + ValidationBlocksPerSlot uint16 `serix:"17,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. diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index 7c957b2c5..910a8a566 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -89,7 +89,7 @@ func (p *V3ProtocolParameters) CommitteeSize() uint16 { return p.basicProtocolParameters.CommitteeSize } -func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint8 { +func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint16 { return p.basicProtocolParameters.ValidationBlocksPerSlot } @@ -247,7 +247,7 @@ func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Man } } -func WithStakingOptions(unbondingPeriod EpochIndex, committeeSize uint16, validationBlocksPerSlot uint8) options.Option[V3ProtocolParameters] { +func WithStakingOptions(unbondingPeriod EpochIndex, committeeSize uint16, validationBlocksPerSlot uint16) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod p.basicProtocolParameters.CommitteeSize = committeeSize From e4386cb9534bd7f99b9204cd05e039d3725f9970 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 7 Sep 2023 08:55:06 +0100 Subject: [PATCH 3/7] remove committee size param --- api.go | 2 -- api_protocol_parameters.go | 3 --- api_test.go | 4 ++-- api_v3_protocol_parameters.go | 13 ++++--------- nodeclient/apimodels/core_test.go | 2 +- vm/stardust/vm_stardust_test.go | 2 +- 6 files changed, 8 insertions(+), 18 deletions(-) diff --git a/api.go b/api.go index eb0203299..f0fd02934 100644 --- a/api.go +++ b/api.go @@ -115,8 +115,6 @@ type ProtocolParameters interface { StakingUnbondingPeriod() EpochIndex - CommitteeSize() uint16 - ValidationBlocksPerSlot() uint16 LivenessThreshold() SlotIndex diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index 4610ca34f..909e61b31 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -43,8 +43,6 @@ type basicProtocolParameters struct { // StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking. StakingUnbondingPeriod EpochIndex `serix:"15,mapKey=stakingUnbondingPeriod"` - // CommitteeSize is the number of validators in the validator committee. - CommitteeSize uint16 `serix:"16,mapKey=committeeSize"` // ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot. ValidationBlocksPerSlot uint16 `serix:"17,mapKey=validationBlocksPerSlot"` @@ -83,7 +81,6 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { b.ManaDecayFactorEpochsSum == other.ManaDecayFactorEpochsSum && b.ManaDecayFactorEpochsSumExponent == other.ManaDecayFactorEpochsSumExponent && b.StakingUnbondingPeriod == other.StakingUnbondingPeriod && - b.CommitteeSize == other.CommitteeSize && b.ValidationBlocksPerSlot == other.ValidationBlocksPerSlot && b.LivenessThreshold == other.LivenessThreshold && b.MinCommittableAge == other.MinCommittableAge && diff --git a/api_test.go b/api_test.go index b9fd31040..b7f3e8a1f 100644 --- a/api_test.go +++ b/api_test.go @@ -113,7 +113,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) { 1337, 20, ), - iotago.WithStakingOptions(11, 32, 10), + iotago.WithStakingOptions(11, 10), iotago.WithLivenessOptions( 3, 10, @@ -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","committeeSize":32,"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}}` + 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) diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index 910a8a566..abcd69c2d 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -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, 32, 10), + WithStakingOptions(10, 10), WithVersionSignalingOptions(7, 5, 7), }, opts..., @@ -85,10 +85,6 @@ func (p *V3ProtocolParameters) StakingUnbondingPeriod() EpochIndex { return p.basicProtocolParameters.StakingUnbondingPeriod } -func (p *V3ProtocolParameters) CommitteeSize() uint16 { - return p.basicProtocolParameters.CommitteeSize -} - func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint16 { return p.basicProtocolParameters.ValidationBlocksPerSlot } @@ -131,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\tCommittee Size: %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.CommitteeSize, p.basicProtocolParameters.ValidationBlocksPerSlot, 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 { @@ -247,10 +243,9 @@ func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Man } } -func WithStakingOptions(unbondingPeriod EpochIndex, committeeSize uint16, validationBlocksPerSlot uint16) options.Option[V3ProtocolParameters] { +func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint16) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod - p.basicProtocolParameters.CommitteeSize = committeeSize p.basicProtocolParameters.ValidationBlocksPerSlot = validationBlocksPerSlot } } diff --git a/nodeclient/apimodels/core_test.go b/nodeclient/apimodels/core_test.go index ecdafbf62..8d6068c26 100644 --- a/nodeclient/apimodels/core_test.go +++ b/nodeclient/apimodels/core_test.go @@ -61,7 +61,7 @@ func Test_InfoResponse(t *testing.T) { jsonResponse, err := api.JSONEncode(response) require.NoError(t, err) - expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21,\"stakingUnbondingPeriod\":\"10\",\"committeeSize\":32,\"validationBlocksPerSlot\":10,\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":3276800},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" + expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21,\"stakingUnbondingPeriod\":\"10\",\"validationBlocksPerSlot\":10,\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":3276800},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" require.Equal(t, expected, string(jsonResponse)) decoded := new(apimodels.InfoResponse) diff --git a/vm/stardust/vm_stardust_test.go b/vm/stardust/vm_stardust_test.go index be280ae27..bde918f34 100644 --- a/vm/stardust/vm_stardust_test.go +++ b/vm/stardust/vm_stardust_test.go @@ -43,7 +43,7 @@ var ( tpkg.ManaDecayFactorEpochsSum(betaPerYear, 1< Date: Thu, 7 Sep 2023 09:08:56 +0100 Subject: [PATCH 4/7] correct serix numbers --- api_protocol_parameters.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index 909e61b31..ad1b23d54 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -44,24 +44,24 @@ 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:"17,mapKey=validationBlocksPerSlot"` + 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:"18,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:"19,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:"20,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:"21,mapKey=epochNearingThreshold"` + EpochNearingThreshold SlotIndex `serix:"20,mapKey=epochNearingThreshold"` // RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC). - CongestionControlParameters CongestionControlParameters `serix:"22,mapKey=congestionControlParameters"` + CongestionControlParameters CongestionControlParameters `serix:"21,mapKey=congestionControlParameters"` - VersionSignaling VersionSignaling `serix:"23,mapKey=versionSignaling"` + VersionSignaling VersionSignaling `serix:"22,mapKey=versionSignaling"` } func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { From ae553965e1a3dd583360f2d7f86907d2863a29e6 Mon Sep 17 00:00:00 2001 From: "Ching-Hua (Vivian) Lin" Date: Fri, 8 Sep 2023 15:02:36 +0800 Subject: [PATCH 5/7] Align protocol parameters to spec (#495) * Add vByteFactorDelegation * Add ManaBitsExponent to protocol parameters * Move mana protocol params to ManaStructure * Fix info response test * Add comment to ManaStructure * Add comments to VersionSignaling * Rename ManaBitsExponent to ManaBitsCount * Rename bitsExponent to bitsCount in ManaDecayProvider * Resolve comments * Rename to bitsCount --- api.go | 8 ++++-- api_protocol_parameters.go | 42 +++++++++--------------------- api_test.go | 4 ++- api_v3_protocol_parameters.go | 29 ++++++++++++--------- mana.go | 31 ++++++++++++++++++++++ mana_decay_provider.go | 25 +++++++++--------- mana_decay_provider_test.go | 23 ++++++++++++++-- nodeclient/apimodels/core_test.go | 2 +- nodeclient/http_api_client_test.go | 2 +- output_test.go | 2 +- rent.go | 2 ++ rent_test.go | 3 ++- tpkg/test_consts.go | 2 +- tpkg/util.go | 1 + vm/stardust/vm_stardust_test.go | 6 +++-- 15 files changed, 114 insertions(+), 68 deletions(-) create mode 100644 mana.go diff --git a/api.go b/api.go index f0fd02934..3643f52ff 100644 --- a/api.go +++ b/api.go @@ -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 { diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index ad1b23d54..6b4f395e3 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -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"` @@ -28,40 +24,31 @@ 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:"16,mapKey=validationBlocksPerSlot"` + ValidationBlocksPerSlot uint16 `serix:"11,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:"17,mapKey=livenessThreshold"` + LivenessThreshold SlotIndex `serix:"12,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:"18,mapKey=minCommittableAge"` + MinCommittableAge SlotIndex `serix:"13,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:"19,mapKey=maxCommittableAge"` + MaxCommittableAge SlotIndex `serix:"14,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:"20,mapKey=epochNearingThreshold"` + EpochNearingThreshold SlotIndex `serix:"15,mapKey=epochNearingThreshold"` // RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC). - CongestionControlParameters CongestionControlParameters `serix:"21,mapKey=congestionControlParameters"` + CongestionControlParameters CongestionControlParameters `serix:"16,mapKey=congestionControlParameters"` - VersionSignaling VersionSignaling `serix:"22,mapKey=versionSignaling"` + VersionSignaling VersionSignaling `serix:"17,mapKey=versionSignaling"` } func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { @@ -74,12 +61,7 @@ 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.LivenessThreshold == other.LivenessThreshold && diff --git a/api_test.go b/api_test.go index b7f3e8a1f..4a96bf78e 100644 --- a/api_test.go +++ b/api_test.go @@ -85,6 +85,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) { 8, 9, 10, + 10, ), iotago.WithWorkScoreOptions( 1, @@ -106,6 +107,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) { 13, ), iotago.WithManaOptions( + 1, 1, 27, []uint32{10, 20}, @@ -133,7 +135,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","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}}` + 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,"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) diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index abcd69c2d..275f12ee1 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -20,10 +20,11 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr append([]options.Option[V3ProtocolParameters]{ WithVersion(apiV3Version), WithNetworkOptions("testnet", PrefixTestnet), - WithSupplyOptions(1813620509061365, 100, 1, 10, 100, 100), + WithSupplyOptions(1813620509061365, 100, 1, 10, 100, 100, 100), WithWorkScoreOptions(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), WithTimeProviderOptions(time.Now().Unix(), 10, 13), - WithManaOptions(1, + WithManaOptions(63, + 1, 17, []uint32{ 4291249941, 4287535805, 4283824883, 4280117173, 4276412671, 4272711377, 4269013285, 4265318395, 4261626702, 4257938205, 4254252900, 4250570785, 4246891856, 4243216112, 4239543550, 4235874166, 4232207957, 4228544922, 4224885058, 4221228361, 4217574829, 4213924459, 4210277249, 4206633195, 4202992295, 4199354547, 4195719947, 4192088493, 4188460182, 4184835011, 4181212978, 4177594080, 4173978314, 4170365677, 4166756168, 4163149782, 4159546518, 4155946372, 4152349343, 4148755427, 4145164621, 4141576923, 4137992331, 4134410840, 4130832450, 4127257157, 4123684959, 4120115852, 4116549834, 4112986903, 4109427055, 4105870289, 4102316601, 4098765988, 4095218449, 4091673981, 4088132580, 4084594244, 4081058971, 4077526757, 4073997601, 4070471499, 4066948449, 4063428449, 4059911495, 4056397585, 4052886716, 4049378886, 4045874092, 4042372332, 4038873602, 4035377901, 4031885225, 4028395572, 4024908939, 4021425325, 4017944725, 4014467138, 4010992560, 4007520990, 4004052425, 4000586862, 3997124298, 3993664731, 3990208159, 3986754578, 3983303986, 3979856381, 3976411760, 3972970120, 3969531459, 3966095774, 3962663063, 3959233323, 3955806551, 3952382745, 3948961903, 3945544021, 3942129098, 3938717130, 3935308116, 3931902052, 3928498936, 3925098765, 3921701537, 3918307250, 3914915900, 3911527486, 3908142004, 3904759453, 3901379829, 3898003131, 3894629355, 3891258499, 3887890560, 3884525537, 3881163426, 3877804224, 3874447931, 3871094542, 3867744056, 3864396469, 3861051780, 3857709986, 3854371084, 3851035072, 3847701948, 3844371708, 3841044351, 3837719873, 3834398273, 3831079548, 3827763695, 3824450713, 3821140597, 3817833347, 3814528959, 3811227431, 3807928760, 3804632945, 3801339982, 3798049869, 3794762604, 3791478184, 3788196607, 3784917870, 3781641970, 3778368907, 3775098676, 3771831275, 3768566702, 3765304955, 3762046031, 3758789928, 3755536643, 3752286174, 3749038518, 3745793673, 3742551636, 3739312405, 3736075978, 3732842352, 3729611525, 3726383494, 3723158258, 3719935812, 3716716156, 3713499286, 3710285201, 3707073897, 3703865373, 3700659626, 3697456653, 3694256453, 3691059023, 3687864360, 3684672462, 3681483326, 3678296951, 3675113334, 3671932472, 3668754363, 3665579005, 3662406395, 3659236531, 3656069411, 3652905032, 3649743392, 3646584488, 3643428318, 3640274880, 3637124172, 3633976190, 3630830933, 3627688398, 3624548583, 3621411486, 3618277104, 3615145434, 3612016476, 3608890225, 3605766680, 3602645839, 3599527699, 3596412257, 3593299512, 3590189461, 3587082102, 3583977433, 3580875450, 3577776153, 3574679537, 3571585602, 3568494345, 3565405764, 3562319855, 3559236618, 3556156049, 3553078146, 3550002907, 3546930330, 3543860413, 3540793152, 3537728546, 3534666593, 3531607290, 3528550634, 3525496624, 3522445258, 3519396533, 3516350446, 3513306995, 3510266179, 3507227995, 3504192440, 3501159513, 3498129210, 3495101531, 3492076472, 3489054031, 3486034206, 3483016995, 3480002395, 3476990404, 3473981020, 3470974241, 3467970065, 3464968488, 3461969510, 3458973127, 3455979337, 3452988139, 3449999530, 3447013507, 3444030069, 3441049213, 3438070937, 3435095238, 3432122115, 3429151566, 3426183587, 3423218178, 3420255335, 3417295056, 3414337339, 3411382183, 3408429584, 3405479541, 3402532051, 3399587112, 3396644722, 3393704878, 3390767579, 3387832823, 3384900606, 3381970927, 3379043784, 3376119175, 3373197097, 3370277548, 3367360525, 3364446028, 3361534053, 3358624598, 3355717662, 3352813241, 3349911335, 3347011940, 3344115054, 3341220676, 3338328803, 3335439433, 3332552563, 3329668193, 3326786318, 3323906939, 3321030051, 3318155653, 3315283743, 3312414319, 3309547378, 3306682918, 3303820938, 3300961435, 3298104407, 3295249852, 3292397767, 3289548151, 3286701001, 3283856315, 3281014092, 3278174328, 3275337023, 3272502173, 3269669777, 3266839832, 3264012336, 3261187288, 3258364685, 3255544525, 3252726806, 3249911526, 3247098682, 3244288273, 3241480296, 3238674749, 3235871631, 3233070939, 3230272671, 3227476825, 3224683399, 3221892391, 3219103798, 3216317619, 3213533851, 3210752492, 3207973541, 3205196995, 3202422853, 3199651111, 3196881768, 3194114823, 3191350272, 3188588114, 3185828346, 3183070967, 3180315975, 3177563367, 3174813142, 3172065297, 3169319830, 3166576739, 3163836023, 3161097679, 3158361705, 3155628099, 3152896859, 3150167982, 3147441468, 3144717314, 3141995517, 3139276076, 3136558989, 3133844253, 3131131867, @@ -127,12 +128,12 @@ 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\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) + 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 Structure: %v\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.ManaStructure, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.ValidationBlocksPerSlot, p.basicProtocolParameters.LivenessThreshold, p.basicProtocolParameters.MinCommittableAge, p.basicProtocolParameters.MaxCommittableAge) } func (p *V3ProtocolParameters) ManaDecayProvider() *ManaDecayProvider { - return NewManaDecayProvider(p.TimeProvider(), p.basicProtocolParameters.SlotsPerEpochExponent, p.basicProtocolParameters.ManaGenerationRate, p.basicProtocolParameters.ManaGenerationRateExponent, p.basicProtocolParameters.ManaDecayFactors, p.basicProtocolParameters.ManaDecayFactorsExponent, p.basicProtocolParameters.ManaDecayFactorEpochsSum, p.basicProtocolParameters.ManaDecayFactorEpochsSumExponent) + return NewManaDecayProvider(p.TimeProvider(), p.basicProtocolParameters.SlotsPerEpochExponent, &p.basicProtocolParameters.ManaStructure) } func (p *V3ProtocolParameters) Equals(other ProtocolParameters) bool { @@ -157,7 +158,7 @@ func WithNetworkOptions(networkName string, bech32HRP NetworkPrefix) options.Opt } } -func WithSupplyOptions(totalSupply BaseToken, vByteCost uint32, vBFactorData, vBFactorKey, vBFactorIssuerKeys, vBFactorStakingFeature VByteCostFactor) options.Option[V3ProtocolParameters] { +func WithSupplyOptions(totalSupply BaseToken, vByteCost uint32, vBFactorData, vBFactorKey, vBFactorIssuerKeys, vBFactorStakingFeature, vBFactorDelegation VByteCostFactor) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.TokenSupply = totalSupply p.basicProtocolParameters.RentStructure = RentStructure{ @@ -166,6 +167,7 @@ func WithSupplyOptions(totalSupply BaseToken, vByteCost uint32, vBFactorData, vB VBFactorKey: vBFactorKey, VBFactorIssuerKeys: vBFactorIssuerKeys, VBFactorStakingFeature: vBFactorStakingFeature, + VBFactorDelegation: vBFactorDelegation, } } } @@ -210,14 +212,15 @@ func WithTimeProviderOptions(genesisTimestamp int64, slotDuration uint8, slotsPe } } -func WithManaOptions(manaGenerationRate uint8, manaGenerationRateExponent uint8, manaDecayFactors []uint32, manaDecayFactorsExponent uint8, manaDecayFactorEpochsSum uint32, manaDecayFactorEpochsSumExponent uint8) options.Option[V3ProtocolParameters] { +func WithManaOptions(manaBitsCount uint8, manaGenerationRate uint8, manaGenerationRateExponent uint8, manaDecayFactors []uint32, manaDecayFactorsExponent uint8, manaDecayFactorEpochsSum uint32, manaDecayFactorEpochsSumExponent uint8) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { - p.basicProtocolParameters.ManaGenerationRate = manaGenerationRate - p.basicProtocolParameters.ManaGenerationRateExponent = manaGenerationRateExponent - p.basicProtocolParameters.ManaDecayFactors = manaDecayFactors - p.basicProtocolParameters.ManaDecayFactorsExponent = manaDecayFactorsExponent - p.basicProtocolParameters.ManaDecayFactorEpochsSum = manaDecayFactorEpochsSum - p.basicProtocolParameters.ManaDecayFactorEpochsSumExponent = manaDecayFactorEpochsSumExponent + p.basicProtocolParameters.ManaStructure.ManaBitsCount = manaBitsCount + p.basicProtocolParameters.ManaStructure.ManaGenerationRate = manaGenerationRate + p.basicProtocolParameters.ManaStructure.ManaGenerationRateExponent = manaGenerationRateExponent + p.basicProtocolParameters.ManaStructure.ManaDecayFactors = manaDecayFactors + p.basicProtocolParameters.ManaStructure.ManaDecayFactorsExponent = manaDecayFactorsExponent + p.basicProtocolParameters.ManaStructure.ManaDecayFactorEpochsSum = manaDecayFactorEpochsSum + p.basicProtocolParameters.ManaStructure.ManaDecayFactorEpochsSumExponent = manaDecayFactorEpochsSumExponent } } diff --git a/mana.go b/mana.go new file mode 100644 index 000000000..55dd0129f --- /dev/null +++ b/mana.go @@ -0,0 +1,31 @@ +package iotago + +import "github.com/iotaledger/hive.go/lo" + +// Mana Structure defines the parameters used in mana calculations. +type ManaStructure struct { + // ManaBitsCount is the number of bits used to represent Mana. + ManaBitsCount uint8 `serix:"0,mapKey=manaBitsCount"` + // ManaGenerationRate is the amount of potential Mana generated by 1 IOTA in 1 slot. + ManaGenerationRate uint8 `serix:"1,mapKey=manaGenerationRate"` + // ManaGenerationRateExponent is the scaling of ManaGenerationRate expressed as an exponent of 2. + ManaGenerationRateExponent uint8 `serix:"2,mapKey=manaGenerationRateExponent"` + // ManaDecayFactors is a lookup table of epoch index diff to mana decay factor (slice index 0 = 1 epoch). + ManaDecayFactors []uint32 `serix:"3,lengthPrefixType=uint16,mapKey=manaDecayFactors"` + // ManaDecayFactorsExponent is the scaling of ManaDecayFactors expressed as an exponent of 2. + ManaDecayFactorsExponent uint8 `serix:"4,mapKey=manaDecayFactorsExponent"` + // ManaDecayFactorEpochsSum is an integer approximation of the sum of decay over epochs. + ManaDecayFactorEpochsSum uint32 `serix:"5,mapKey=manaDecayFactorEpochsSum"` + // ManaDecayFactorEpochsSumExponent is the scaling of ManaDecayFactorEpochsSum expressed as an exponent of 2. + ManaDecayFactorEpochsSumExponent uint8 `serix:"6,mapKey=manaDecayFactorEpochsSumExponent"` +} + +func (m ManaStructure) Equals(other ManaStructure) bool { + return m.ManaBitsCount == other.ManaBitsCount && + m.ManaGenerationRate == other.ManaGenerationRate && + m.ManaGenerationRateExponent == other.ManaGenerationRateExponent && + lo.Equal(m.ManaDecayFactors, other.ManaDecayFactors) && + m.ManaDecayFactorsExponent == other.ManaDecayFactorsExponent && + m.ManaDecayFactorEpochsSum == other.ManaDecayFactorEpochsSum && + m.ManaDecayFactorEpochsSumExponent == other.ManaDecayFactorEpochsSumExponent +} diff --git a/mana_decay_provider.go b/mana_decay_provider.go index 352ceb868..cf5955fc7 100644 --- a/mana_decay_provider.go +++ b/mana_decay_provider.go @@ -55,6 +55,9 @@ type ManaDecayProvider struct { // (2**SlotsPerEpochExponent) == slots in an epoch. slotsPerEpochExponent uint64 + // bitsCount is the number of bits used to represent Mana. + bitsCount uint64 + // generationRate is the amount of potential Mana generated by 1 IOTA in 1 slot. generationRate uint64 // the generation rate needs to be scaled by 2^-generationRateExponent @@ -80,23 +83,19 @@ type ManaDecayProvider struct { func NewManaDecayProvider( timeProvider *TimeProvider, slotsPerEpochExponent uint8, - generationRate uint8, - generationRateExponent uint8, - decayFactors []uint32, - decayFactorsExponent uint8, - decayFactorEpochsSum uint32, - decayFactorEpochsSumExponent uint8, + manaStructure *ManaStructure, ) *ManaDecayProvider { return &ManaDecayProvider{ timeProvider: timeProvider, slotsPerEpochExponent: uint64(slotsPerEpochExponent), - generationRate: uint64(generationRate), - generationRateExponent: uint64(generationRateExponent), - decayFactors: lo.Map(decayFactors, func(factor uint32) uint64 { return uint64(factor) }), - decayFactorsLength: uint64(len(decayFactors)), - decayFactorsExponent: uint64(decayFactorsExponent), - decayFactorEpochsSum: uint64(decayFactorEpochsSum), - decayFactorEpochsSumExponent: uint64(decayFactorEpochsSumExponent), + bitsCount: uint64(manaStructure.ManaBitsCount), + generationRate: uint64(manaStructure.ManaGenerationRate), + generationRateExponent: uint64(manaStructure.ManaGenerationRateExponent), + decayFactors: lo.Map(manaStructure.ManaDecayFactors, func(factor uint32) uint64 { return uint64(factor) }), + decayFactorsLength: uint64(len(manaStructure.ManaDecayFactors)), + decayFactorsExponent: uint64(manaStructure.ManaDecayFactorsExponent), + decayFactorEpochsSum: uint64(manaStructure.ManaDecayFactorEpochsSum), + decayFactorEpochsSumExponent: uint64(manaStructure.ManaDecayFactorEpochsSumExponent), } } diff --git a/mana_decay_provider_test.go b/mana_decay_provider_test.go index 18227ed50..58fe48a31 100644 --- a/mana_decay_provider_test.go +++ b/mana_decay_provider_test.go @@ -16,6 +16,7 @@ const ( betaPerYear float64 = 1 / 3.0 slotsPerEpochExponent = 13 slotDurationSeconds = 10 + bitsCount = 63 generationRate = 1 generationRateExponent = 27 decayFactorsExponent = 32 @@ -38,7 +39,16 @@ func TestMain(m *testing.M) { testManaDecayFactorEpochsSum = tpkg.ManaDecayFactorEpochsSum(betaPerYear, 1< Date: Sat, 9 Sep 2023 16:26:30 +0100 Subject: [PATCH 6/7] Add MaxValidationBufferSize --- api_test.go | 5 +++-- api_v3_protocol_parameters.go | 5 +++-- nodeclient/apimodels/core_test.go | 2 +- rmc.go | 7 +++++-- tpkg/util.go | 1 + vm/stardust/vm_stardust_test.go | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/api_test.go b/api_test.go index 4a96bf78e..2e5a311db 100644 --- a/api_test.go +++ b/api_test.go @@ -130,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,"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,"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,"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) diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index 275f12ee1..24451ac71 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -34,7 +34,7 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr 21, ), WithLivenessOptions(3, 10, 20, 24), - WithCongestionControlOptions(1, 0, 0, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1, 100*MaxBlockSize), + WithCongestionControlOptions(1, 0, 0, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1, 1000, 100), WithStakingOptions(10, 10), WithVersionSignalingOptions(7, 5, 7), }, @@ -233,7 +233,7 @@ func WithLivenessOptions(livenessThreshold SlotIndex, minCommittableAge SlotInde } } -func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Mana, rmcIncreaseThreshold WorkScore, rmcDecreaseThreshold WorkScore, schedulerRate WorkScore, minMana Mana, maxBufferSize uint32) options.Option[V3ProtocolParameters] { +func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Mana, rmcIncreaseThreshold WorkScore, rmcDecreaseThreshold WorkScore, schedulerRate WorkScore, minMana Mana, maxBufferSize uint32, maxValBufferSize uint32) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.CongestionControlParameters.RMCMin = rmcMin p.basicProtocolParameters.CongestionControlParameters.Increase = rmcIncrease @@ -243,6 +243,7 @@ func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Man p.basicProtocolParameters.CongestionControlParameters.SchedulerRate = schedulerRate p.basicProtocolParameters.CongestionControlParameters.MinMana = minMana p.basicProtocolParameters.CongestionControlParameters.MaxBufferSize = maxBufferSize + p.basicProtocolParameters.CongestionControlParameters.MaxValidationBufferSize = maxValBufferSize } } diff --git a/nodeclient/apimodels/core_test.go b/nodeclient/apimodels/core_test.go index 8c39a46e9..b926ed2aa 100644 --- a/nodeclient/apimodels/core_test.go +++ b/nodeclient/apimodels/core_test.go @@ -61,7 +61,7 @@ func Test_InfoResponse(t *testing.T) { jsonResponse, err := api.JSONEncode(response) require.NoError(t, err) - expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100,\"vByteFactorDelegation\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaStructure\":{\"manaBitsCount\":63,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21},\"stakingUnbondingPeriod\":\"10\",\"validationBlocksPerSlot\":10,\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":3276800},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" + expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100,\"vByteFactorDelegation\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaStructure\":{\"manaBitsCount\":63,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21},\"stakingUnbondingPeriod\":\"10\",\"validationBlocksPerSlot\":10,\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":1000,\"maxValidationBufferSize\":100},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" require.Equal(t, expected, string(jsonResponse)) decoded := new(apimodels.InfoResponse) diff --git a/rmc.go b/rmc.go index 100dda652..6abdaf5db 100644 --- a/rmc.go +++ b/rmc.go @@ -17,8 +17,10 @@ type CongestionControlParameters struct { SchedulerRate WorkScore `serix:"5,mapKey=schedulerRate"` // MinMana is the minimum amount of Mana that an account must have to have a block scheduled. MinMana Mana `serix:"6,mapKey=minMana"` - // MaxBufferSize is the maximum size of the buffer. + // MaxBufferSize is the maximum number of blocks in the DRR buffer. MaxBufferSize uint32 `serix:"7,mapKey=maxBufferSize"` + // MaxValidaitonBufferSize is the maximum number of blocks in the validation buffer. + MaxValidationBufferSize uint32 `serix:"8,mapKey=maxValidationBufferSize"` } func (c *CongestionControlParameters) Equals(other CongestionControlParameters) bool { @@ -29,5 +31,6 @@ func (c *CongestionControlParameters) Equals(other CongestionControlParameters) c.DecreaseThreshold == other.DecreaseThreshold && c.SchedulerRate == other.SchedulerRate && c.MinMana == other.MinMana && - c.MaxBufferSize == other.MaxBufferSize + c.MaxBufferSize == other.MaxBufferSize && + c.MaxValidationBufferSize == other.MaxValidationBufferSize } diff --git a/tpkg/util.go b/tpkg/util.go index 3febbac54..6694a2552 100644 --- a/tpkg/util.go +++ b/tpkg/util.go @@ -790,6 +790,7 @@ func RandProtocolParameters() iotago.ProtocolParameters { RandWorkScore(math.MaxUint32), RandMana(math.MaxUint64), RandUint32(math.MaxUint32), + RandUint32(math.MaxUint32), ), ) } diff --git a/vm/stardust/vm_stardust_test.go b/vm/stardust/vm_stardust_test.go index e220680aa..aa62031ad 100644 --- a/vm/stardust/vm_stardust_test.go +++ b/vm/stardust/vm_stardust_test.go @@ -47,7 +47,7 @@ var ( ), iotago.WithStakingOptions(10, 10), iotago.WithLivenessOptions(3, 10, 20, 24), - iotago.WithCongestionControlOptions(500, 500, 500, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1, 100*iotago.MaxBlockSize), + iotago.WithCongestionControlOptions(500, 500, 500, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1, 1000, 100), ) testAPI = iotago.V3API(testProtoParams) From 76a815a68a071e7e4ddd1fa713a7c9f39c15a344 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 11 Sep 2023 16:49:00 +0100 Subject: [PATCH 7/7] Add PunishmentEpochs parameter to the protocol parameters --- api.go | 2 ++ api_protocol_parameters.go | 16 +++++++++------- api_test.go | 4 ++-- api_v3_protocol_parameters.go | 13 +++++++++---- nodeclient/apimodels/core_test.go | 2 +- vm/stardust/vm_stardust_test.go | 2 +- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/api.go b/api.go index 3643f52ff..1d17a8e65 100644 --- a/api.go +++ b/api.go @@ -121,6 +121,8 @@ type ProtocolParameters interface { ValidationBlocksPerSlot() uint16 + PunishmentEpochs() EpochIndex + LivenessThreshold() SlotIndex MinCommittableAge() SlotIndex diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index 6b4f395e3..4eb0c741f 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -29,26 +29,27 @@ 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"` + // 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:"12,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:"13,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:"14,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:"15,mapKey=epochNearingThreshold"` + EpochNearingThreshold SlotIndex `serix:"16,mapKey=epochNearingThreshold"` // RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC). - CongestionControlParameters CongestionControlParameters `serix:"16,mapKey=congestionControlParameters"` + CongestionControlParameters CongestionControlParameters `serix:"17,mapKey=congestionControlParameters"` - VersionSignaling VersionSignaling `serix:"17,mapKey=versionSignaling"` + VersionSignaling VersionSignaling `serix:"18,mapKey=versionSignaling"` } func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { @@ -64,6 +65,7 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { 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 && diff --git a/api_test.go b/api_test.go index 2e5a311db..9eb937180 100644 --- a/api_test.go +++ b/api_test.go @@ -115,7 +115,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) { 1337, 20, ), - iotago.WithStakingOptions(11, 10), + iotago.WithStakingOptions(11, 10, 9), iotago.WithLivenessOptions( 3, 10, @@ -136,7 +136,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,"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,"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}}` + 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) diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index 24451ac71..a01ab67fb 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -35,7 +35,7 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr ), WithLivenessOptions(3, 10, 20, 24), WithCongestionControlOptions(1, 0, 0, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1, 1000, 100), - WithStakingOptions(10, 10), + WithStakingOptions(10, 10, 10), WithVersionSignalingOptions(7, 5, 7), }, opts..., @@ -90,6 +90,10 @@ func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint16 { return p.basicProtocolParameters.ValidationBlocksPerSlot } +func (p *V3ProtocolParameters) PunishmentEpochs() EpochIndex { + return p.basicProtocolParameters.PunishmentEpochs +} + func (p *V3ProtocolParameters) LivenessThreshold() SlotIndex { return p.basicProtocolParameters.LivenessThreshold } @@ -128,8 +132,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 Structure: %v\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.ManaStructure, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.ValidationBlocksPerSlot, 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 Structure: %v\n\tStaking Unbonding Period: %d\n\tValidation Blocks per Slot: %d\n\tPunishment Epochs: %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.ManaStructure, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.ValidationBlocksPerSlot, p.basicProtocolParameters.PunishmentEpochs, p.basicProtocolParameters.LivenessThreshold, p.basicProtocolParameters.MinCommittableAge, p.basicProtocolParameters.MaxCommittableAge) } func (p *V3ProtocolParameters) ManaDecayProvider() *ManaDecayProvider { @@ -247,10 +251,11 @@ func WithCongestionControlOptions(rmcMin Mana, rmcIncrease Mana, rmcDecrease Man } } -func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint16) options.Option[V3ProtocolParameters] { +func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint16, punishmentEpochs EpochIndex) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod p.basicProtocolParameters.ValidationBlocksPerSlot = validationBlocksPerSlot + p.basicProtocolParameters.PunishmentEpochs = punishmentEpochs } } diff --git a/nodeclient/apimodels/core_test.go b/nodeclient/apimodels/core_test.go index b926ed2aa..1caacc775 100644 --- a/nodeclient/apimodels/core_test.go +++ b/nodeclient/apimodels/core_test.go @@ -61,7 +61,7 @@ func Test_InfoResponse(t *testing.T) { jsonResponse, err := api.JSONEncode(response) require.NoError(t, err) - expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100,\"vByteFactorDelegation\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaStructure\":{\"manaBitsCount\":63,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21},\"stakingUnbondingPeriod\":\"10\",\"validationBlocksPerSlot\":10,\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":1000,\"maxValidationBufferSize\":100},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" + expected := "{\"name\":\"test\",\"version\":\"2.0.0\",\"status\":{\"isHealthy\":false,\"acceptedTangleTime\":\"1690879505000000000\",\"relativeAcceptedTangleTime\":\"1690879505000000000\",\"confirmedTangleTime\":\"1690879505000000000\",\"relativeConfirmedTangleTime\":\"1690879505000000000\",\"latestCommitmentId\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"latestFinalizedSlot\":\"1\",\"latestAcceptedBlockSlot\":\"2\",\"latestConfirmedBlockSlot\":\"3\",\"pruningEpoch\":\"4\"},\"metrics\":{\"blocksPerSecond\":\"1.1E+00\",\"confirmedBlocksPerSecond\":\"2.2E+00\",\"confirmationRate\":\"3.3E+00\"},\"protocolParameters\":[{\"startEpoch\":\"0\",\"parameters\":{\"type\":0,\"version\":3,\"networkName\":\"testnet\",\"bech32Hrp\":\"rms\",\"rentStructure\":{\"vByteCost\":100,\"vByteFactorData\":1,\"vByteFactorKey\":10,\"vByteFactorIssuerKeys\":100,\"vByteFactorStakingFeature\":100,\"vByteFactorDelegation\":100},\"workScoreStructure\":{\"dataKilobyte\":0,\"block\":1,\"missingParent\":0,\"input\":0,\"contextInput\":0,\"output\":0,\"nativeToken\":0,\"staking\":0,\"blockIssuer\":0,\"allotment\":0,\"signatureEd25519\":0,\"minStrongParentsThreshold\":0},\"tokenSupply\":\"1813620509061365\",\"genesisUnixTimestamp\":\"1690879505\",\"slotDurationInSeconds\":10,\"slotsPerEpochExponent\":13,\"manaStructure\":{\"manaBitsCount\":63,\"manaGenerationRate\":1,\"manaGenerationRateExponent\":17,\"manaDecayFactors\":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],\"manaDecayFactorsExponent\":32,\"manaDecayFactorEpochsSum\":2420916375,\"manaDecayFactorEpochsSumExponent\":21},\"stakingUnbondingPeriod\":\"10\",\"validationBlocksPerSlot\":10,\"punishmentEpochs\":\"10\",\"livenessThreshold\":\"3\",\"minCommittableAge\":\"10\",\"maxCommittableAge\":\"20\",\"epochNearingThreshold\":\"24\",\"congestionControlParameters\":{\"rmcMin\":\"1\",\"increase\":\"0\",\"decrease\":\"0\",\"increaseThreshold\":800000,\"decreaseThreshold\":500000,\"schedulerRate\":100000,\"minMana\":\"1\",\"maxBufferSize\":1000,\"maxValidationBufferSize\":100},\"versionSignaling\":{\"windowSize\":7,\"windowTargetRatio\":5,\"activationOffset\":7}}}],\"baseToken\":{\"name\":\"Shimmer\",\"tickerSymbol\":\"SMR\",\"unit\":\"SMR\",\"subunit\":\"glow\",\"decimals\":6,\"useMetricPrefix\":false},\"features\":[\"test\"]}" require.Equal(t, expected, string(jsonResponse)) decoded := new(apimodels.InfoResponse) diff --git a/vm/stardust/vm_stardust_test.go b/vm/stardust/vm_stardust_test.go index aa62031ad..52dacf023 100644 --- a/vm/stardust/vm_stardust_test.go +++ b/vm/stardust/vm_stardust_test.go @@ -45,7 +45,7 @@ var ( tpkg.ManaDecayFactorEpochsSum(betaPerYear, 1<