diff --git a/address_account.go b/address_account.go index aa7c248b0..d26592251 100644 --- a/address_account.go +++ b/address_account.go @@ -29,7 +29,7 @@ func (addr *AccountAddress) Clone() Address { return cpy } -func (addr *AccountAddress) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (addr *AccountAddress) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { return 0 } diff --git a/address_ed25519.go b/address_ed25519.go index 7e7c7fe18..b1faa9f40 100644 --- a/address_ed25519.go +++ b/address_ed25519.go @@ -30,7 +30,7 @@ func (addr *Ed25519Address) Clone() Address { return cpy } -func (addr *Ed25519Address) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (addr *Ed25519Address) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { return 0 } diff --git a/address_implicit_account_creation.go b/address_implicit_account_creation.go index 23753625a..afcd4c66e 100644 --- a/address_implicit_account_creation.go +++ b/address_implicit_account_creation.go @@ -53,8 +53,8 @@ func (addr *ImplicitAccountCreationAddress) Clone() Address { return cpy } -func (addr *ImplicitAccountCreationAddress) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc) StorageScore { - return rentStruct.StorageScoreOffsetImplicitAccountCreationAddress +func (addr *ImplicitAccountCreationAddress) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore { + return storageScoreStruct.OffsetImplicitAccountCreationAddress } func (addr *ImplicitAccountCreationAddress) ID() []byte { diff --git a/address_multi.go b/address_multi.go index f52a66ada..778504035 100644 --- a/address_multi.go +++ b/address_multi.go @@ -60,7 +60,7 @@ func (addr *MultiAddress) Clone() Address { return cpy } -func (addr *MultiAddress) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (addr *MultiAddress) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { return 0 } diff --git a/address_multi_reference.go b/address_multi_reference.go index 90741824b..db153e01c 100644 --- a/address_multi_reference.go +++ b/address_multi_reference.go @@ -21,7 +21,7 @@ func (addr *MultiAddressReference) Clone() Address { } } -func (addr *MultiAddressReference) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (addr *MultiAddressReference) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { panic("not used") } diff --git a/address_nft.go b/address_nft.go index 6b837b8f2..245b16aa5 100644 --- a/address_nft.go +++ b/address_nft.go @@ -29,7 +29,7 @@ func (addr *NFTAddress) Clone() Address { return cpy } -func (addr *NFTAddress) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (addr *NFTAddress) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { return 0 } diff --git a/address_restricted.go b/address_restricted.go index bce5a3cd2..39b180613 100644 --- a/address_restricted.go +++ b/address_restricted.go @@ -23,7 +23,7 @@ func (addr *RestrictedAddress) Clone() Address { } } -func (addr *RestrictedAddress) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (addr *RestrictedAddress) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { return 0 } diff --git a/allotment.go b/allotment.go index 291cd9eab..7f77b3d10 100644 --- a/allotment.go +++ b/allotment.go @@ -46,9 +46,9 @@ func (a Allotments) Size() int { return serializer.UInt16ByteSize + len(a)*(AccountIDLength+ManaSize) } -func (a Allotments) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (a Allotments) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // Allotments requires invocation of account managers, so requires extra work. - workScoreAllotments, err := workScoreStructure.Allotment.Multiply(len(a)) + workScoreAllotments, err := workScoreParameters.Allotment.Multiply(len(a)) if err != nil { return 0, err } diff --git a/api.go b/api.go index 131fb250c..c9cc90912 100644 --- a/api.go +++ b/api.go @@ -58,8 +58,8 @@ type API interface { Version() Version // ProtocolParameters returns the protocol parameters this API is used with. ProtocolParameters() ProtocolParameters - // RentStructure returns the rent structure used by the protocol. - RentStructure() *RentStructure + // StorageScoreStructure returns the storage score structure used by the protocol. + StorageScoreStructure() *StorageScoreStructure // TimeProvider returns the underlying time provider used. TimeProvider() *TimeProvider // ManaDecayProvider returns the underlying mana decay provider used. @@ -110,10 +110,10 @@ type ProtocolParameters interface { NetworkID() NetworkID // Bech32HRP defines the HRP prefix used for Bech32 addresses in the network. Bech32HRP() NetworkPrefix - // RentStructure defines the rent structure used by given node/network. - RentParameters() *RentParameters - // WorkScoreStructure defines the work score structure used by the given network. - WorkScoreStructure() *WorkScoreStructure + // StorageScoreStructure defines the storage score structure used by given node/network. + StorageScoreParameters() *StorageScoreParameters + // WorkScoreParameters defines the work score parameters used by the given network. + WorkScoreParameters() *WorkScoreParameters // TokenSupply defines the current token supply on the network. TokenSupply() BaseToken @@ -123,7 +123,7 @@ type ProtocolParameters interface { StakingUnbondingPeriod() EpochIndex - ValidationBlocksPerSlot() uint16 + ValidationBlocksPerSlot() uint8 PunishmentEpochs() EpochIndex diff --git a/api_common.go b/api_common.go index 4d5831dcf..7185276ff 100644 --- a/api_common.go +++ b/api_common.go @@ -123,7 +123,7 @@ func CommonSerixAPI() *serix.API { // All versions of the protocol need to be able to parse older protocol parameter versions. { - must(api.RegisterTypeSettings(RentStructure{}, serix.TypeSettings{})) + must(api.RegisterTypeSettings(StorageScoreStructure{}, serix.TypeSettings{})) must(api.RegisterTypeSettings(V3ProtocolParameters{}, serix.TypeSettings{}.WithObjectType(uint8(ProtocolParametersV3))), diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index 4782889be..5788f774f 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -9,10 +9,10 @@ type basicProtocolParameters struct { // Bech32HRP defines the HRP prefix used for Bech32 addresses in the network. Bech32HRP NetworkPrefix `serix:"2,lengthPrefixType=uint8,mapKey=bech32Hrp"` - // RentStructure defines the rent structure used by given node/network. - RentParameters RentParameters `serix:"3,mapKey=rentParameters"` - // WorkScoreStructure defines the work score structure used by given node/network. - WorkScoreStructure WorkScoreStructure `serix:"4,mapKey=workScoreStructure"` + // StorageScoreParameters defines the Storage Score Parameters used by given node/network. + StorageScoreParameters StorageScoreParameters `serix:"3,mapKey=storageScoreParameters"` + // WorkScoreParameters defines the work score parameters used by given node/network. + WorkScoreParameters WorkScoreParameters `serix:"4,mapKey=workScoreParameters"` // TokenSupply defines the current token supply on the network. TokenSupply BaseToken `serix:"5,mapKey=tokenSupply"` @@ -24,13 +24,13 @@ type basicProtocolParameters struct { // (2**SlotsPerEpochExponent) == slots in an epoch. SlotsPerEpochExponent uint8 `serix:"8,mapKey=slotsPerEpochExponent"` - // ManaStructure defines the mana parameters used by mana calculation. - ManaStructure ManaStructure `serix:"9,mapKey=manaStructure"` + // ManaParameters defines the mana parameters used by mana calculation. + ManaParameters ManaParameters `serix:"9,mapKey=manaParameters"` // StakingUnbondingPeriod defines the unbonding period in epochs before an account can stop staking. StakingUnbondingPeriod EpochIndex `serix:"10,mapKey=stakingUnbondingPeriod"` // ValidationBlocksPerSlot is the number of validation blocks that each validator should issue each slot. - ValidationBlocksPerSlot uint16 `serix:"11,mapKey=validationBlocksPerSlot"` + ValidationBlocksPerSlot uint8 `serix:"11,mapKey=validationBlocksPerSlot"` // PunishmentEpochs is the number of epochs worth of Mana that a node is punished with for each additional validation block it issues. PunishmentEpochs EpochIndex `serix:"12,mapKey=punishmentEpochs"` @@ -62,13 +62,13 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool { return b.Version == other.Version && b.NetworkName == other.NetworkName && b.Bech32HRP == other.Bech32HRP && - b.RentParameters.Equals(other.RentParameters) && - b.WorkScoreStructure.Equals(other.WorkScoreStructure) && + b.StorageScoreParameters.Equals(other.StorageScoreParameters) && + b.WorkScoreParameters.Equals(other.WorkScoreParameters) && b.TokenSupply == other.TokenSupply && b.GenesisUnixTimestamp == other.GenesisUnixTimestamp && b.SlotDurationInSeconds == other.SlotDurationInSeconds && b.SlotsPerEpochExponent == other.SlotsPerEpochExponent && - b.ManaStructure.Equals(other.ManaStructure) && + b.ManaParameters.Equals(other.ManaParameters) && b.StakingUnbondingPeriod == other.StakingUnbondingPeriod && b.ValidationBlocksPerSlot == other.ValidationBlocksPerSlot && b.PunishmentEpochs == other.PunishmentEpochs && diff --git a/api_test.go b/api_test.go index 5b27436d2..b1b5fbc34 100644 --- a/api_test.go +++ b/api_test.go @@ -132,10 +132,10 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) { 100, ), iotago.WithVersionSignalingOptions(3, 4, 1), - iotago.WithRewardsOptions(10, 8, 8, 31, 1154, 2, 1), + iotago.WithRewardsOptions(8, 8, 31, 1154, 2, 1), ) - protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","rentParameters":{"storageCost":"6","storageScoreFactorData":7,"storageScoreOffsetOutput":"8","storageScoreOffsetEd25519BlockIssuerKey":"9","storageScoreOffsetStakingFeature":"10","storageScoreOffsetDelegation":"10"},"workScoreStructure":{"dataByte":1,"block":2,"input":3,"contextInput":4,"output":5,"nativeToken":6,"staking":7,"blockIssuer":8,"allotment":9,"signatureEd25519":10},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"bitsCount":1,"generationRate":1,"generationRateExponent":27,"decayFactors":[10,20],"decayFactorsExponent":32,"decayFactorEpochsSum":1337,"decayFactorEpochsSumExponent":20},"stakingUnbondingPeriod":11,"validationBlocksPerSlot":10,"punishmentEpochs":9,"livenessThresholdLowerBound":15,"livenessThresholdUpperBound":30,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1},"rewardsParameters":{"validatorBlocksPerSlot":10,"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}` + protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","storageScoreParameters":{"storageCost":"6","factorData":7,"offsetOutput":"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},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaParameters":{"bitsCount":1,"generationRate":1,"generationRateExponent":27,"decayFactors":[10,20],"decayFactorsExponent":32,"decayFactorEpochsSum":1337,"decayFactorEpochsSumExponent":20},"stakingUnbondingPeriod":11,"validationBlocksPerSlot":10,"punishmentEpochs":9,"livenessThresholdLowerBound":15,"livenessThresholdUpperBound":30,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1},"rewardsParameters":{"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}` jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams) require.NoError(t, err) diff --git a/api_v3.go b/api_v3.go index 9aa03517d..1e6f94cf2 100644 --- a/api_v3.go +++ b/api_v3.go @@ -183,7 +183,7 @@ type v3api struct { timeProvider *TimeProvider manaDecayProvider *ManaDecayProvider livenessThresholdDuration time.Duration - rentStructure *RentStructure + storageScoreStructure *StorageScoreStructure maxBlockWork WorkScore computedInitialReward uint64 computedFinalReward uint64 @@ -224,8 +224,8 @@ func (v *v3api) ProtocolParameters() ProtocolParameters { return v.protocolParameters } -func (v *v3api) RentStructure() *RentStructure { - return v.rentStructure +func (v *v3api) StorageScoreStructure() *StorageScoreStructure { + return v.storageScoreStructure } func (v *v3api) TimeProvider() *TimeProvider { @@ -266,7 +266,7 @@ func V3API(protoParams ProtocolParameters) API { timeProvider := protoParams.TimeProvider() - maxBlockWork, err := protoParams.WorkScoreStructure().MaxBlockWork() + maxBlockWork, err := protoParams.WorkScoreParameters().MaxBlockWork() must(err) initialReward, finalReward, err := calculateRewards(protoParams) @@ -276,7 +276,7 @@ func V3API(protoParams ProtocolParameters) API { v3 := &v3api{ serixAPI: api, protocolParameters: protoParams.(*V3ProtocolParameters), - rentStructure: NewRentStructure(protoParams.RentParameters()), + storageScoreStructure: NewStorageScoreStructure(protoParams.StorageScoreParameters()), timeProvider: timeProvider, manaDecayProvider: protoParams.ManaDecayProvider(), maxBlockWork: maxBlockWork, @@ -643,7 +643,7 @@ func V3API(protoParams ProtocolParameters) API { } func calculateRewards(protoParams ProtocolParameters) (initialRewards, finalRewards uint64, err error) { - manaStructure := protoParams.ManaDecayProvider() + manaParameters := protoParams.ManaDecayProvider() // final reward, after bootstrapping phase result, err := safemath.SafeMul(uint64(protoParams.TokenSupply()), protoParams.RewardsParameters().ManaShareCoefficient) @@ -651,12 +651,12 @@ func calculateRewards(protoParams ProtocolParameters) (initialRewards, finalRewa return 0, 0, ierrors.Wrap(err, "failed to calculate target reward due to tokenSupply and RewardsManaShareCoefficient multiplication overflow") } - result, err = safemath.SafeMul(result, manaStructure.generationRate) + result, err = safemath.SafeMul(result, manaParameters.generationRate) if err != nil { return 0, 0, ierrors.Wrapf(err, "failed to calculate target reward due to multiplication with generationRate overflow") } - subExponent, err := safemath.SafeSub(manaStructure.generationRateExponent, uint64(protoParams.TimeProvider().SlotsPerEpochExponent())) + subExponent, err := safemath.SafeSub(manaParameters.generationRateExponent, uint64(protoParams.TimeProvider().SlotsPerEpochExponent())) if err != nil { return 0, 0, ierrors.Wrapf(err, "failed to calculate target reward due to generationRateExponent - slotsPerEpochExponent subtraction overflow") } diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index 4e9cbcb53..3e91d761a 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -37,7 +37,7 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr WithCongestionControlOptions(1, 0, 0, 8*schedulerRate, 5*schedulerRate, schedulerRate, 1000, 100), WithStakingOptions(10, 10, 10), WithVersionSignalingOptions(7, 5, 7), - WithRewardsOptions(10, 8, 8, 31, 1154, 2, 1), + WithRewardsOptions(8, 8, 31, 1154, 2, 1), }, opts..., ), @@ -58,12 +58,12 @@ func (p *V3ProtocolParameters) NetworkName() string { return p.basicProtocolParameters.NetworkName } -func (p *V3ProtocolParameters) RentParameters() *RentParameters { - return &p.basicProtocolParameters.RentParameters +func (p *V3ProtocolParameters) StorageScoreParameters() *StorageScoreParameters { + return &p.basicProtocolParameters.StorageScoreParameters } -func (p *V3ProtocolParameters) WorkScoreStructure() *WorkScoreStructure { - return &p.basicProtocolParameters.WorkScoreStructure +func (p *V3ProtocolParameters) WorkScoreParameters() *WorkScoreParameters { + return &p.basicProtocolParameters.WorkScoreParameters } func (p *V3ProtocolParameters) TokenSupply() BaseToken { @@ -87,7 +87,7 @@ func (p *V3ProtocolParameters) StakingUnbondingPeriod() EpochIndex { return p.basicProtocolParameters.StakingUnbondingPeriod } -func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint16 { +func (p *V3ProtocolParameters) ValidationBlocksPerSlot() uint8 { return p.basicProtocolParameters.ValidationBlocksPerSlot } @@ -141,17 +141,17 @@ 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\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", + 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\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 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.RentParameters, - p.basicProtocolParameters.WorkScoreStructure, + p.basicProtocolParameters.StorageScoreParameters, + p.basicProtocolParameters.WorkScoreParameters, p.basicProtocolParameters.TokenSupply, p.basicProtocolParameters.GenesisUnixTimestamp, p.basicProtocolParameters.SlotDurationInSeconds, p.basicProtocolParameters.SlotsPerEpochExponent, - p.basicProtocolParameters.ManaStructure, + p.basicProtocolParameters.ManaParameters, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.ValidationBlocksPerSlot, p.basicProtocolParameters.PunishmentEpochs, @@ -167,7 +167,7 @@ func (p *V3ProtocolParameters) String() string { } func (p *V3ProtocolParameters) ManaDecayProvider() *ManaDecayProvider { - return NewManaDecayProvider(p.TimeProvider(), p.basicProtocolParameters.SlotsPerEpochExponent, &p.basicProtocolParameters.ManaStructure) + return NewManaDecayProvider(p.TimeProvider(), p.basicProtocolParameters.SlotsPerEpochExponent, &p.basicProtocolParameters.ManaParameters) } func (p *V3ProtocolParameters) Equals(other ProtocolParameters) bool { @@ -192,16 +192,16 @@ func WithNetworkOptions(networkName string, bech32HRP NetworkPrefix) options.Opt } } -func WithSupplyOptions(totalSupply BaseToken, storageCost BaseToken, storageScoreFactorData StorageScoreFactor, storageScoreOffsetOutput, storageScoreOffsetEd25519BlockIssuerKey, storageScoreOffsetStakingFeature, storageScoreOffsetDelegation StorageScore) options.Option[V3ProtocolParameters] { +func WithSupplyOptions(totalSupply BaseToken, storageCost BaseToken, factorData StorageScoreFactor, offsetOutput, offsetEd25519BlockIssuerKey, offsetStakingFeature, offsetDelegation StorageScore) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.TokenSupply = totalSupply - p.basicProtocolParameters.RentParameters = RentParameters{ - StorageCost: storageCost, - StorageScoreFactorData: storageScoreFactorData, - StorageScoreOffsetOutput: storageScoreOffsetOutput, - StorageScoreOffsetEd25519BlockIssuerKey: storageScoreOffsetEd25519BlockIssuerKey, - StorageScoreOffsetStakingFeature: storageScoreOffsetStakingFeature, - StorageScoreOffsetDelegation: storageScoreOffsetDelegation, + p.basicProtocolParameters.StorageScoreParameters = StorageScoreParameters{ + StorageCost: storageCost, + FactorData: factorData, + OffsetOutput: offsetOutput, + OffsetEd25519BlockIssuerKey: offsetEd25519BlockIssuerKey, + OffsetStakingFeature: offsetStakingFeature, + OffsetDelegation: offsetDelegation, } } } @@ -219,7 +219,7 @@ func WithWorkScoreOptions( signatureEd25519 WorkScore, ) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { - p.basicProtocolParameters.WorkScoreStructure = WorkScoreStructure{ + p.basicProtocolParameters.WorkScoreParameters = WorkScoreParameters{ DataByte: dataByte, Block: block, Input: input, @@ -244,13 +244,13 @@ func WithTimeProviderOptions(genesisTimestamp int64, slotDurationInSeconds uint8 func WithManaOptions(bitsCount uint8, generationRate uint8, generationRateExponent uint8, decayFactors []uint32, decayFactorsExponent uint8, decayFactorEpochsSum uint32, decayFactorEpochsSumExponent uint8) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { - p.basicProtocolParameters.ManaStructure.BitsCount = bitsCount - p.basicProtocolParameters.ManaStructure.GenerationRate = generationRate - p.basicProtocolParameters.ManaStructure.GenerationRateExponent = generationRateExponent - p.basicProtocolParameters.ManaStructure.DecayFactors = decayFactors - p.basicProtocolParameters.ManaStructure.DecayFactorsExponent = decayFactorsExponent - p.basicProtocolParameters.ManaStructure.DecayFactorEpochsSum = decayFactorEpochsSum - p.basicProtocolParameters.ManaStructure.DecayFactorEpochsSumExponent = decayFactorEpochsSumExponent + p.basicProtocolParameters.ManaParameters.BitsCount = bitsCount + p.basicProtocolParameters.ManaParameters.GenerationRate = generationRate + p.basicProtocolParameters.ManaParameters.GenerationRateExponent = generationRateExponent + p.basicProtocolParameters.ManaParameters.DecayFactors = decayFactors + p.basicProtocolParameters.ManaParameters.DecayFactorsExponent = decayFactorsExponent + p.basicProtocolParameters.ManaParameters.DecayFactorEpochsSum = decayFactorEpochsSum + p.basicProtocolParameters.ManaParameters.DecayFactorEpochsSumExponent = decayFactorEpochsSumExponent } } @@ -277,7 +277,7 @@ func WithCongestionControlOptions(minReferenceManaCost Mana, rmcIncrease Mana, r } } -func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint16, punishmentEpochs EpochIndex) options.Option[V3ProtocolParameters] { +func WithStakingOptions(unbondingPeriod EpochIndex, validationBlocksPerSlot uint8, punishmentEpochs EpochIndex) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { p.basicProtocolParameters.StakingUnbondingPeriod = unbondingPeriod p.basicProtocolParameters.ValidationBlocksPerSlot = validationBlocksPerSlot @@ -295,9 +295,8 @@ func WithVersionSignalingOptions(windowSize uint8, windowTargetRatio uint8, acti } } -func WithRewardsOptions(validatorBlocksPerSlot, profitMarginExponent, decayBalancingConstantExponent, poolCoefficientExponent uint8, bootstrappingDuration EpochIndex, manaShareCoefficient, decayBalancingConstant uint64) options.Option[V3ProtocolParameters] { +func WithRewardsOptions(profitMarginExponent, decayBalancingConstantExponent, poolCoefficientExponent uint8, bootstrappingDuration EpochIndex, manaShareCoefficient, decayBalancingConstant uint64) options.Option[V3ProtocolParameters] { return func(p *V3ProtocolParameters) { - p.basicProtocolParameters.RewardsParameters.ValidatorBlocksPerSlot = validatorBlocksPerSlot p.basicProtocolParameters.RewardsParameters.ProfitMarginExponent = profitMarginExponent p.basicProtocolParameters.RewardsParameters.BootstrappingDuration = bootstrappingDuration p.basicProtocolParameters.RewardsParameters.ManaShareCoefficient = manaShareCoefficient diff --git a/block.go b/block.go index 6e12b81c9..74ed0834e 100644 --- a/block.go +++ b/block.go @@ -74,7 +74,7 @@ func (b *BlockHeader) Hash(api API) (Identifier, error) { return blake2b.Sum256(headerBytes), nil } -func (b *BlockHeader) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (b *BlockHeader) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } @@ -244,19 +244,19 @@ func (b *ProtocolBlock) ForEachParent(consumer func(parent Parent)) { } func (b *ProtocolBlock) WorkScore() (WorkScore, error) { - workScoreStructure := b.API.ProtocolParameters().WorkScoreStructure() + workScoreParameters := b.API.ProtocolParameters().WorkScoreParameters() - workScoreHeader, err := b.BlockHeader.WorkScore(workScoreStructure) + workScoreHeader, err := b.BlockHeader.WorkScore(workScoreParameters) if err != nil { return 0, err } - workScoreBlock, err := b.Block.WorkScore(workScoreStructure) + workScoreBlock, err := b.Block.WorkScore(workScoreParameters) if err != nil { return 0, err } - workScoreSignature, err := b.Signature.WorkScore(workScoreStructure) + workScoreSignature, err := b.Signature.WorkScore(workScoreParameters) if err != nil { return 0, err } @@ -371,22 +371,22 @@ func (b *BasicBlock) Hash() (Identifier, error) { return blake2b.Sum256(blockBytes), nil } -func (b *BasicBlock) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (b *BasicBlock) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { var err error var workScorePayload WorkScore if b.Payload != nil { - workScorePayload, err = b.Payload.WorkScore(workScoreStructure) + workScorePayload, err = b.Payload.WorkScore(workScoreParameters) if err != nil { return 0, err } } // offset for block plus payload. - return workScoreStructure.Block.Add(workScorePayload) + return workScoreParameters.Block.Add(workScorePayload) } -func (b *BasicBlock) ManaCost(rmc Mana, workScoreStructure *WorkScoreStructure) (Mana, error) { - workScore, err := b.WorkScore(workScoreStructure) +func (b *BasicBlock) ManaCost(rmc Mana, workScoreParameters *WorkScoreParameters) (Mana, error) { + workScore, err := b.WorkScore(workScoreParameters) if err != nil { return 0, err } @@ -489,7 +489,7 @@ func (b *ValidationBlock) Hash() (Identifier, error) { return IdentifierFromData(blockBytes), nil } -func (b *ValidationBlock) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (b *ValidationBlock) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // Validator blocks do not incur any work score as they do not burn mana return 0, nil } diff --git a/block_issuer_key.go b/block_issuer_key.go index e14e72d9b..ec47851cc 100644 --- a/block_issuer_key.go +++ b/block_issuer_key.go @@ -124,10 +124,10 @@ func (keys BlockIssuerKeys) Size() int { return size } -func (keys BlockIssuerKeys) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc) StorageScore { +func (keys BlockIssuerKeys) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore { var storageScore StorageScore for _, key := range keys { - storageScore += key.StorageScore(rentStruct, nil) + storageScore += key.StorageScore(storageScoreStruct, nil) } return storageScore diff --git a/block_issuer_key_ed25519_pubkey.go b/block_issuer_key_ed25519_pubkey.go index 579e0f6ce..4870b3a0f 100644 --- a/block_issuer_key_ed25519_pubkey.go +++ b/block_issuer_key_ed25519_pubkey.go @@ -58,6 +58,6 @@ func (key *Ed25519PublicKeyBlockIssuerKey) Size() int { return serializer.SmallTypeDenotationByteSize + ed25519.PublicKeySize } -func (key *Ed25519PublicKeyBlockIssuerKey) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc) StorageScore { - return rentStruct.StorageScoreOffsetEd25519BlockIssuerKey() +func (key *Ed25519PublicKeyBlockIssuerKey) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore { + return storageScoreStruct.OffsetEd25519BlockIssuerKey() } diff --git a/block_issuer_key_ed25519_pubkeyhash.go b/block_issuer_key_ed25519_pubkeyhash.go index 7696a325b..41f5aa6b1 100644 --- a/block_issuer_key_ed25519_pubkeyhash.go +++ b/block_issuer_key_ed25519_pubkeyhash.go @@ -70,6 +70,6 @@ func (key *Ed25519PublicKeyHashBlockIssuerKey) Size() int { return serializer.SmallTypeDenotationByteSize + Ed25519PublicKeyHashBytesLength } -func (key *Ed25519PublicKeyHashBlockIssuerKey) StorageScore(rentStructure *RentStructure, _ StorageScoreFunc) StorageScore { - return rentStructure.StorageScoreOffsetEd25519BlockIssuerKey() +func (key *Ed25519PublicKeyHashBlockIssuerKey) StorageScore(storageScoreStructure *StorageScoreStructure, _ StorageScoreFunc) StorageScore { + return storageScoreStructure.OffsetEd25519BlockIssuerKey() } diff --git a/builder/block_builder.go b/builder/block_builder.go index 834c00267..9175a8097 100644 --- a/builder/block_builder.go +++ b/builder/block_builder.go @@ -180,7 +180,7 @@ func (b *BasicBlockBuilder) CalculateAndSetMaxBurnedMana(rmc iotago.Mana) *Basic return b } - burnedMana, err := b.basicBlock.ManaCost(rmc, b.protocolBlock.API.ProtocolParameters().WorkScoreStructure()) + burnedMana, err := b.basicBlock.ManaCost(rmc, b.protocolBlock.API.ProtocolParameters().WorkScoreParameters()) if err != nil { b.err = ierrors.Errorf("error calculating mana cost: %w", err) return b diff --git a/builder/block_builder_test.go b/builder/block_builder_test.go index a4c6e5df8..cba1b8d83 100644 --- a/builder/block_builder_test.go +++ b/builder/block_builder_test.go @@ -28,7 +28,7 @@ func TestBasicBlockBuilder(t *testing.T) { require.Equal(t, iotago.BlockTypeBasic, block.Block.Type()) basicBlock := block.Block.(*iotago.BasicBlock) - expectedBurnedMana, err := basicBlock.ManaCost(100, tpkg.TestAPI.ProtocolParameters().WorkScoreStructure()) + expectedBurnedMana, err := basicBlock.ManaCost(100, tpkg.TestAPI.ProtocolParameters().WorkScoreParameters()) require.NoError(t, err) require.EqualValues(t, expectedBurnedMana, basicBlock.MaxBurnedMana) } diff --git a/builder/transaction_builder.go b/builder/transaction_builder.go index a31f0842c..57ae9497f 100644 --- a/builder/transaction_builder.go +++ b/builder/transaction_builder.go @@ -151,7 +151,7 @@ func (b *TransactionBuilder) AllotRequiredManaAndStoreRemainingManaInOutput(targ } // calculate the minimum required mana to issue the block - minRequiredMana, err := b.MinRequiredAllotedMana(b.api.ProtocolParameters().WorkScoreStructure(), rmc, blockIssuerAccountID) + minRequiredMana, err := b.MinRequiredAllotedMana(b.api.ProtocolParameters().WorkScoreParameters(), rmc, blockIssuerAccountID) if err != nil { return setBuildError(ierrors.Wrap(err, "failed to calculate the minimum required mana to issue the block")) } @@ -326,7 +326,7 @@ func CalculateAvailableMana(protoParams iotago.ProtocolParameters, inputSet iota var potentialMana iotago.Mana // we need to ignore the storage deposit, because it doesn't generate mana - minDeposit, err := iotago.NewRentStructure(protoParams.RentParameters()).MinDeposit(input) + minDeposit, err := iotago.NewStorageScoreStructure(protoParams.StorageScoreParameters()).MinDeposit(input) if err != nil { return 0, 0, nil, ierrors.Wrap(err, "failed to calculate min deposit") } @@ -373,7 +373,7 @@ func CalculateAvailableMana(protoParams iotago.ProtocolParameters, inputSet iota // MinRequiredAllotedMana returns the minimum alloted mana required to issue a ProtocolBlock // with 4 strong parents, the transaction payload from the builder and 1 allotment for the block issuer. -func (b *TransactionBuilder) MinRequiredAllotedMana(workScoreStructure *iotago.WorkScoreStructure, rmc iotago.Mana, blockIssuerAccountID iotago.AccountID) (iotago.Mana, error) { +func (b *TransactionBuilder) MinRequiredAllotedMana(workScoreParameters *iotago.WorkScoreParameters, rmc iotago.Mana, blockIssuerAccountID iotago.AccountID) (iotago.Mana, error) { // clone the essence allotments to not modify the original transaction allotmentsCpy := b.transaction.Allotments.Clone() @@ -392,12 +392,12 @@ func (b *TransactionBuilder) MinRequiredAllotedMana(workScoreStructure *iotago.W return 0, ierrors.Wrap(err, "failed to build the transaction payload") } - payloadWorkScore, err := dummyTxPayload.WorkScore(workScoreStructure) + payloadWorkScore, err := dummyTxPayload.WorkScore(workScoreParameters) if err != nil { return 0, ierrors.Wrap(err, "failed to calculate the transaction payload workscore") } - workScore, err := workScoreStructure.Block.Add(payloadWorkScore) + workScore, err := workScoreParameters.Block.Add(payloadWorkScore) if err != nil { return 0, ierrors.Wrap(err, "failed to add the block workscore") } diff --git a/candidacy_announcement.go b/candidacy_announcement.go index 80fffd907..2570fd325 100644 --- a/candidacy_announcement.go +++ b/candidacy_announcement.go @@ -17,8 +17,8 @@ func (u *CandidacyAnnouncement) Size() int { return 1 } -func (u *CandidacyAnnouncement) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (u *CandidacyAnnouncement) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // we account for the network traffic only on "Payload" level // TODO: is the work score correct? - return workScoreStructure.DataByte.Multiply(u.Size()) + return workScoreParameters.DataByte.Multiply(u.Size()) } diff --git a/feat.go b/feat.go index c1aca76f9..8bb9a77aa 100644 --- a/feat.go +++ b/feat.go @@ -69,19 +69,19 @@ func (f Features[T]) Clone() Features[T] { return lo.CloneSlice(f) } -func (f Features[T]) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc) StorageScore { +func (f Features[T]) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore { var sumCost StorageScore for _, feat := range f { - sumCost += feat.StorageScore(rentStruct, nil) + sumCost += feat.StorageScore(storageScoreStruct, nil) } return sumCost } -func (f Features[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (f Features[T]) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { var workScoreFeats WorkScore for _, feat := range f { - workScoreFeat, err := feat.WorkScore(workScoreStructure) + workScoreFeat, err := feat.WorkScore(workScoreParameters) if err != nil { return 0, err } diff --git a/feat_blockissuer.go b/feat_blockissuer.go index 411934aa6..bcc1d88c5 100644 --- a/feat_blockissuer.go +++ b/feat_blockissuer.go @@ -22,13 +22,13 @@ func (s *BlockIssuerFeature) Clone() Feature { return &BlockIssuerFeature{BlockIssuerKeys: s.BlockIssuerKeys, ExpirySlot: s.ExpirySlot} } -func (s *BlockIssuerFeature) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc) StorageScore { - return s.BlockIssuerKeys.StorageScore(rentStruct, nil) +func (s *BlockIssuerFeature) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore { + return s.BlockIssuerKeys.StorageScore(storageScoreStruct, nil) } -func (s *BlockIssuerFeature) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (s *BlockIssuerFeature) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // block issuer feature requires invocation of account and mana managers, so requires extra work. - return workScoreStructure.BlockIssuer, nil + return workScoreParameters.BlockIssuer, nil } func (s *BlockIssuerFeature) Equal(other Feature) bool { diff --git a/feat_issuer.go b/feat_issuer.go index 2a59eabcd..e952677fb 100644 --- a/feat_issuer.go +++ b/feat_issuer.go @@ -18,11 +18,11 @@ func (s *IssuerFeature) Clone() Feature { return &IssuerFeature{Address: s.Address.Clone()} } -func (s *IssuerFeature) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc) StorageScore { - return s.Address.StorageScore(rentStruct, nil) +func (s *IssuerFeature) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore { + return s.Address.StorageScore(storageScoreStruct, nil) } -func (s *IssuerFeature) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *IssuerFeature) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // we do not need to charge for a signature check here as this is covered by the unlock that must be provided. return 0, nil } diff --git a/feat_metadata.go b/feat_metadata.go index 473e9ace8..cc0057800 100644 --- a/feat_metadata.go +++ b/feat_metadata.go @@ -16,11 +16,11 @@ func (s *MetadataFeature) Clone() Feature { return &MetadataFeature{Data: append([]byte(nil), s.Data...)} } -func (s *MetadataFeature) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (s *MetadataFeature) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { return 0 } -func (s *MetadataFeature) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *MetadataFeature) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } diff --git a/feat_native_token.go b/feat_native_token.go index 9c7729329..d78e6b576 100644 --- a/feat_native_token.go +++ b/feat_native_token.go @@ -61,12 +61,12 @@ func (n *NativeTokenFeature) Type() FeatureType { return FeatureNativeToken } -func (n *NativeTokenFeature) StorageScore(_ *RentStructure, _ StorageScoreFunc) StorageScore { +func (n *NativeTokenFeature) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore { return 0 } -func (n *NativeTokenFeature) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { - return workScoreStructure.NativeToken, nil +func (n *NativeTokenFeature) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { + return workScoreParameters.NativeToken, nil } // Equal checks whether other is equal to this NativeToken. diff --git a/feat_sender.go b/feat_sender.go index b05ae9a50..0ac200d33 100644 --- a/feat_sender.go +++ b/feat_sender.go @@ -15,15 +15,15 @@ func (s *SenderFeature) Clone() Feature { return &SenderFeature{Address: s.Address.Clone()} } -func (s *SenderFeature) StorageScore(rentStruct *RentStructure, f StorageScoreFunc) StorageScore { +func (s *SenderFeature) StorageScore(storageScoreStruct *StorageScoreStructure, f StorageScoreFunc) StorageScore { if f != nil { - return f(rentStruct) + return f(storageScoreStruct) } - return s.Address.StorageScore(rentStruct, nil) + return s.Address.StorageScore(storageScoreStruct, nil) } -func (s *SenderFeature) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *SenderFeature) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // we do not need to charge for a signature check here as this is covered by the unlock that must be provided. return 0, nil } diff --git a/feat_staking.go b/feat_staking.go index 2d9c307c5..a48211dac 100644 --- a/feat_staking.go +++ b/feat_staking.go @@ -46,17 +46,17 @@ func (s *StakingFeature) Clone() Feature { return &StakingFeature{StakedAmount: s.StakedAmount, FixedCost: s.FixedCost, StartEpoch: s.StartEpoch, EndEpoch: s.EndEpoch} } -func (s *StakingFeature) StorageScore(rentStruct *RentStructure, f StorageScoreFunc) StorageScore { +func (s *StakingFeature) StorageScore(storageScoreStruct *StorageScoreStructure, f StorageScoreFunc) StorageScore { if f != nil { - return f(rentStruct) + return f(storageScoreStruct) } - return rentStruct.StorageScoreOffsetStakingFeature() + return storageScoreStruct.OffsetStakingFeature() } -func (s *StakingFeature) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (s *StakingFeature) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // staking feature changes require invokation of staking managers so require extra work. - return workScoreStructure.Staking, nil + return workScoreParameters.Staking, nil } func (s *StakingFeature) Equal(other Feature) bool { diff --git a/feat_tag.go b/feat_tag.go index 2aee07fd6..50bd26300 100644 --- a/feat_tag.go +++ b/feat_tag.go @@ -15,15 +15,15 @@ func (s *TagFeature) Clone() Feature { return &TagFeature{Tag: append([]byte(nil), s.Tag...)} } -func (s *TagFeature) StorageScore(rentStruct *RentStructure, f StorageScoreFunc) StorageScore { +func (s *TagFeature) StorageScore(storageScoreStruct *StorageScoreStructure, f StorageScoreFunc) StorageScore { if f != nil { - return f(rentStruct) + return f(storageScoreStruct) } return 0 } -func (s *TagFeature) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *TagFeature) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } diff --git a/input.go b/input.go index c545ccf82..a255db66e 100644 --- a/input.go +++ b/input.go @@ -61,10 +61,10 @@ func (in Inputs[T]) Size() int { return sum } -func (in Inputs[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (in Inputs[T]) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { var workScoreInputs WorkScore for _, input := range in { - workScoreInput, err := input.WorkScore(workScoreStructure) + workScoreInput, err := input.WorkScore(workScoreParameters) if err != nil { return 0, err } diff --git a/input_block_issuance_credit.go b/input_block_issuance_credit.go index 2f0650ce0..1b85ddcfb 100644 --- a/input_block_issuance_credit.go +++ b/input_block_issuance_credit.go @@ -35,7 +35,7 @@ func (b *BlockIssuanceCreditInput) Size() int { return serializer.OneByte + AccountIDLength } -func (b *BlockIssuanceCreditInput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (b *BlockIssuanceCreditInput) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // context inputs require invocation of informations in the node, so requires extra work. - return workScoreStructure.ContextInput, nil + return workScoreParameters.ContextInput, nil } diff --git a/input_commitment.go b/input_commitment.go index b24370f6d..019b2a3d9 100644 --- a/input_commitment.go +++ b/input_commitment.go @@ -31,7 +31,7 @@ func (c *CommitmentInput) Size() int { return serializer.OneByte + CommitmentIDLength } -func (c *CommitmentInput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (c *CommitmentInput) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // context inputs require invocation of informations in the node, so requires extra work. - return workScoreStructure.ContextInput, nil + return workScoreParameters.ContextInput, nil } diff --git a/input_context.go b/input_context.go index 84ec6c18a..bf4afe422 100644 --- a/input_context.go +++ b/input_context.go @@ -33,10 +33,10 @@ func (in ContextInputs[T]) Clone() ContextInputs[T] { return cpy } -func (in ContextInputs[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (in ContextInputs[T]) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { var workScoreContextInputs WorkScore for _, input := range in { - workScoreInput, err := input.WorkScore(workScoreStructure) + workScoreInput, err := input.WorkScore(workScoreParameters) if err != nil { return 0, err } diff --git a/input_reward.go b/input_reward.go index d344ed654..83b431113 100644 --- a/input_reward.go +++ b/input_reward.go @@ -40,7 +40,7 @@ func (r *RewardInput) Size() int { return serializer.OneByte + serializer.UInt16ByteSize } -func (r *RewardInput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (r *RewardInput) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // context inputs require invocation of informations in the node, so requires extra work. - return workScoreStructure.ContextInput, nil + return workScoreParameters.ContextInput, nil } diff --git a/input_utxo.go b/input_utxo.go index 12ce5141d..20c891bbb 100644 --- a/input_utxo.go +++ b/input_utxo.go @@ -77,7 +77,7 @@ func (u *UTXOInput) Size() int { return serializer.SmallTypeDenotationByteSize + TransactionIDLength + OutputIndexLength } -func (u *UTXOInput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (u *UTXOInput) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) { // inputs require lookup of the UTXO, so requires extra work. - return workScoreStructure.Input, nil + return workScoreParameters.Input, nil } diff --git a/mana.go b/mana.go index 28926efa3..bf86fae28 100644 --- a/mana.go +++ b/mana.go @@ -7,7 +7,7 @@ import ( ) // Mana Structure defines the parameters used in mana calculations. -type ManaStructure struct { +type ManaParameters struct { // BitsCount is the number of bits used to represent Mana. BitsCount uint8 `serix:"0,mapKey=bitsCount"` // GenerationRate is the amount of potential Mana generated by 1 IOTA in 1 slot. @@ -24,7 +24,7 @@ type ManaStructure struct { DecayFactorEpochsSumExponent uint8 `serix:"6,mapKey=decayFactorEpochsSumExponent"` } -func (m ManaStructure) Equals(other ManaStructure) bool { +func (m ManaParameters) Equals(other ManaParameters) bool { return m.BitsCount == other.BitsCount && m.GenerationRate == other.GenerationRate && m.GenerationRateExponent == other.GenerationRateExponent && @@ -35,25 +35,22 @@ func (m ManaStructure) Equals(other ManaStructure) bool { } type RewardsParameters struct { - // ValidatorBlocksPerSlot is the number of validation blocks that should be issued by a selected validator per slot during its epoch duties. - ValidatorBlocksPerSlot uint8 `serix:"0,mapKey=validatorBlocksPerSlot"` // ProfitMarginExponent is used for shift operation for calculation of profit margin. - ProfitMarginExponent uint8 `serix:"1,mapKey=profitMarginExponent"` + ProfitMarginExponent uint8 `serix:"0,mapKey=profitMarginExponent"` // BootstrappingDuration is the length in epochs of the bootstrapping phase, (approx 3 years). - BootstrappingDuration EpochIndex `serix:"2,mapKey=bootstrappingDuration"` + BootstrappingDuration EpochIndex `serix:"1,mapKey=bootstrappingDuration"` // ManaShareCoefficient is the coefficient used for calculation of initial rewards, relative to the term theta/(1-theta) from the Whitepaper, with theta = 2/3. - ManaShareCoefficient uint64 `serix:"3,mapKey=manaShareCoefficient"` + ManaShareCoefficient uint64 `serix:"2,mapKey=manaShareCoefficient"` // DecayBalancingConstantExponent is the exponent used for calculation of the initial reward. - DecayBalancingConstantExponent uint8 `serix:"4,mapKey=decayBalancingConstantExponent"` + DecayBalancingConstantExponent uint8 `serix:"3,mapKey=decayBalancingConstantExponent"` // DecayBalancingConstant needs to be an integer approximation calculated based on chosen DecayBalancingConstantExponent. - DecayBalancingConstant uint64 `serix:"5,mapKey=decayBalancingConstant"` + DecayBalancingConstant uint64 `serix:"4,mapKey=decayBalancingConstant"` // PoolCoefficientExponent is the exponent used for shifting operation in the pool rewards calculations. - PoolCoefficientExponent uint8 `serix:"6,mapKey=poolCoefficientExponent"` + PoolCoefficientExponent uint8 `serix:"5,mapKey=poolCoefficientExponent"` } func (r RewardsParameters) Equals(other RewardsParameters) bool { - return r.ValidatorBlocksPerSlot == other.ValidatorBlocksPerSlot && - r.ProfitMarginExponent == other.ProfitMarginExponent && r.BootstrappingDuration == other.BootstrappingDuration && + return r.ProfitMarginExponent == other.ProfitMarginExponent && r.BootstrappingDuration == other.BootstrappingDuration && r.ManaShareCoefficient == other.ManaShareCoefficient && r.DecayBalancingConstantExponent == other.DecayBalancingConstantExponent && r.DecayBalancingConstant == other.DecayBalancingConstant && diff --git a/mana_decay_provider.go b/mana_decay_provider.go index 0c2b28516..fe5e4ede6 100644 --- a/mana_decay_provider.go +++ b/mana_decay_provider.go @@ -83,19 +83,19 @@ type ManaDecayProvider struct { func NewManaDecayProvider( timeProvider *TimeProvider, slotsPerEpochExponent uint8, - manaStructure *ManaStructure, + manaParameters *ManaParameters, ) *ManaDecayProvider { return &ManaDecayProvider{ timeProvider: timeProvider, slotsPerEpochExponent: uint64(slotsPerEpochExponent), - bitsCount: uint64(manaStructure.BitsCount), - generationRate: uint64(manaStructure.GenerationRate), - generationRateExponent: uint64(manaStructure.GenerationRateExponent), - decayFactors: lo.Map(manaStructure.DecayFactors, func(factor uint32) uint64 { return uint64(factor) }), - decayFactorsLength: uint64(len(manaStructure.DecayFactors)), - decayFactorsExponent: uint64(manaStructure.DecayFactorsExponent), - decayFactorEpochsSum: uint64(manaStructure.DecayFactorEpochsSum), - decayFactorEpochsSumExponent: uint64(manaStructure.DecayFactorEpochsSumExponent), + bitsCount: uint64(manaParameters.BitsCount), + generationRate: uint64(manaParameters.GenerationRate), + generationRateExponent: uint64(manaParameters.GenerationRateExponent), + decayFactors: lo.Map(manaParameters.DecayFactors, func(factor uint32) uint64 { return uint64(factor) }), + decayFactorsLength: uint64(len(manaParameters.DecayFactors)), + decayFactorsExponent: uint64(manaParameters.DecayFactorsExponent), + decayFactorEpochsSum: uint64(manaParameters.DecayFactorEpochsSum), + decayFactorEpochsSumExponent: uint64(manaParameters.DecayFactorEpochsSumExponent), } } diff --git a/mana_decay_provider_test.go b/mana_decay_provider_test.go index b2f743bc5..58ce58d0c 100644 --- a/mana_decay_provider_test.go +++ b/mana_decay_provider_test.go @@ -39,7 +39,7 @@ func TestMain(m *testing.M) { testManaDecayFactorEpochsSum = tpkg.ManaDecayFactorEpochsSum(betaPerYear, 1<