Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align naming: structure to parameters #564

Merged
merged 15 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion address_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion address_ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions address_implicit_account_creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion address_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion address_multi_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion address_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion address_restricted.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions allotment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -123,7 +123,7 @@ type ProtocolParameters interface {

StakingUnbondingPeriod() EpochIndex

ValidationBlocksPerSlot() uint16
ValidationBlocksPerSlot() uint8

PunishmentEpochs() EpochIndex

Expand Down
2 changes: 1 addition & 1 deletion api_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down
20 changes: 10 additions & 10 deletions api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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"`

Expand Down Expand Up @@ -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 &&
Expand Down
4 changes: 2 additions & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions api_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type v3api struct {
timeProvider *TimeProvider
manaDecayProvider *ManaDecayProvider
livenessThresholdDuration time.Duration
rentStructure *RentStructure
storageScoreStructure *StorageScoreStructure
maxBlockWork WorkScore
computedInitialReward uint64
computedFinalReward uint64
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -643,20 +643,20 @@ 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)
if err != nil {
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")
}
Expand Down
Loading
Loading