Skip to content

Commit

Permalink
Rename WorkScoreStructure to WorkScoreParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Oct 16, 2023
1 parent 7004432 commit ba8ef41
Show file tree
Hide file tree
Showing 55 changed files with 79 additions and 79 deletions.
2 changes: 1 addition & 1 deletion allotment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (a Allotments) Size() int {
return serializer.UInt16ByteSize + len(a)*(AccountIDLength+ManaSize)
}

func (a Allotments) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) {
func (a Allotments) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
// Allotments requires invocation of account managers, so requires extra work.
workScoreAllotments, err := workScoreStructure.Allotment.Multiply(len(a))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ type ProtocolParameters interface {
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
// WorkScoreParameters defines the work score structure used by the given network.
WorkScoreParameters() *WorkScoreParameters
// TokenSupply defines the current token supply on the network.
TokenSupply() BaseToken

Expand Down
6 changes: 3 additions & 3 deletions api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type basicProtocolParameters struct {

// 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"`
// WorkScoreParameters defines the work score structure 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 Down Expand Up @@ -63,7 +63,7 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
b.NetworkName == other.NetworkName &&
b.Bech32HRP == other.Bech32HRP &&
b.RentParameters.Equals(other.RentParameters) &&
b.WorkScoreStructure.Equals(other.WorkScoreStructure) &&
b.WorkScoreParameters.Equals(other.WorkScoreParameters) &&
b.TokenSupply == other.TokenSupply &&
b.GenesisUnixTimestamp == other.GenesisUnixTimestamp &&
b.SlotDurationInSeconds == other.SlotDurationInSeconds &&
Expand Down
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
iotago.WithRewardsOptions(10, 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","rentParameters":{"storageCost":"6","storageScoreFactorData":7,"storageScoreOffsetOutput":"8","storageScoreOffsetEd25519BlockIssuerKey":"9","storageScoreOffsetStakingFeature":"10","storageScoreOffsetDelegation":"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,"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}}`

jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion api_v3.go
Original file line number Diff line number Diff line change
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 Down
8 changes: 4 additions & 4 deletions api_v3_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (p *V3ProtocolParameters) RentParameters() *RentParameters {
return &p.basicProtocolParameters.RentParameters
}

func (p *V3ProtocolParameters) WorkScoreStructure() *WorkScoreStructure {
return &p.basicProtocolParameters.WorkScoreStructure
func (p *V3ProtocolParameters) WorkScoreParameters() *WorkScoreParameters {
return &p.basicProtocolParameters.WorkScoreParameters
}

func (p *V3ProtocolParameters) TokenSupply() BaseToken {
Expand Down Expand Up @@ -146,7 +146,7 @@ func (p *V3ProtocolParameters) String() string {
p.basicProtocolParameters.NetworkName,
p.basicProtocolParameters.Bech32HRP,
p.basicProtocolParameters.RentParameters,
p.basicProtocolParameters.WorkScoreStructure,
p.basicProtocolParameters.WorkScoreParameters,
p.basicProtocolParameters.TokenSupply,
p.basicProtocolParameters.GenesisUnixTimestamp,
p.basicProtocolParameters.SlotDurationInSeconds,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion builder/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion builder/block_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions builder/transaction_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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"))
}
Expand Down Expand Up @@ -345,7 +345,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()

Expand All @@ -364,12 +364,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")
}
Expand Down
2 changes: 1 addition & 1 deletion feat.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (f Features[T]) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc)
return sumCost
}

func (f Features[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) {
func (f Features[T]) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
var workScoreFeats WorkScore
for _, feat := range f {
workScoreFeat, err := feat.WorkScore(workScoreStructure)
Expand Down
2 changes: 1 addition & 1 deletion feat_blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *BlockIssuerFeature) StorageScore(rentStruct *RentStructure, _ StorageSc
return s.BlockIssuerKeys.StorageScore(rentStruct, nil)
}

func (s *BlockIssuerFeature) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) {
func (s *BlockIssuerFeature) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
// block issuer feature requires invocation of account and mana managers, so requires extra work.
return workScoreStructure.BlockIssuer, nil
}
Expand Down
2 changes: 1 addition & 1 deletion feat_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (s *IssuerFeature) StorageScore(rentStruct *RentStructure, _ StorageScoreFu
return s.Address.StorageScore(rentStruct, 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
}
Expand Down
2 changes: 1 addition & 1 deletion feat_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (s *MetadataFeature) StorageScore(_ *RentStructure, _ StorageScoreFunc) Sto
return 0
}

func (s *MetadataFeature) WorkScore(_ *WorkScoreStructure) (WorkScore, error) {
func (s *MetadataFeature) WorkScore(_ *WorkScoreParameters) (WorkScore, error) {
return 0, nil
}

Expand Down
2 changes: 1 addition & 1 deletion feat_native_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (n *NativeTokenFeature) StorageScore(_ *RentStructure, _ StorageScoreFunc)
return 0
}

func (n *NativeTokenFeature) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) {
func (n *NativeTokenFeature) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
return workScoreStructure.NativeToken, nil
}

Expand Down
2 changes: 1 addition & 1 deletion feat_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *SenderFeature) StorageScore(rentStruct *RentStructure, f StorageScoreFu
return s.Address.StorageScore(rentStruct, 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
}
Expand Down
2 changes: 1 addition & 1 deletion feat_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *StakingFeature) StorageScore(rentStruct *RentStructure, f StorageScoreF
return rentStruct.StorageScoreOffsetStakingFeature()
}

func (s *StakingFeature) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) {
func (s *StakingFeature) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
// staking feature changes require invokation of staking managers so require extra work.
return workScoreStructure.Staking, nil
}
Expand Down
2 changes: 1 addition & 1 deletion feat_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *TagFeature) StorageScore(rentStruct *RentStructure, f StorageScoreFunc)
return 0
}

func (s *TagFeature) WorkScore(_ *WorkScoreStructure) (WorkScore, error) {
func (s *TagFeature) WorkScore(_ *WorkScoreParameters) (WorkScore, error) {
return 0, nil
}

Expand Down
2 changes: 1 addition & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (in Inputs[T]) Size() int {
return sum
}

func (in Inputs[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) {
func (in Inputs[T]) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
var workScoreInputs WorkScore
for _, input := range in {
workScoreInput, err := input.WorkScore(workScoreStructure)
Expand Down
2 changes: 1 addition & 1 deletion input_block_issuance_credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
// context inputs require invocation of informations in the node, so requires extra work.
return workScoreStructure.ContextInput, nil
}
2 changes: 1 addition & 1 deletion input_commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
// context inputs require invocation of informations in the node, so requires extra work.
return workScoreStructure.ContextInput, nil
}
2 changes: 1 addition & 1 deletion input_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (in ContextInputs[T]) Clone() ContextInputs[T] {
return cpy
}

func (in ContextInputs[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) {
func (in ContextInputs[T]) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
var workScoreContextInputs WorkScore
for _, input := range in {
workScoreInput, err := input.WorkScore(workScoreStructure)
Expand Down
2 changes: 1 addition & 1 deletion input_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
// context inputs require invocation of informations in the node, so requires extra work.
return workScoreStructure.ContextInput, nil
}
2 changes: 1 addition & 1 deletion input_utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(workScoreStructure *WorkScoreParameters) (WorkScore, error) {
// inputs require lookup of the UTXO, so requires extra work.
return workScoreStructure.Input, nil
}
Loading

0 comments on commit ba8ef41

Please sign in to comment.