Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 03a1348

Browse files
committed
Added GenesisSlot to the protocol parameters
1 parent 578f582 commit 03a1348

File tree

8 files changed

+41
-28
lines changed

8 files changed

+41
-28
lines changed

api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ type ProtocolParameters interface {
110110
NetworkID() NetworkID
111111
// Bech32HRP defines the HRP prefix used for Bech32 addresses in the network.
112112
Bech32HRP() NetworkPrefix
113-
// StorageScoreStructure defines the storage score structure used by the given network.
113+
// StorageScoreParameters defines the storage score structure used by the given network.
114114
StorageScoreParameters() *StorageScoreParameters
115115
// WorkScoreParameters defines the work score parameters used by the given network.
116116
WorkScoreParameters() *WorkScoreParameters
@@ -119,6 +119,8 @@ type ProtocolParameters interface {
119119
// TokenSupply defines the current token supply on the network.
120120
TokenSupply() BaseToken
121121

122+
// GenesisSlot defines the slot of the genesis.
123+
GenesisSlot() SlotIndex
122124
// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
123125
GenesisUnixTimestamp() int64
124126
// SlotDurationInSeconds defines the duration of each slot in seconds.

api_protocol_parameters.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,45 @@ type basicProtocolParameters struct {
1919
// TokenSupply defines the current token supply on the network.
2020
TokenSupply BaseToken `serix:"6,mapKey=tokenSupply"`
2121

22+
// GenesisSlot defines the slot of the genesis.
23+
GenesisSlot SlotIndex `serix:"7,mapKey=genesisSlot"`
2224
// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
23-
GenesisUnixTimestamp int64 `serix:"7,mapKey=genesisUnixTimestamp"`
25+
GenesisUnixTimestamp int64 `serix:"8,mapKey=genesisUnixTimestamp"`
2426
// SlotDurationInSeconds defines the duration of each slot in seconds.
25-
SlotDurationInSeconds uint8 `serix:"8,mapKey=slotDurationInSeconds"`
27+
SlotDurationInSeconds uint8 `serix:"9,mapKey=slotDurationInSeconds"`
2628
// SlotsPerEpochExponent is the number of slots in an epoch expressed as an exponent of 2.
2729
// (2**SlotsPerEpochExponent) == slots in an epoch.
28-
SlotsPerEpochExponent uint8 `serix:"9,mapKey=slotsPerEpochExponent"`
30+
SlotsPerEpochExponent uint8 `serix:"10,mapKey=slotsPerEpochExponent"`
2931

3032
// StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking.
31-
StakingUnbondingPeriod EpochIndex `serix:"10,mapKey=stakingUnbondingPeriod"`
33+
StakingUnbondingPeriod EpochIndex `serix:"11,mapKey=stakingUnbondingPeriod"`
3234
// ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot.
33-
ValidationBlocksPerSlot uint8 `serix:"11,mapKey=validationBlocksPerSlot"`
35+
ValidationBlocksPerSlot uint8 `serix:"12,mapKey=validationBlocksPerSlot"`
3436
// PunishmentEpochs is the number of epochs worth of Mana that a node is punished with for each additional validation block it issues.
35-
PunishmentEpochs EpochIndex `serix:"12,mapKey=punishmentEpochs"`
37+
PunishmentEpochs EpochIndex `serix:"13,mapKey=punishmentEpochs"`
3638

3739
// LivenessThresholdLowerBound is used by tip-selection to determine if a block is eligible by evaluating issuingTimes.
3840
// and commitments in its past-cone to ATT and lastCommittedSlot respectively.
39-
LivenessThresholdLowerBoundInSeconds uint16 `serix:"13,mapKey=livenessThresholdLowerBound"`
41+
LivenessThresholdLowerBoundInSeconds uint16 `serix:"14,mapKey=livenessThresholdLowerBound"`
4042
// LivenessThresholdUpperBound is used by tip-selection to determine if a block is eligible by evaluating issuingTimes
4143
// and commitments in its past-cone to ATT and lastCommittedSlot respectively.
42-
LivenessThresholdUpperBoundInSeconds uint16 `serix:"14,mapKey=livenessThresholdUpperBound"`
44+
LivenessThresholdUpperBoundInSeconds uint16 `serix:"15,mapKey=livenessThresholdUpperBound"`
4345

4446
// MinCommittableAge is the minimum age relative to the accepted tangle time slot index that a slot can be committed.
4547
// 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.
46-
MinCommittableAge SlotIndex `serix:"15,mapKey=minCommittableAge"`
48+
MinCommittableAge SlotIndex `serix:"16,mapKey=minCommittableAge"`
4749
// 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.
4850
// For example, if the last accepted slot is in slot 100, and maxCommittableAge=20, then the oldest referencable commitment is 100-20=80.
49-
MaxCommittableAge SlotIndex `serix:"16,mapKey=maxCommittableAge"`
51+
MaxCommittableAge SlotIndex `serix:"17,mapKey=maxCommittableAge"`
5052
// EpochNearingThreshold is used by the epoch orchestrator to detect the slot that should trigger a new committee
5153
// selection for the next and upcoming epoch.
52-
EpochNearingThreshold SlotIndex `serix:"17,mapKey=epochNearingThreshold"`
54+
EpochNearingThreshold SlotIndex `serix:"18,mapKey=epochNearingThreshold"`
5355
// RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC).
54-
CongestionControlParameters CongestionControlParameters `serix:"18,mapKey=congestionControlParameters"`
56+
CongestionControlParameters CongestionControlParameters `serix:"19,mapKey=congestionControlParameters"`
5557
// VersionSignaling defines the parameters used for version upgrades.
56-
VersionSignaling VersionSignaling `serix:"19,mapKey=versionSignaling"`
58+
VersionSignaling VersionSignaling `serix:"20,mapKey=versionSignaling"`
5759
// RewardsParameters defines the parameters used for reward calculation.
58-
RewardsParameters RewardsParameters `serix:"20,mapKey=rewardsParameters"`
60+
RewardsParameters RewardsParameters `serix:"21,mapKey=rewardsParameters"`
5961
}
6062

6163
func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
@@ -66,6 +68,7 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
6668
b.WorkScoreParameters.Equals(other.WorkScoreParameters) &&
6769
b.ManaParameters.Equals(other.ManaParameters) &&
6870
b.TokenSupply == other.TokenSupply &&
71+
b.GenesisSlot == other.GenesisSlot &&
6972
b.GenesisUnixTimestamp == other.GenesisUnixTimestamp &&
7073
b.SlotDurationInSeconds == other.SlotDurationInSeconds &&
7174
b.SlotsPerEpochExponent == other.SlotsPerEpochExponent &&

api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
100100
10,
101101
),
102102
iotago.WithTimeProviderOptions(
103+
654978,
103104
1681373293,
104105
10,
105106
13,
@@ -135,7 +136,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
135136
iotago.WithRewardsOptions(8, 8, 31, 1154, 2, 1),
136137
)
137138

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

140141
jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
141142
require.NoError(t, err)

api_v3_protocol_parameters.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr
2222
WithNetworkOptions("testnet", PrefixTestnet),
2323
WithSupplyOptions(1813620509061365, 100, 1, 10, 100, 100, 100),
2424
WithWorkScoreOptions(0, 1, 0, 0, 0, 0, 0, 0, 0, 0),
25-
WithTimeProviderOptions(time.Now().Unix(), 10, 13),
25+
WithTimeProviderOptions(0, time.Now().Unix(), 10, 13),
2626
WithManaOptions(63,
2727
1,
2828
17,
@@ -79,6 +79,11 @@ func (p *V3ProtocolParameters) NetworkID() NetworkID {
7979
return NetworkIDFromString(p.basicProtocolParameters.NetworkName)
8080
}
8181

82+
// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
83+
func (p *V3ProtocolParameters) GenesisSlot() SlotIndex {
84+
return p.basicProtocolParameters.GenesisSlot
85+
}
86+
8287
// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
8388
func (p *V3ProtocolParameters) GenesisUnixTimestamp() int64 {
8489
return p.basicProtocolParameters.GenesisUnixTimestamp
@@ -159,14 +164,15 @@ func (p *V3ProtocolParameters) Hash() (Identifier, error) {
159164
}
160165

161166
func (p *V3ProtocolParameters) String() string {
162-
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 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",
167+
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",
163168
p.basicProtocolParameters.Version,
164169
p.basicProtocolParameters.NetworkName,
165170
p.basicProtocolParameters.Bech32HRP,
166171
p.basicProtocolParameters.StorageScoreParameters,
167172
p.basicProtocolParameters.WorkScoreParameters,
168173
p.basicProtocolParameters.ManaParameters,
169174
p.basicProtocolParameters.TokenSupply,
175+
p.basicProtocolParameters.GenesisSlot,
170176
p.basicProtocolParameters.GenesisUnixTimestamp,
171177
p.basicProtocolParameters.SlotDurationInSeconds,
172178
p.basicProtocolParameters.SlotsPerEpochExponent,
@@ -260,8 +266,9 @@ func WithManaOptions(bitsCount uint8, generationRate uint8, generationRateExpone
260266
}
261267
}
262268

263-
func WithTimeProviderOptions(genesisTimestamp int64, slotDurationInSeconds uint8, slotsPerEpochExponent uint8) options.Option[V3ProtocolParameters] {
269+
func WithTimeProviderOptions(genesisSlot SlotIndex, genesisTimestamp int64, slotDurationInSeconds uint8, slotsPerEpochExponent uint8) options.Option[V3ProtocolParameters] {
264270
return func(p *V3ProtocolParameters) {
271+
p.basicProtocolParameters.GenesisSlot = genesisSlot
265272
p.basicProtocolParameters.GenesisUnixTimestamp = genesisTimestamp
266273
p.basicProtocolParameters.SlotDurationInSeconds = slotDurationInSeconds
267274
p.basicProtocolParameters.SlotsPerEpochExponent = slotsPerEpochExponent

block_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestBlock_Commitments(t *testing.T) {
154154
apiProvider := api.NewEpochBasedProvider()
155155
apiProvider.AddProtocolParametersAtEpoch(
156156
iotago.NewV3ProtocolParameters(
157-
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
157+
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
158158
iotago.WithLivenessOptions(15, 30, 11, 21, 4),
159159
), 0)
160160

@@ -174,7 +174,7 @@ func TestBlock_Commitments1(t *testing.T) {
174174
apiProvider := api.NewEpochBasedProvider()
175175
apiProvider.AddProtocolParametersAtEpoch(
176176
iotago.NewV3ProtocolParameters(
177-
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
177+
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
178178
iotago.WithLivenessOptions(15, 30, 7, 21, 4),
179179
), 0)
180180

@@ -199,7 +199,7 @@ func TestBlock_TransactionCreationTime(t *testing.T) {
199199
apiProvider := api.NewEpochBasedProvider()
200200
apiProvider.AddProtocolParametersAtEpoch(
201201
iotago.NewV3ProtocolParameters(
202-
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
202+
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
203203
iotago.WithLivenessOptions(15, 30, 7, 21, 4),
204204
), 0)
205205

@@ -266,7 +266,7 @@ func TestBlock_WeakParents(t *testing.T) {
266266
apiProvider := api.NewEpochBasedProvider()
267267
apiProvider.AddProtocolParametersAtEpoch(
268268
iotago.NewV3ProtocolParameters(
269-
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
269+
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
270270
iotago.WithLivenessOptions(15, 30, 10, 20, 4),
271271
), 0)
272272
strongParent1 := tpkg.RandBlockID()
@@ -325,7 +325,7 @@ func TestBlock_TransactionCommitmentInput(t *testing.T) {
325325
apiProvider := api.NewEpochBasedProvider()
326326
apiProvider.AddProtocolParametersAtEpoch(
327327
iotago.NewV3ProtocolParameters(
328-
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
328+
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
329329
iotago.WithLivenessOptions(15, 30, 11, 21, 4),
330330
), 0)
331331

0 commit comments

Comments
 (0)