From ba8ef414898aaf6d0e17875a1e69d88bb6a038e8 Mon Sep 17 00:00:00 2001 From: jkrvivian Date: Mon, 16 Oct 2023 15:26:03 +0800 Subject: [PATCH] Rename WorkScoreStructure to WorkScoreParameters --- allotment.go | 2 +- api.go | 4 ++-- api_protocol_parameters.go | 6 +++--- api_test.go | 2 +- api_v3.go | 2 +- api_v3_protocol_parameters.go | 8 ++++---- block.go | 22 +++++++++++----------- builder/block_builder.go | 2 +- builder/block_builder_test.go | 2 +- builder/transaction_builder.go | 8 ++++---- feat.go | 2 +- feat_blockissuer.go | 2 +- feat_issuer.go | 2 +- feat_metadata.go | 2 +- feat_native_token.go | 2 +- feat_sender.go | 2 +- feat_staking.go | 2 +- feat_tag.go | 2 +- input.go | 2 +- input_block_issuance_credit.go | 2 +- input_commitment.go | 2 +- input_context.go | 2 +- input_reward.go | 2 +- input_utxo.go | 2 +- nodeclient/apimodels/core_test.go | 2 +- output.go | 2 +- output_account.go | 2 +- output_basic.go | 2 +- output_delegation.go | 2 +- output_foundry.go | 2 +- output_nft.go | 2 +- signature_ed25519.go | 2 +- signed_transaction.go | 2 +- tagged_data.go | 2 +- token_scheme_simple.go | 2 +- tpkg/util.go | 6 +++--- transaction.go | 2 +- transaction_essence.go | 2 +- unlock.go | 2 +- unlock_account.go | 2 +- unlock_cond.go | 2 +- unlock_cond_address.go | 2 +- unlock_cond_expiration.go | 2 +- unlock_cond_governor.go | 2 +- unlock_cond_imm_account.go | 2 +- unlock_cond_state_ctrl.go | 2 +- unlock_cond_storage_return.go | 2 +- unlock_cond_timelock.go | 2 +- unlock_empty.go | 2 +- unlock_multi.go | 2 +- unlock_nft.go | 2 +- unlock_reference.go | 2 +- unlock_signature.go | 2 +- workscore.go | 8 ++++---- workscore_test.go | 2 +- 55 files changed, 79 insertions(+), 79 deletions(-) diff --git a/allotment.go b/allotment.go index 291cd9eab..6e72094c7 100644 --- a/allotment.go +++ b/allotment.go @@ -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 { diff --git a/api.go b/api.go index 131fb250c..cdb01fc7d 100644 --- a/api.go +++ b/api.go @@ -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 diff --git a/api_protocol_parameters.go b/api_protocol_parameters.go index 4782889be..bb42436c1 100644 --- a/api_protocol_parameters.go +++ b/api_protocol_parameters.go @@ -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"` @@ -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 && diff --git a/api_test.go b/api_test.go index 5b27436d2..30bc9190a 100644 --- a/api_test.go +++ b/api_test.go @@ -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) diff --git a/api_v3.go b/api_v3.go index fda2b3099..aec0dd90a 100644 --- a/api_v3.go +++ b/api_v3.go @@ -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) diff --git a/api_v3_protocol_parameters.go b/api_v3_protocol_parameters.go index 4e9cbcb53..05e27b6aa 100644 --- a/api_v3_protocol_parameters.go +++ b/api_v3_protocol_parameters.go @@ -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 { @@ -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, @@ -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, 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/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 5bdaef780..421717b96 100644 --- a/builder/transaction_builder.go +++ b/builder/transaction_builder.go @@ -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")) } @@ -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() @@ -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") } diff --git a/feat.go b/feat.go index c1aca76f9..4da24be34 100644 --- a/feat.go +++ b/feat.go @@ -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) diff --git a/feat_blockissuer.go b/feat_blockissuer.go index 411934aa6..9252bc5b2 100644 --- a/feat_blockissuer.go +++ b/feat_blockissuer.go @@ -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 } diff --git a/feat_issuer.go b/feat_issuer.go index 2a59eabcd..2a9614912 100644 --- a/feat_issuer.go +++ b/feat_issuer.go @@ -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 } diff --git a/feat_metadata.go b/feat_metadata.go index 473e9ace8..c3299f175 100644 --- a/feat_metadata.go +++ b/feat_metadata.go @@ -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 } diff --git a/feat_native_token.go b/feat_native_token.go index 9c7729329..bfe115014 100644 --- a/feat_native_token.go +++ b/feat_native_token.go @@ -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 } diff --git a/feat_sender.go b/feat_sender.go index b05ae9a50..56b81a3e9 100644 --- a/feat_sender.go +++ b/feat_sender.go @@ -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 } diff --git a/feat_staking.go b/feat_staking.go index 2d9c307c5..d8fc35802 100644 --- a/feat_staking.go +++ b/feat_staking.go @@ -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 } diff --git a/feat_tag.go b/feat_tag.go index 2aee07fd6..95b9d81ce 100644 --- a/feat_tag.go +++ b/feat_tag.go @@ -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 } diff --git a/input.go b/input.go index c545ccf82..347c32964 100644 --- a/input.go +++ b/input.go @@ -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) diff --git a/input_block_issuance_credit.go b/input_block_issuance_credit.go index 2f0650ce0..265775dea 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(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // context inputs require invocation of informations in the node, so requires extra work. return workScoreStructure.ContextInput, nil } diff --git a/input_commitment.go b/input_commitment.go index b24370f6d..43a09dbbc 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(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // context inputs require invocation of informations in the node, so requires extra work. return workScoreStructure.ContextInput, nil } diff --git a/input_context.go b/input_context.go index 84ec6c18a..d4e9ba75d 100644 --- a/input_context.go +++ b/input_context.go @@ -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) diff --git a/input_reward.go b/input_reward.go index d344ed654..2da38471b 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(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // context inputs require invocation of informations in the node, so requires extra work. return workScoreStructure.ContextInput, nil } diff --git a/input_utxo.go b/input_utxo.go index 12ce5141d..49756404a 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(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // inputs require lookup of the UTXO, so requires extra work. return workScoreStructure.Input, nil } diff --git a/nodeclient/apimodels/core_test.go b/nodeclient/apimodels/core_test.go index 365d901b8..4ab14290d 100644 --- a/nodeclient/apimodels/core_test.go +++ b/nodeclient/apimodels/core_test.go @@ -61,7 +61,7 @@ func Test_InfoResponse(t *testing.T) { jsonResponse, err := api.JSONEncode(response) require.NoError(t, err) - expected := `{"name":"test","version":"2.0.0","status":{"isHealthy":false,"acceptedTangleTime":"1690879505000000000","relativeAcceptedTangleTime":"1690879505000000000","confirmedTangleTime":"1690879505000000000","relativeConfirmedTangleTime":"1690879505000000000","latestCommitmentId":"0x000000000000000000000000000000000000000000000000000000000000000000000000","latestFinalizedSlot":1,"latestAcceptedBlockSlot":2,"latestConfirmedBlockSlot":3,"pruningEpoch":4},"metrics":{"blocksPerSecond":"1.1E+00","confirmedBlocksPerSecond":"2.2E+00","confirmationRate":"3.3E+00"},"protocolParameters":[{"startEpoch":0,"parameters":{"type":0,"version":3,"networkName":"testnet","bech32Hrp":"rms","rentParameters":{"storageCost":"100","storageScoreFactorData":1,"storageScoreOffsetOutput":"10","storageScoreOffsetEd25519BlockIssuerKey":"100","storageScoreOffsetStakingFeature":"100","storageScoreOffsetDelegation":"100"},"workScoreStructure":{"dataByte":0,"block":1,"input":0,"contextInput":0,"output":0,"nativeToken":0,"staking":0,"blockIssuer":0,"allotment":0,"signatureEd25519":0},"tokenSupply":"1813620509061365","genesisUnixTimestamp":"1690879505","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"bitsCount":63,"generationRate":1,"generationRateExponent":17,"decayFactors":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],"decayFactorsExponent":32,"decayFactorEpochsSum":2420916375,"decayFactorEpochsSumExponent":21},"stakingUnbondingPeriod":10,"validationBlocksPerSlot":10,"punishmentEpochs":10,"livenessThresholdLowerBound":15,"livenessThresholdUpperBound":30,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"1","increase":"0","decrease":"0","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":7,"windowTargetRatio":5,"activationOffset":7},"rewardsParameters":{"validatorBlocksPerSlot":10,"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}}],"baseToken":{"name":"Shimmer","tickerSymbol":"SMR","unit":"SMR","subunit":"glow","decimals":6,"useMetricPrefix":false},"features":["test"]}` + expected := `{"name":"test","version":"2.0.0","status":{"isHealthy":false,"acceptedTangleTime":"1690879505000000000","relativeAcceptedTangleTime":"1690879505000000000","confirmedTangleTime":"1690879505000000000","relativeConfirmedTangleTime":"1690879505000000000","latestCommitmentId":"0x000000000000000000000000000000000000000000000000000000000000000000000000","latestFinalizedSlot":1,"latestAcceptedBlockSlot":2,"latestConfirmedBlockSlot":3,"pruningEpoch":4},"metrics":{"blocksPerSecond":"1.1E+00","confirmedBlocksPerSecond":"2.2E+00","confirmationRate":"3.3E+00"},"protocolParameters":[{"startEpoch":0,"parameters":{"type":0,"version":3,"networkName":"testnet","bech32Hrp":"rms","rentParameters":{"storageCost":"100","storageScoreFactorData":1,"storageScoreOffsetOutput":"10","storageScoreOffsetEd25519BlockIssuerKey":"100","storageScoreOffsetStakingFeature":"100","storageScoreOffsetDelegation":"100"},"workScoreParameters":{"dataByte":0,"block":1,"input":0,"contextInput":0,"output":0,"nativeToken":0,"staking":0,"blockIssuer":0,"allotment":0,"signatureEd25519":0},"tokenSupply":"1813620509061365","genesisUnixTimestamp":"1690879505","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"bitsCount":63,"generationRate":1,"generationRateExponent":17,"decayFactors":[4291249941,4287535805,4283824883,4280117173,4276412671,4272711377,4269013285,4265318395,4261626702,4257938205,4254252900,4250570785,4246891856,4243216112,4239543550,4235874166,4232207957,4228544922,4224885058,4221228361,4217574829,4213924459,4210277249,4206633195,4202992295,4199354547,4195719947,4192088493,4188460182,4184835011,4181212978,4177594080,4173978314,4170365677,4166756168,4163149782,4159546518,4155946372,4152349343,4148755427,4145164621,4141576923,4137992331,4134410840,4130832450,4127257157,4123684959,4120115852,4116549834,4112986903,4109427055,4105870289,4102316601,4098765988,4095218449,4091673981,4088132580,4084594244,4081058971,4077526757,4073997601,4070471499,4066948449,4063428449,4059911495,4056397585,4052886716,4049378886,4045874092,4042372332,4038873602,4035377901,4031885225,4028395572,4024908939,4021425325,4017944725,4014467138,4010992560,4007520990,4004052425,4000586862,3997124298,3993664731,3990208159,3986754578,3983303986,3979856381,3976411760,3972970120,3969531459,3966095774,3962663063,3959233323,3955806551,3952382745,3948961903,3945544021,3942129098,3938717130,3935308116,3931902052,3928498936,3925098765,3921701537,3918307250,3914915900,3911527486,3908142004,3904759453,3901379829,3898003131,3894629355,3891258499,3887890560,3884525537,3881163426,3877804224,3874447931,3871094542,3867744056,3864396469,3861051780,3857709986,3854371084,3851035072,3847701948,3844371708,3841044351,3837719873,3834398273,3831079548,3827763695,3824450713,3821140597,3817833347,3814528959,3811227431,3807928760,3804632945,3801339982,3798049869,3794762604,3791478184,3788196607,3784917870,3781641970,3778368907,3775098676,3771831275,3768566702,3765304955,3762046031,3758789928,3755536643,3752286174,3749038518,3745793673,3742551636,3739312405,3736075978,3732842352,3729611525,3726383494,3723158258,3719935812,3716716156,3713499286,3710285201,3707073897,3703865373,3700659626,3697456653,3694256453,3691059023,3687864360,3684672462,3681483326,3678296951,3675113334,3671932472,3668754363,3665579005,3662406395,3659236531,3656069411,3652905032,3649743392,3646584488,3643428318,3640274880,3637124172,3633976190,3630830933,3627688398,3624548583,3621411486,3618277104,3615145434,3612016476,3608890225,3605766680,3602645839,3599527699,3596412257,3593299512,3590189461,3587082102,3583977433,3580875450,3577776153,3574679537,3571585602,3568494345,3565405764,3562319855,3559236618,3556156049,3553078146,3550002907,3546930330,3543860413,3540793152,3537728546,3534666593,3531607290,3528550634,3525496624,3522445258,3519396533,3516350446,3513306995,3510266179,3507227995,3504192440,3501159513,3498129210,3495101531,3492076472,3489054031,3486034206,3483016995,3480002395,3476990404,3473981020,3470974241,3467970065,3464968488,3461969510,3458973127,3455979337,3452988139,3449999530,3447013507,3444030069,3441049213,3438070937,3435095238,3432122115,3429151566,3426183587,3423218178,3420255335,3417295056,3414337339,3411382183,3408429584,3405479541,3402532051,3399587112,3396644722,3393704878,3390767579,3387832823,3384900606,3381970927,3379043784,3376119175,3373197097,3370277548,3367360525,3364446028,3361534053,3358624598,3355717662,3352813241,3349911335,3347011940,3344115054,3341220676,3338328803,3335439433,3332552563,3329668193,3326786318,3323906939,3321030051,3318155653,3315283743,3312414319,3309547378,3306682918,3303820938,3300961435,3298104407,3295249852,3292397767,3289548151,3286701001,3283856315,3281014092,3278174328,3275337023,3272502173,3269669777,3266839832,3264012336,3261187288,3258364685,3255544525,3252726806,3249911526,3247098682,3244288273,3241480296,3238674749,3235871631,3233070939,3230272671,3227476825,3224683399,3221892391,3219103798,3216317619,3213533851,3210752492,3207973541,3205196995,3202422853,3199651111,3196881768,3194114823,3191350272,3188588114,3185828346,3183070967,3180315975,3177563367,3174813142,3172065297,3169319830,3166576739,3163836023,3161097679,3158361705,3155628099,3152896859,3150167982,3147441468,3144717314,3141995517,3139276076,3136558989,3133844253,3131131867],"decayFactorsExponent":32,"decayFactorEpochsSum":2420916375,"decayFactorEpochsSumExponent":21},"stakingUnbondingPeriod":10,"validationBlocksPerSlot":10,"punishmentEpochs":10,"livenessThresholdLowerBound":15,"livenessThresholdUpperBound":30,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"1","increase":"0","decrease":"0","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":7,"windowTargetRatio":5,"activationOffset":7},"rewardsParameters":{"validatorBlocksPerSlot":10,"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}}],"baseToken":{"name":"Shimmer","tickerSymbol":"SMR","unit":"SMR","subunit":"glow","decimals":6,"useMetricPrefix":false},"features":["test"]}` require.Equal(t, expected, string(jsonResponse)) decoded := new(apimodels.InfoResponse) diff --git a/output.go b/output.go index 1fed78f34..062f4861b 100644 --- a/output.go +++ b/output.go @@ -175,7 +175,7 @@ func (outputs Outputs[T]) Size() int { return sum } -func (outputs Outputs[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (outputs Outputs[T]) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { var workScoreOutputs WorkScore for _, output := range outputs { workScoreOutput, err := output.WorkScore(workScoreStructure) diff --git a/output_account.go b/output_account.go index 6b1d5a0cb..18147c8f0 100644 --- a/output_account.go +++ b/output_account.go @@ -215,7 +215,7 @@ func (a *AccountOutput) syntacticallyValidate() error { return nil } -func (a *AccountOutput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (a *AccountOutput) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { workScoreConditions, err := a.Conditions.WorkScore(workScoreStructure) if err != nil { return 0, err diff --git a/output_basic.go b/output_basic.go index 91f62ac21..5d0811bb0 100644 --- a/output_basic.go +++ b/output_basic.go @@ -77,7 +77,7 @@ func (e *BasicOutput) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc e.Features.StorageScore(rentStruct, nil) } -func (e *BasicOutput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (e *BasicOutput) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { workScoreConditions, err := e.Conditions.WorkScore(workScoreStructure) if err != nil { return 0, err diff --git a/output_delegation.go b/output_delegation.go index 17f5dacbf..ab228b209 100644 --- a/output_delegation.go +++ b/output_delegation.go @@ -195,7 +195,7 @@ func (d *DelegationOutput) syntacticallyValidate() error { return nil } -func (d *DelegationOutput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (d *DelegationOutput) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { return d.Conditions.WorkScore(workScoreStructure) } diff --git a/output_foundry.go b/output_foundry.go index 8eaeb0299..19a409e89 100644 --- a/output_foundry.go +++ b/output_foundry.go @@ -187,7 +187,7 @@ func (f *FoundryOutput) StorageScore(rentStruct *RentStructure, _ StorageScoreFu f.ImmutableFeatures.StorageScore(rentStruct, nil) } -func (f *FoundryOutput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (f *FoundryOutput) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { workScoreTokenScheme, err := f.TokenScheme.WorkScore(workScoreStructure) if err != nil { return 0, err diff --git a/output_nft.go b/output_nft.go index 8bd4ba085..867d1d2c8 100644 --- a/output_nft.go +++ b/output_nft.go @@ -169,7 +169,7 @@ func (n *NFTOutput) StorageScore(rentStruct *RentStructure, _ StorageScoreFunc) n.ImmutableFeatures.StorageScore(rentStruct, nil) } -func (n *NFTOutput) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (n *NFTOutput) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { workScoreConditions, err := n.Conditions.WorkScore(workScoreStructure) if err != nil { return 0, err diff --git a/signature_ed25519.go b/signature_ed25519.go index a6becf387..0d657cfd2 100644 --- a/signature_ed25519.go +++ b/signature_ed25519.go @@ -78,7 +78,7 @@ func (e *Ed25519Signature) Size() int { return serializer.SmallTypeDenotationByteSize + ed25519.PublicKeySize + ed25519.SignatureSize } -func (e *Ed25519Signature) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (e *Ed25519Signature) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // signature verification requires extra work return workScoreStructure.SignatureEd25519, nil } diff --git a/signed_transaction.go b/signed_transaction.go index 611d91edb..cf62bb1c2 100644 --- a/signed_transaction.go +++ b/signed_transaction.go @@ -116,7 +116,7 @@ func (t *SignedTransaction) syntacticallyValidate() error { return nil } -func (t *SignedTransaction) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (t *SignedTransaction) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // we account for the network traffic only on "Payload" level workScoreSignedTransactionData, err := workScoreStructure.DataByte.Multiply(t.Size()) if err != nil { diff --git a/tagged_data.go b/tagged_data.go index 3c36f2eaf..6fdc9dc83 100644 --- a/tagged_data.go +++ b/tagged_data.go @@ -31,7 +31,7 @@ func (u *TaggedData) Size() int { serializer.UInt32ByteSize + len(u.Data) } -func (u *TaggedData) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (u *TaggedData) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // we account for the network traffic only on "Payload" level return workScoreStructure.DataByte.Multiply(u.Size()) } diff --git a/token_scheme_simple.go b/token_scheme_simple.go index 8da6824ff..4aaeafb8c 100644 --- a/token_scheme_simple.go +++ b/token_scheme_simple.go @@ -184,7 +184,7 @@ func (s *SimpleTokenScheme) Size() int { return serializer.OneByte + serializer.UInt256ByteSize + serializer.UInt256ByteSize + serializer.UInt256ByteSize } -func (s *SimpleTokenScheme) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (s *SimpleTokenScheme) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { // we add the offset for a native token here, since the simple token scheme requires extra work for big.Int calculations return workScoreStructure.NativeToken, nil } diff --git a/tpkg/util.go b/tpkg/util.go index 2f42acbe7..d5bb9855b 100644 --- a/tpkg/util.go +++ b/tpkg/util.go @@ -676,7 +676,7 @@ func RandBlockID() iotago.BlockID { // RandProtocolBlock returns a random block with the given inner payload. func RandProtocolBlock(block iotago.Block, api iotago.API, rmc iotago.Mana) *iotago.ProtocolBlock { if basicBlock, isBasic := block.(*iotago.BasicBlock); isBasic { - burnedMana, err := basicBlock.ManaCost(rmc, api.ProtocolParameters().WorkScoreStructure()) + burnedMana, err := basicBlock.ManaCost(rmc, api.ProtocolParameters().WorkScoreParameters()) if err != nil { panic(err) } @@ -987,8 +987,8 @@ func RandWorkScore(max uint32) iotago.WorkScore { } // RandWorkscoreStructure produces random workscore structure. -func RandWorkscoreStructure() *iotago.WorkScoreStructure { - return &iotago.WorkScoreStructure{ +func RandWorkscoreStructure() *iotago.WorkScoreParameters { + return &iotago.WorkScoreParameters{ DataByte: RandWorkScore(math.MaxUint32), Block: RandWorkScore(math.MaxUint32), Input: RandWorkScore(math.MaxUint32), diff --git a/transaction.go b/transaction.go index e90ccd9d6..571fc3168 100644 --- a/transaction.go +++ b/transaction.go @@ -265,7 +265,7 @@ func (t *Transaction) syntacticallyValidate(api API) error { } // WorkScore calculates the Work Score of the Transaction. -func (t *Transaction) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (t *Transaction) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { workscoreTransactionEssence, err := t.TransactionEssence.WorkScore(workScoreStructure) if err != nil { return 0, err diff --git a/transaction_essence.go b/transaction_essence.go index d789b625a..3057d6a7a 100644 --- a/transaction_essence.go +++ b/transaction_essence.go @@ -87,7 +87,7 @@ func (u *TransactionEssence) Size() int { // // Does not specifically include the work score of the optional payload because that is already // included in the Work Score of the SignedTransaction. -func (u *TransactionEssence) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (u *TransactionEssence) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { workScoreContextInputs, err := u.ContextInputs.WorkScore(workScoreStructure) if err != nil { return 0, err diff --git a/unlock.go b/unlock.go index a9721eee5..fa4e43e3a 100644 --- a/unlock.go +++ b/unlock.go @@ -82,7 +82,7 @@ func (o Unlocks) Size() int { return sum } -func (o Unlocks) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (o Unlocks) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { var workScoreUnlocks WorkScore for _, unlock := range o { workScoreUnlock, err := unlock.WorkScore(workScoreStructure) diff --git a/unlock_account.go b/unlock_account.go index 7bbace381..07ef87f7d 100644 --- a/unlock_account.go +++ b/unlock_account.go @@ -39,6 +39,6 @@ func (r *AccountUnlock) Size() int { return serializer.SmallTypeDenotationByteSize + serializer.UInt16ByteSize } -func (r *AccountUnlock) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (r *AccountUnlock) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } diff --git a/unlock_cond.go b/unlock_cond.go index 9ea22997d..747e18f78 100644 --- a/unlock_cond.go +++ b/unlock_cond.go @@ -106,7 +106,7 @@ func (f UnlockConditions[T]) StorageScore(rentStruct *RentStructure, _ StorageSc return sumCost } -func (f UnlockConditions[T]) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (f UnlockConditions[T]) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { var workScoreUnlockConds WorkScore for _, unlockCond := range f { workScoreUnlockCond, err := unlockCond.WorkScore(workScoreStructure) diff --git a/unlock_cond_address.go b/unlock_cond_address.go index f1d32fed1..1014c47ec 100644 --- a/unlock_cond_address.go +++ b/unlock_cond_address.go @@ -18,7 +18,7 @@ func (s *AddressUnlockCondition) StorageScore(rentStruct *RentStructure, _ Stora return s.Address.StorageScore(rentStruct, nil) } -func (s *AddressUnlockCondition) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *AddressUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // AddressUnlockCondition does not require a signature check on creation, only consumption. return 0, nil } diff --git a/unlock_cond_expiration.go b/unlock_cond_expiration.go index fb5dedb7a..5cd127fd1 100644 --- a/unlock_cond_expiration.go +++ b/unlock_cond_expiration.go @@ -26,7 +26,7 @@ func (s *ExpirationUnlockCondition) StorageScore(rentStruct *RentStructure, _ St return s.ReturnAddress.StorageScore(rentStruct, nil) } -func (s *ExpirationUnlockCondition) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *ExpirationUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // ExpirationUnlockCondition does not require a signature check on creation, only consumption. return 0, nil } diff --git a/unlock_cond_governor.go b/unlock_cond_governor.go index 117246d78..d7802ebe2 100644 --- a/unlock_cond_governor.go +++ b/unlock_cond_governor.go @@ -18,7 +18,7 @@ func (s *GovernorAddressUnlockCondition) StorageScore(rentStruct *RentStructure, return s.Address.StorageScore(rentStruct, nil) } -func (s *GovernorAddressUnlockCondition) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *GovernorAddressUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // GovernorAddressUnlockCondition does not require a signature check on creation, only consumption. return 0, nil } diff --git a/unlock_cond_imm_account.go b/unlock_cond_imm_account.go index 68eefb797..4842a3662 100644 --- a/unlock_cond_imm_account.go +++ b/unlock_cond_imm_account.go @@ -20,7 +20,7 @@ func (s *ImmutableAccountUnlockCondition) StorageScore(rentStruct *RentStructure return s.Address.StorageScore(rentStruct, nil) } -func (s *ImmutableAccountUnlockCondition) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *ImmutableAccountUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // ImmutableAccountUnlockCondition does not require a signature check on creation, only consumption. return 0, nil } diff --git a/unlock_cond_state_ctrl.go b/unlock_cond_state_ctrl.go index 1c2c1fb74..82a6a8b71 100644 --- a/unlock_cond_state_ctrl.go +++ b/unlock_cond_state_ctrl.go @@ -18,7 +18,7 @@ func (s *StateControllerAddressUnlockCondition) StorageScore(rentStruct *RentStr return s.Address.StorageScore(rentStruct, nil) } -func (s *StateControllerAddressUnlockCondition) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *StateControllerAddressUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // StateControllerAddressUnlockCondition does not require a signature check on creation, only consumption. return 0, nil } diff --git a/unlock_cond_storage_return.go b/unlock_cond_storage_return.go index fa7a36eef..3846a2923 100644 --- a/unlock_cond_storage_return.go +++ b/unlock_cond_storage_return.go @@ -24,7 +24,7 @@ func (s *StorageDepositReturnUnlockCondition) StorageScore(rentStruct *RentStruc return s.ReturnAddress.StorageScore(rentStruct, nil) } -func (s *StorageDepositReturnUnlockCondition) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *StorageDepositReturnUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { // StorageDepositReturnUnlockCondition does not require a signature check on creation, only consumption. return 0, nil } diff --git a/unlock_cond_timelock.go b/unlock_cond_timelock.go index 13af0c9a8..ce52eba9b 100644 --- a/unlock_cond_timelock.go +++ b/unlock_cond_timelock.go @@ -22,7 +22,7 @@ func (s *TimelockUnlockCondition) StorageScore(_ *RentStructure, _ StorageScoreF return 0 } -func (s *TimelockUnlockCondition) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (s *TimelockUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } diff --git a/unlock_empty.go b/unlock_empty.go index 3e49b21e5..cb375cb8a 100644 --- a/unlock_empty.go +++ b/unlock_empty.go @@ -20,6 +20,6 @@ func (u *EmptyUnlock) Size() int { return serializer.SmallTypeDenotationByteSize } -func (u *EmptyUnlock) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (u *EmptyUnlock) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } diff --git a/unlock_multi.go b/unlock_multi.go index 002e44947..8c322cbbd 100644 --- a/unlock_multi.go +++ b/unlock_multi.go @@ -32,7 +32,7 @@ func (u *MultiUnlock) Size() int { return sum } -func (u *MultiUnlock) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (u *MultiUnlock) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { var sum WorkScore for _, unlock := range u.Unlocks { unlockWorkScore, err := unlock.WorkScore(workScoreStructure) diff --git a/unlock_nft.go b/unlock_nft.go index 6b14323e2..c6c2ab10f 100644 --- a/unlock_nft.go +++ b/unlock_nft.go @@ -39,6 +39,6 @@ func (r *NFTUnlock) Size() int { return serializer.SmallTypeDenotationByteSize + serializer.UInt16ByteSize } -func (r *NFTUnlock) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (r *NFTUnlock) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } diff --git a/unlock_reference.go b/unlock_reference.go index 29e219726..ee08a1792 100644 --- a/unlock_reference.go +++ b/unlock_reference.go @@ -39,6 +39,6 @@ func (r *ReferenceUnlock) Size() int { return serializer.SmallTypeDenotationByteSize + serializer.UInt16ByteSize } -func (r *ReferenceUnlock) WorkScore(_ *WorkScoreStructure) (WorkScore, error) { +func (r *ReferenceUnlock) WorkScore(_ *WorkScoreParameters) (WorkScore, error) { return 0, nil } diff --git a/unlock_signature.go b/unlock_signature.go index becdae89a..5ee9ea38f 100644 --- a/unlock_signature.go +++ b/unlock_signature.go @@ -25,6 +25,6 @@ func (s *SignatureUnlock) Size() int { return serializer.OneByte + s.Signature.Size() } -func (s *SignatureUnlock) WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) { +func (s *SignatureUnlock) WorkScore(workScoreStructure *WorkScoreParameters) (WorkScore, error) { return s.Signature.WorkScore(workScoreStructure) } diff --git a/workscore.go b/workscore.go index dc173bb00..ef5ad4ed2 100644 --- a/workscore.go +++ b/workscore.go @@ -33,7 +33,7 @@ func (w WorkScore) Multiply(in int) (WorkScore, error) { return result, nil } -type WorkScoreStructure struct { +type WorkScoreParameters struct { // DataByte accounts for the network traffic per byte. DataByte WorkScore `serix:"0,mapKey=dataByte"` // Block accounts for work done to process a block in the node software. @@ -58,7 +58,7 @@ type WorkScoreStructure struct { SignatureEd25519 WorkScore `serix:"9,mapKey=signatureEd25519"` } -func (w WorkScoreStructure) Equals(other WorkScoreStructure) bool { +func (w WorkScoreParameters) Equals(other WorkScoreParameters) bool { return w.DataByte == other.DataByte && w.Block == other.Block && w.Input == other.Input && @@ -72,7 +72,7 @@ func (w WorkScoreStructure) Equals(other WorkScoreStructure) bool { } // MaxBlockWork is the maximum work score a block can have. -func (w WorkScoreStructure) MaxBlockWork() (WorkScore, error) { +func (w WorkScoreParameters) MaxBlockWork() (WorkScore, error) { var maxBlockWork WorkScore // max basic block payload size data factor dataFactorBytes, err := w.DataByte.Multiply(MaxPayloadSize) @@ -138,5 +138,5 @@ type ProcessableObject interface { // WorkScore returns the cost this object has in terms of computation // requirements for a node to process it. These costs attempt to encapsulate all processing steps // carried out on this object throughout its life in the node. - WorkScore(workScoreStructure *WorkScoreStructure) (WorkScore, error) + WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) } diff --git a/workscore_test.go b/workscore_test.go index 697d9eee3..73edbcc33 100644 --- a/workscore_test.go +++ b/workscore_test.go @@ -84,7 +84,7 @@ func TestTransactionEssenceWorkScore(t *testing.T) { Build(iotago.NewInMemoryAddressSigner(iotago.AddressKeys{Address: addr, Keys: ed25519.PrivateKey(keyPair.PrivateKey[:])})) require.NoError(t, err) - workScoreStructure := api.ProtocolParameters().WorkScoreStructure() + workScoreStructure := api.ProtocolParameters().WorkScoreParameters() workScore, err := tx.WorkScore(workScoreStructure) require.NoError(t, err)