-
Notifications
You must be signed in to change notification settings - Fork 95
/
api_v3_protocol_parameters.go
535 lines (450 loc) · 23.8 KB
/
api_v3_protocol_parameters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
package iotago
import (
"context"
"fmt"
"math"
"sync"
"time"
"github.com/iotaledger/hive.go/core/safemath"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/runtime/options"
)
// V3ProtocolParameters defines the parameters of the protocol.
type V3ProtocolParameters struct {
basicProtocolParameters `serix:""`
hashIdentifier Identifier
hashOnce sync.Once
bytes []byte
bytesMutex sync.Mutex
networkID NetworkID
networkIDOnce sync.Once
}
var _ ProtocolParameters = &V3ProtocolParameters{}
func (p *V3ProtocolParameters) Version() Version {
return p.basicProtocolParameters.Version
}
func (p *V3ProtocolParameters) Bech32HRP() NetworkPrefix {
return p.basicProtocolParameters.Bech32HRP
}
func (p *V3ProtocolParameters) NetworkName() string {
return p.basicProtocolParameters.NetworkName
}
func (p *V3ProtocolParameters) StorageScoreParameters() *StorageScoreParameters {
return &p.basicProtocolParameters.StorageScoreParameters
}
func (p *V3ProtocolParameters) WorkScoreParameters() *WorkScoreParameters {
return &p.basicProtocolParameters.WorkScoreParameters
}
func (p *V3ProtocolParameters) ManaParameters() *ManaParameters {
return &p.basicProtocolParameters.ManaParameters
}
func (p *V3ProtocolParameters) TokenSupply() BaseToken {
return p.basicProtocolParameters.TokenSupply
}
func (p *V3ProtocolParameters) NetworkID() NetworkID {
p.networkIDOnce.Do(func() {
p.networkID = NetworkIDFromString(p.basicProtocolParameters.NetworkName)
})
return p.networkID
}
// GenesisBlockID defines the block ID of the genesis block.
func (p *V3ProtocolParameters) GenesisBlockID() BlockID {
return NewBlockID(p.basicProtocolParameters.GenesisSlot, EmptyIdentifier)
}
// GenesisSlot defines the genesis slot.
func (p *V3ProtocolParameters) GenesisSlot() SlotIndex {
return p.basicProtocolParameters.GenesisSlot
}
// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
func (p *V3ProtocolParameters) GenesisUnixTimestamp() int64 {
return p.basicProtocolParameters.GenesisUnixTimestamp
}
// SlotDurationInSeconds defines the duration of each slot in seconds.
func (p *V3ProtocolParameters) SlotDurationInSeconds() uint8 {
return p.basicProtocolParameters.SlotDurationInSeconds
}
// SlotsPerEpochExponent is the number of slots in an epoch expressed as an exponent of 2.
func (p *V3ProtocolParameters) SlotsPerEpochExponent() uint8 {
return p.basicProtocolParameters.SlotsPerEpochExponent
}
// ParamEpochDurationInSlots defines the amount of slots in an epoch.
func (p *V3ProtocolParameters) ParamEpochDurationInSlots() SlotIndex {
return 1 << p.basicProtocolParameters.SlotsPerEpochExponent
}
func (p *V3ProtocolParameters) StakingUnbondingPeriod() EpochIndex {
return p.basicProtocolParameters.StakingUnbondingPeriod
}
func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint8 {
return p.basicProtocolParameters.ValidationBlocksPerSlot
}
func (p *V3ProtocolParameters) PunishmentEpochs() EpochIndex {
return p.basicProtocolParameters.PunishmentEpochs
}
func (p *V3ProtocolParameters) LivenessThresholdLowerBound() time.Duration {
return time.Duration(p.basicProtocolParameters.LivenessThresholdLowerBoundInSeconds) * time.Second
}
func (p *V3ProtocolParameters) LivenessThresholdUpperBound() time.Duration {
return time.Duration(p.basicProtocolParameters.LivenessThresholdUpperBoundInSeconds) * time.Second
}
func (p *V3ProtocolParameters) MinCommittableAge() SlotIndex {
return p.basicProtocolParameters.MinCommittableAge
}
func (p *V3ProtocolParameters) MaxCommittableAge() SlotIndex {
return p.basicProtocolParameters.MaxCommittableAge
}
func (p *V3ProtocolParameters) EpochNearingThreshold() SlotIndex {
return p.basicProtocolParameters.EpochNearingThreshold
}
func (p *V3ProtocolParameters) CongestionControlParameters() *CongestionControlParameters {
return &p.basicProtocolParameters.CongestionControlParameters
}
func (p *V3ProtocolParameters) VersionSignalingParameters() *VersionSignalingParameters {
return &p.basicProtocolParameters.VersionSignalingParameters
}
func (p *V3ProtocolParameters) RewardsParameters() *RewardsParameters {
return &p.basicProtocolParameters.RewardsParameters
}
func (p *V3ProtocolParameters) TargetCommitteeSize() uint8 {
return p.basicProtocolParameters.TargetCommitteeSize
}
func (p *V3ProtocolParameters) ChainSwitchingThreshold() uint8 {
return p.basicProtocolParameters.ChainSwitchingThreshold
}
func (p *V3ProtocolParameters) Bytes() ([]byte, error) {
if len(p.bytes) > 0 {
return p.bytes, nil
}
p.bytesMutex.Lock()
defer p.bytesMutex.Unlock()
// Check if some other goroutine cached the bytes while waiting for the lock.
if len(p.bytes) > 0 {
return p.bytes, nil
}
bytes, err := CommonSerixAPI().Encode(context.TODO(), p)
if err != nil {
return nil, err
}
p.bytes = bytes
return p.bytes, nil
}
func (p *V3ProtocolParameters) Hash() (Identifier, error) {
bytes, err := p.Bytes()
if err != nil {
return Identifier{}, err
}
p.hashOnce.Do(func() {
p.hashIdentifier = IdentifierFromData(bytes)
})
return p.hashIdentifier, nil
}
func (p *V3ProtocolParameters) String() string {
return fmt.Sprintf("ProtocolParameters: {\n\tVersion: %d\n\tNetwork Name: %s\n\tBech32 HRP Prefix: %s\n\tStorageScore Structure: %v\n\tWorkScore Structure: %v\n\tMana Structure: %v\n\tToken Supply: %d\n\tGenesis Slot: %d\n\tGenesis Unix Timestamp: %d\n\tSlot Duration in Seconds: %d\n\tSlots per Epoch Exponent: %d\n\tStaking Unbonding Period: %d\n\tValidation Blocks per Slot: %d\n\tPunishment Epochs: %d\n\tLiveness Threshold Lower Bound: %d\n\tLiveness Threshold Upper Bound: %d\n\tMin Committable Age: %d\n\tMax Committable Age: %d\n\tEpoch Nearing Threshold: %d\n\tCongestion Control parameters: %v\n\tVersion Signaling: %v\n\tRewardsParameters: %v\n",
p.basicProtocolParameters.Version,
p.basicProtocolParameters.NetworkName,
p.basicProtocolParameters.Bech32HRP,
p.basicProtocolParameters.StorageScoreParameters,
p.basicProtocolParameters.WorkScoreParameters,
p.basicProtocolParameters.ManaParameters,
p.basicProtocolParameters.TokenSupply,
p.basicProtocolParameters.GenesisSlot,
p.basicProtocolParameters.GenesisUnixTimestamp,
p.basicProtocolParameters.SlotDurationInSeconds,
p.basicProtocolParameters.SlotsPerEpochExponent,
p.basicProtocolParameters.StakingUnbondingPeriod,
p.basicProtocolParameters.ValidationBlocksPerSlot,
p.basicProtocolParameters.PunishmentEpochs,
p.basicProtocolParameters.LivenessThresholdLowerBoundInSeconds,
p.basicProtocolParameters.LivenessThresholdUpperBoundInSeconds,
p.basicProtocolParameters.MinCommittableAge,
p.basicProtocolParameters.MaxCommittableAge,
p.basicProtocolParameters.EpochNearingThreshold,
p.basicProtocolParameters.CongestionControlParameters,
p.basicProtocolParameters.VersionSignalingParameters,
p.basicProtocolParameters.RewardsParameters,
)
}
func (p *V3ProtocolParameters) Equals(other ProtocolParameters) bool {
otherV3Params, matches := other.(*V3ProtocolParameters)
if !matches {
return false
}
return p.basicProtocolParameters.Equals(otherV3Params.basicProtocolParameters)
}
// NewV3SnapshotProtocolParameters creates a new V3ProtocolParameters instance with the given options.
// IMPORTANT: this function should only be used to derive new protocol params for genesis snapshots or tests because it uses
// floating point arithmetic to derive mana decay factors and decay factor epochs sum.
// This might result in different parameters on different machines.
func NewV3SnapshotProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3ProtocolParameters {
newProtocolParams := options.Apply(
new(V3ProtocolParameters),
append([]options.Option[V3ProtocolParameters]{
WithVersion(apiV3Version),
WithNetworkOptions("testnet", PrefixTestnet),
WithStorageOptions(100, 1, 10, 100, 100, 100),
WithWorkScoreOptions(500, 110_000, 7_500, 40_000, 90_000, 50_000, 40_000, 70_000, 5_000, 15_000),
WithTimeProviderOptions(0, time.Now().Unix(), 10, 13),
WithLivenessOptions(15, 30, 10, 20, 60),
WithSupplyOptions(1813620509061365, 63, 1, 17, 32, 21, 70),
WithCongestionControlOptions(1, 1, 1, 400_000_000, 250_000_000, 50_000_000, 1000, 100),
WithStakingOptions(10, 10, 10),
WithVersionSignalingOptions(7, 5, 7),
WithRewardsOptions(8, 11, 2, 384),
WithTargetCommitteeSize(32),
WithChainSwitchingThreshold(3),
},
opts...,
),
)
// Compute derived parameters
newProtocolParams.basicProtocolParameters.ManaParameters.DecayFactors = deriveManaDecayFactors(
newProtocolParams.ManaParameters().AnnualDecayFactorPercentage,
newProtocolParams.SlotsPerEpochExponent(),
newProtocolParams.SlotDurationInSeconds(),
newProtocolParams.ManaParameters().DecayFactorsExponent,
)
newProtocolParams.basicProtocolParameters.ManaParameters.DecayFactorEpochsSum = deriveManaDecayFactorEpochsSum(
newProtocolParams.ManaParameters().AnnualDecayFactorPercentage,
newProtocolParams.SlotsPerEpochExponent(),
newProtocolParams.SlotDurationInSeconds(),
newProtocolParams.ManaParameters().DecayFactorEpochsSumExponent,
)
newProtocolParams.basicProtocolParameters.RewardsParameters.BootstrappingDuration = deriveBootstrappingDuration(
newProtocolParams.ManaParameters().AnnualDecayFactorPercentage,
newProtocolParams.SlotsPerEpochExponent(),
newProtocolParams.SlotDurationInSeconds(),
)
initialTargetRewardsRate, finalTargetRewardsRate := deriveTargetRewardsRates(newProtocolParams)
newProtocolParams.basicProtocolParameters.RewardsParameters.InitialTargetRewardsRate = initialTargetRewardsRate
newProtocolParams.basicProtocolParameters.RewardsParameters.FinalTargetRewardsRate = finalTargetRewardsRate
// Sanity checks
manaSupplySanityCheck(newProtocolParams)
timeSanityCheck(newProtocolParams)
congestionControlSanityCheck(newProtocolParams)
stakingSanityCheck(newProtocolParams)
return newProtocolParams
}
// deriveManaDecayFactors computes a lookup table of mana decay factors using floating point arithmetic.
func deriveManaDecayFactors(annualDecayFactorPercentage uint8, slotsPerEpochExponent uint8, slotDurationSeconds uint8, decayFactorsExponent uint8) []uint32 {
epochsPerYear := ((365.0 * 24.0 * 60.0 * 60.0) / float64(slotDurationSeconds)) / math.Pow(2, float64(slotsPerEpochExponent))
epochsInTable := lo.Min(65535, int(epochsPerYear))
decayFactors := make([]uint32, epochsInTable)
decayFactorPerEpoch := math.Pow(float64(annualDecayFactorPercentage)/100.0, 1.0/epochsPerYear)
for epoch := 1; epoch <= epochsInTable; epoch++ {
decayFactor := math.Pow(decayFactorPerEpoch, float64(epoch)) * (math.Pow(2, float64(decayFactorsExponent)))
decayFactors[epoch-1] = uint32(decayFactor)
}
return decayFactors
}
// deriveManaDecayFactorEpochsSum computes mana decay factor epochs sum parameter using floating point arithmetic.
func deriveManaDecayFactorEpochsSum(annualDecayFactorPercentage uint8, slotsPerEpochExponent uint8, slotDurationSeconds uint8, decayFactorEpochsSumExponent uint8) uint32 {
delta := math.Pow(2, float64(slotsPerEpochExponent)) * (1.0 / (365.0 * 24.0 * 60.0 * 60.0)) * float64(slotDurationSeconds)
annualDecayFactor := float64(annualDecayFactorPercentage) / 100.0
return uint32((math.Pow(annualDecayFactor, delta) / (1 - math.Pow(annualDecayFactor, delta)) * (math.Pow(2, float64(decayFactorEpochsSumExponent)))))
}
// deriveBootstrappingDuration computes the bootstrapping duration using floating point arithmetic.
func deriveBootstrappingDuration(annualDecayFactorPercentage uint8, slotsPerEpochExponent uint8, slotDurationSeconds uint8) EpochIndex {
epochsPerYear := (365.0 * 24.0 * 60.0 * 60.0) / (math.Pow(2, float64(slotsPerEpochExponent)) * float64(slotDurationSeconds))
annualDecayFactor := float64(annualDecayFactorPercentage) / 100.0
beta := -math.Log(annualDecayFactor)
return EpochIndex(epochsPerYear / beta)
}
func deriveTargetRewardsRates(protoParams ProtocolParameters) (Mana, Mana) {
// final reward, after bootstrapping phase
result, err := safemath.SafeMul(uint64(protoParams.TokenSupply()), uint64(protoParams.RewardsParameters().RewardToGenerationRatio))
if err != nil {
panic("failed to calculate target reward due to tokenSupply and rewardToGenerationRatio multiplication overflow")
}
result, err = safemath.SafeMul(result, uint64(protoParams.ManaParameters().GenerationRate))
if err != nil {
panic("failed to calculate target reward due to multiplication with generationRate overflow")
}
subExponent, err := safemath.SafeSub(protoParams.ManaParameters().GenerationRateExponent, protoParams.SlotsPerEpochExponent())
if err != nil {
panic("failed to calculate target reward due to generationRateExponent - slotsPerEpochExponent subtraction overflow")
}
finalTargetRewardsRate := result >> subExponent
// delta represents the epoch duration in years, beta is a constant 1/3 and T is the bootstrapping duration in epochs.
epochDurationInYears := float64(protoParams.SlotDurationInSeconds()) * math.Pow(2.0, float64(protoParams.SlotsPerEpochExponent())) / (365 * 24 * 60 * 60)
annualDecayFactor := float64(protoParams.ManaParameters().AnnualDecayFactorPercentage) / 100.0
bootstrappingDurationInYears := float64(protoParams.RewardsParameters().BootstrappingDuration) * epochDurationInYears
decayBalancingConstant := 1 / math.Pow(annualDecayFactor, bootstrappingDurationInYears)
initialTargetRewardsRate := float64(finalTargetRewardsRate) * decayBalancingConstant
return Mana(initialTargetRewardsRate), Mana(finalTargetRewardsRate)
}
func manaSupplySanityCheck(protocolParams *V3ProtocolParameters) {
beta := -math.Log(float64(protocolParams.ManaParameters().AnnualDecayFactorPercentage) / 100.0)
epochDurationInYears := float64(protocolParams.SlotDurationInSeconds()) * math.Pow(2.0, float64(protocolParams.SlotsPerEpochExponent())) / (365 * 24 * 60 * 60)
maxManaSupply := 21.0 * float64(protocolParams.TokenSupply()) * float64(protocolParams.ManaParameters().GenerationRate) * math.Pow(2.0, float64(protocolParams.SlotsPerEpochExponent())-float64(protocolParams.ManaParameters().GenerationRateExponent)) / (beta * epochDurationInYears)
if maxManaSupply >= math.Pow(2.0, float64(protocolParams.ManaParameters().BitsCount)) {
panic("the combination of parameters might lead to overflowing of the Mana supply")
}
// this check is specific to the way decay is calculated to prevent overflow
if _, err := safemath.SafeMul(protocolParams.ManaParameters().DecayFactorEpochsSum, uint32(protocolParams.ManaParameters().GenerationRate)); err != nil {
panic("decayFactorEpochsSum * generationRate must not require more than 32 bits")
}
}
func timeSanityCheck(protocolParams *V3ProtocolParameters) {
if protocolParams.LivenessThresholdLowerBoundInSeconds > protocolParams.LivenessThresholdUpperBoundInSeconds {
panic("LivenessThresholdLowerBoundInSeconds must be less than or equal to LivenessThresholdUpperBoundInSeconds")
}
if SlotIndex(protocolParams.LivenessThresholdUpperBoundInSeconds) >= protocolParams.MinCommittableAge()*SlotIndex(protocolParams.SlotDurationInSeconds()) {
panic("LivenessThresholdUpperBoundInSeconds must be strictly less than MinCommittableAge * SlotDurationInSeconds")
}
if protocolParams.MinCommittableAge() >= protocolParams.MaxCommittableAge() {
panic("MinCommittableAge must be strictly less than MaxCommittableAge")
}
if protocolParams.MaxCommittableAge() >= protocolParams.EpochNearingThreshold() {
panic("MaxCommittableAge must be strictly less than EpochNearingThreshold")
}
if (1 << protocolParams.SlotsPerEpochExponent()) <= protocolParams.EpochNearingThreshold() {
panic("Epoch duration in slots must be strictly greater than EpochNearingThreshold")
}
// TODO: add warning level log for EpochNearingThreshold > 2 * MaxCommittableAge and EpochsPerSlot > 2 * EpochNearingThreshold
}
func congestionControlSanityCheck(protocolParams *V3ProtocolParameters) {
if protocolParams.CongestionControlParameters().IncreaseThreshold > WorkScore(protocolParams.SlotDurationInSeconds())*protocolParams.CongestionControlParameters().SchedulerRate {
fmt.Printf("IncreaseThreshold: %d, SchedulerRate: %d, SlotDurationSeconds: %d\n", protocolParams.CongestionControlParameters().IncreaseThreshold, protocolParams.CongestionControlParameters().SchedulerRate, protocolParams.SlotDurationInSeconds())
panic("IncreaseThreshold must be less than or equal to SchedulerRate*SlotDurationInSeconds")
}
if protocolParams.CongestionControlParameters().DecreaseThreshold > WorkScore(protocolParams.SlotDurationInSeconds())*protocolParams.CongestionControlParameters().SchedulerRate {
panic("DecreaseThreshold must be less than or equal to SchedulerRate*SlotDurationInSeconds")
}
if protocolParams.CongestionControlParameters().DecreaseThreshold > protocolParams.CongestionControlParameters().IncreaseThreshold {
panic("DecreaseThreshold must be less than or equal to IncreaseThreshold")
}
}
func stakingSanityCheck(protocolParams *V3ProtocolParameters) {
tokenSupplyBitsCount := uint8(math.Log2(float64(protocolParams.TokenSupply()))) + 1
poolCoefficientExponent := protocolParams.RewardsParameters().PoolCoefficientExponent
if poolCoefficientExponent > 64 || tokenSupplyBitsCount+poolCoefficientExponent > 64 {
message := fmt.Sprintf("Token supply bits count (%d) + PoolCoefficientExponent (%d) must be less than or equal to 64\n", tokenSupplyBitsCount, protocolParams.RewardsParameters().PoolCoefficientExponent)
panic(message)
}
if protocolParams.ValidationBlocksPerSlot() > 32 {
panic("ValidationBlocksPerSlot must be less than or equal to 32")
}
}
func WithVersion(version Version) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.Version = version
}
}
func WithStorageOptions(storageCost BaseToken, factorData StorageScoreFactor, offsetOutputOverhead, offsetEd25519BlockIssuerKey, offsetStakingFeature, offsetDelegation StorageScore) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.StorageScoreParameters = StorageScoreParameters{
StorageCost: storageCost,
FactorData: factorData,
OffsetOutputOverhead: offsetOutputOverhead,
OffsetEd25519BlockIssuerKey: offsetEd25519BlockIssuerKey,
OffsetStakingFeature: offsetStakingFeature,
OffsetDelegation: offsetDelegation,
}
}
}
func WithWorkScoreOptions(
dataByte WorkScore,
block WorkScore,
input WorkScore,
contextInput WorkScore,
output WorkScore,
nativeToken WorkScore,
staking WorkScore,
blockIssuer WorkScore,
allotment WorkScore,
signatureEd25519 WorkScore,
) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.WorkScoreParameters = WorkScoreParameters{
DataByte: dataByte,
Block: block,
Input: input,
ContextInput: contextInput,
Output: output,
NativeToken: nativeToken,
Staking: staking,
BlockIssuer: blockIssuer,
Allotment: allotment,
SignatureEd25519: signatureEd25519,
}
}
}
func WithSupplyOptions(baseTokenSupply BaseToken, bitsCount uint8, generationRate uint8, generationRateExponent uint8, decayFactorsExponent uint8, decayFactorEpochsSumExponent uint8, annualDecayFactorPercentage uint8) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.TokenSupply = baseTokenSupply
p.basicProtocolParameters.ManaParameters.BitsCount = bitsCount
p.basicProtocolParameters.ManaParameters.GenerationRate = generationRate
p.basicProtocolParameters.ManaParameters.GenerationRateExponent = generationRateExponent
p.basicProtocolParameters.ManaParameters.DecayFactorsExponent = decayFactorsExponent
p.basicProtocolParameters.ManaParameters.DecayFactorEpochsSumExponent = decayFactorEpochsSumExponent
p.basicProtocolParameters.ManaParameters.AnnualDecayFactorPercentage = annualDecayFactorPercentage
}
}
func WithTimeProviderOptions(genesisSlot SlotIndex, genesisTimestamp int64, slotDurationInSeconds uint8, slotsPerEpochExponent uint8) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.GenesisSlot = genesisSlot
p.basicProtocolParameters.GenesisUnixTimestamp = genesisTimestamp
p.basicProtocolParameters.SlotDurationInSeconds = slotDurationInSeconds
p.basicProtocolParameters.SlotsPerEpochExponent = slotsPerEpochExponent
}
}
func WithLivenessOptions(livenessThresholdLowerBoundInSeconds uint16, livenessThresholdUpperBoundInSeconds uint16, minCommittableAge SlotIndex, maxCommittableAge SlotIndex, epochNearingThreshold SlotIndex) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.LivenessThresholdLowerBoundInSeconds = livenessThresholdLowerBoundInSeconds
p.basicProtocolParameters.LivenessThresholdUpperBoundInSeconds = livenessThresholdUpperBoundInSeconds
p.basicProtocolParameters.MinCommittableAge = minCommittableAge
p.basicProtocolParameters.MaxCommittableAge = maxCommittableAge
p.basicProtocolParameters.EpochNearingThreshold = epochNearingThreshold
}
}
func WithCongestionControlOptions(minReferenceManaCost Mana, rmcIncrease Mana, rmcDecrease Mana, rmcIncreaseThreshold WorkScore, rmcDecreaseThreshold WorkScore, schedulerRate WorkScore, maxBufferSize uint32, maxValBufferSize uint32) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.CongestionControlParameters.MinReferenceManaCost = minReferenceManaCost
p.basicProtocolParameters.CongestionControlParameters.Increase = rmcIncrease
p.basicProtocolParameters.CongestionControlParameters.Decrease = rmcDecrease
p.basicProtocolParameters.CongestionControlParameters.IncreaseThreshold = rmcIncreaseThreshold
p.basicProtocolParameters.CongestionControlParameters.DecreaseThreshold = rmcDecreaseThreshold
p.basicProtocolParameters.CongestionControlParameters.SchedulerRate = schedulerRate
p.basicProtocolParameters.CongestionControlParameters.MaxBufferSize = maxBufferSize
p.basicProtocolParameters.CongestionControlParameters.MaxValidationBufferSize = maxValBufferSize
}
}
func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint8, punishmentEpochs EpochIndex) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod
p.basicProtocolParameters.ValidationBlocksPerSlot = validationBlocksPerSlot
p.basicProtocolParameters.PunishmentEpochs = punishmentEpochs
}
}
func WithVersionSignalingOptions(windowSize uint8, windowTargetRatio uint8, activationOffset uint8) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.VersionSignalingParameters = VersionSignalingParameters{
WindowSize: windowSize,
WindowTargetRatio: windowTargetRatio,
ActivationOffset: activationOffset,
}
}
}
func WithRewardsOptions(profitMarginExponent, poolCoefficientExponent, rewardToGenerationRatio uint8, retentionPeriod uint16) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.RewardsParameters.ProfitMarginExponent = profitMarginExponent
p.basicProtocolParameters.RewardsParameters.RewardToGenerationRatio = rewardToGenerationRatio
p.basicProtocolParameters.RewardsParameters.PoolCoefficientExponent = poolCoefficientExponent
p.basicProtocolParameters.RewardsParameters.RetentionPeriod = retentionPeriod
}
}
func WithTargetCommitteeSize(targetCommitteeSize uint8) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.TargetCommitteeSize = targetCommitteeSize
}
}
func WithNetworkOptions(networkName string, hrp NetworkPrefix) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.NetworkName = networkName
p.basicProtocolParameters.Bech32HRP = hrp
}
}
func WithChainSwitchingThreshold(chainSwitchingThreshold uint8) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.ChainSwitchingThreshold = chainSwitchingThreshold
}
}