Skip to content

Commit

Permalink
Added GenesisSlot to the protocol parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsporn committed Oct 31, 2023
1 parent 578f582 commit bbd74c0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
4 changes: 3 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type ProtocolParameters interface {
NetworkID() NetworkID
// Bech32HRP defines the HRP prefix used for Bech32 addresses in the network.
Bech32HRP() NetworkPrefix
// StorageScoreStructure defines the storage score structure used by the given network.
// StorageScoreParameters defines the storage score structure used by the given network.
StorageScoreParameters() *StorageScoreParameters
// WorkScoreParameters defines the work score parameters used by the given network.
WorkScoreParameters() *WorkScoreParameters
Expand All @@ -119,6 +119,8 @@ type ProtocolParameters interface {
// TokenSupply defines the current token supply on the network.
TokenSupply() BaseToken

// GenesisSlot defines the slot of the genesis.
GenesisSlot() SlotIndex
// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
GenesisUnixTimestamp() int64
// SlotDurationInSeconds defines the duration of each slot in seconds.
Expand Down
30 changes: 16 additions & 14 deletions api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,45 @@ type basicProtocolParameters struct {
// TokenSupply defines the current token supply on the network.
TokenSupply BaseToken `serix:"6,mapKey=tokenSupply"`

// GenesisSlot defines the slot of the genesis.
GenesisSlot SlotIndex `serix:"7,mapKey=genesisSlot"`
// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
GenesisUnixTimestamp int64 `serix:"7,mapKey=genesisUnixTimestamp"`
GenesisUnixTimestamp int64 `serix:"8,mapKey=genesisUnixTimestamp"`
// SlotDurationInSeconds defines the duration of each slot in seconds.
SlotDurationInSeconds uint8 `serix:"8,mapKey=slotDurationInSeconds"`
SlotDurationInSeconds uint8 `serix:"9,mapKey=slotDurationInSeconds"`
// SlotsPerEpochExponent is the number of slots in an epoch expressed as an exponent of 2.
// (2**SlotsPerEpochExponent) == slots in an epoch.
SlotsPerEpochExponent uint8 `serix:"9,mapKey=slotsPerEpochExponent"`
SlotsPerEpochExponent uint8 `serix:"10,mapKey=slotsPerEpochExponent"`

// StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking.
StakingUnbondingPeriod EpochIndex `serix:"10,mapKey=stakingUnbondingPeriod"`
StakingUnbondingPeriod EpochIndex `serix:"11,mapKey=stakingUnbondingPeriod"`
// ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot.
ValidationBlocksPerSlot uint8 `serix:"11,mapKey=validationBlocksPerSlot"`
ValidationBlocksPerSlot uint8 `serix:"12,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"`
PunishmentEpochs EpochIndex `serix:"13,mapKey=punishmentEpochs"`

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

// 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:"15,mapKey=minCommittableAge"`
MinCommittableAge SlotIndex `serix:"16,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:"16,mapKey=maxCommittableAge"`
MaxCommittableAge SlotIndex `serix:"17,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:"17,mapKey=epochNearingThreshold"`
EpochNearingThreshold SlotIndex `serix:"18,mapKey=epochNearingThreshold"`
// RMCParameters defines the parameters used by to calculate the Reference Mana Cost (RMC).
CongestionControlParameters CongestionControlParameters `serix:"18,mapKey=congestionControlParameters"`
CongestionControlParameters CongestionControlParameters `serix:"19,mapKey=congestionControlParameters"`
// VersionSignaling defines the parameters used for version upgrades.
VersionSignaling VersionSignaling `serix:"19,mapKey=versionSignaling"`
VersionSignaling VersionSignaling `serix:"20,mapKey=versionSignaling"`
// RewardsParameters defines the parameters used for reward calculation.
RewardsParameters RewardsParameters `serix:"20,mapKey=rewardsParameters"`
RewardsParameters RewardsParameters `serix:"21,mapKey=rewardsParameters"`
}

func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
Expand Down
3 changes: 2 additions & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
10,
),
iotago.WithTimeProviderOptions(
654978,
1681373293,
10,
13,
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
iotago.WithRewardsOptions(8, 8, 31, 1154, 2, 1),
)

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}}`
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}}`

jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
require.NoError(t, err)
Expand Down
10 changes: 8 additions & 2 deletions api_v3_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr
WithNetworkOptions("testnet", PrefixTestnet),
WithSupplyOptions(1813620509061365, 100, 1, 10, 100, 100, 100),
WithWorkScoreOptions(0, 1, 0, 0, 0, 0, 0, 0, 0, 0),
WithTimeProviderOptions(time.Now().Unix(), 10, 13),
WithTimeProviderOptions(0, time.Now().Unix(), 10, 13),
WithManaOptions(63,
1,
17,
Expand Down Expand Up @@ -79,6 +79,11 @@ func (p *V3ProtocolParameters) NetworkID() NetworkID {
return NetworkIDFromString(p.basicProtocolParameters.NetworkName)
}

// GenesisUnixTimestamp defines the genesis timestamp at which the slots start to count.
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
Expand Down Expand Up @@ -260,8 +265,9 @@ func WithManaOptions(bitsCount uint8, generationRate uint8, generationRateExpone
}
}

func WithTimeProviderOptions(genesisTimestamp int64, slotDurationInSeconds uint8, slotsPerEpochExponent uint8) options.Option[V3ProtocolParameters] {
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
Expand Down
10 changes: 5 additions & 5 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestBlock_Commitments(t *testing.T) {
apiProvider := api.NewEpochBasedProvider()
apiProvider.AddProtocolParametersAtEpoch(
iotago.NewV3ProtocolParameters(
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
iotago.WithLivenessOptions(15, 30, 11, 21, 4),
), 0)

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

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

Expand Down Expand Up @@ -266,7 +266,7 @@ func TestBlock_WeakParents(t *testing.T) {
apiProvider := api.NewEpochBasedProvider()
apiProvider.AddProtocolParametersAtEpoch(
iotago.NewV3ProtocolParameters(
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
iotago.WithLivenessOptions(15, 30, 10, 20, 4),
), 0)
strongParent1 := tpkg.RandBlockID()
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestBlock_TransactionCommitmentInput(t *testing.T) {
apiProvider := api.NewEpochBasedProvider()
apiProvider.AddProtocolParametersAtEpoch(
iotago.NewV3ProtocolParameters(
iotago.WithTimeProviderOptions(time.Now().Add(-20*time.Minute).Unix(), 10, 13),
iotago.WithTimeProviderOptions(0, time.Now().Add(-20*time.Minute).Unix(), 10, 13),
iotago.WithLivenessOptions(15, 30, 11, 21, 4),
), 0)

Expand Down
Loading

0 comments on commit bbd74c0

Please sign in to comment.