diff --git a/components/debugapi/commitment.go b/components/debugapi/commitment.go index 4319459c4..815d5319a 100644 --- a/components/debugapi/commitment.go +++ b/components/debugapi/commitment.go @@ -95,9 +95,17 @@ func prepareCommitmentGraph(g *graphviz.Graphviz, rootCommitment *protocol.Commi } func createNode(graph *cgraph.Graph, commitment *protocol.Commitment) (*cgraph.Node, error) { - node, err := graph.Node(fmt.Sprintf("%d: %s", commitment.ID().Slot(), commitment.ID().String()[:8])) + node, err := graph.CreateNode(fmt.Sprintf("%d-%s", commitment.ID().Slot(), commitment.ID().Identifier().String()[:8])) if err != nil { - return nil, ierrors.Wrapf(err, "could not create node %s", commitment.ID().String()[:8]) + return nil, ierrors.Wrapf(err, "could not retrieve node %s", commitment.ID().Identifier().String()[:8]) + } + if node != nil { + return node, nil + } + + node, err = graph.CreateNode(fmt.Sprintf("%d-%s", commitment.ID().Slot(), commitment.ID().Identifier().String()[:8])) + if err != nil { + return nil, ierrors.Wrapf(err, "could not create node %s", commitment.ID().Identifier().String()[:8]) } return node, nil diff --git a/components/inx/server_commitments.go b/components/inx/server_commitments.go index 1e8fc3961..fafb7445e 100644 --- a/components/inx/server_commitments.go +++ b/components/inx/server_commitments.go @@ -8,6 +8,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/kvstore" + "github.com/iotaledger/hive.go/runtime/event" "github.com/iotaledger/hive.go/runtime/workerpool" inx "github.com/iotaledger/inx/go" "github.com/iotaledger/iota-core/pkg/model" @@ -142,7 +143,7 @@ func (s *Server) ListenToCommitments(req *inx.SlotRangeRequest, srv inx.INX_List case done: cancel() } - }).Unhook + }, event.WithWorkerPool(wp)).Unhook <-ctx.Done() unhook() diff --git a/components/inx/server_utxo.go b/components/inx/server_utxo.go index fd815e01a..8724f5f90 100644 --- a/components/inx/server_utxo.go +++ b/components/inx/server_utxo.go @@ -346,7 +346,7 @@ func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_Li case done: cancel() } - }).Unhook + }, event.WithWorkerPool(wp)).Unhook <-ctx.Done() unhook() diff --git a/components/restapi/core/accounts.go b/components/restapi/core/accounts.go index d6d379fd5..f324acc29 100644 --- a/components/restapi/core/accounts.go +++ b/components/restapi/core/accounts.go @@ -185,7 +185,7 @@ func rewardsByOutputID(c echo.Context) (*api.ManaRewardsResponse, error) { } var reward iotago.Mana - var actualStart, actualEnd iotago.EpochIndex + var firstRewardEpoch, lastRewardEpoch iotago.EpochIndex switch utxoOutput.OutputType() { case iotago.OutputAccount: //nolint:forcetypeassert @@ -198,33 +198,38 @@ func rewardsByOutputID(c echo.Context) (*api.ManaRewardsResponse, error) { //nolint:forcetypeassert stakingFeature := feature.(*iotago.StakingFeature) + apiForSlot := deps.Protocol.APIForSlot(slotIndex) + futureBoundedSlotIndex := slotIndex + apiForSlot.ProtocolParameters().MinCommittableAge() + claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) + // check if the account is a validator - reward, actualStart, actualEnd, err = deps.Protocol.Engines.Main.Get().SybilProtection.ValidatorReward( + reward, firstRewardEpoch, lastRewardEpoch, err = deps.Protocol.Engines.Main.Get().SybilProtection.ValidatorReward( accountOutput.AccountID, - stakingFeature.StakedAmount, - stakingFeature.StartEpoch, - stakingFeature.EndEpoch, + stakingFeature, + claimingEpoch, ) case iotago.OutputDelegation: //nolint:forcetypeassert delegationOutput := utxoOutput.Output().(*iotago.DelegationOutput) delegationEnd := delegationOutput.EndEpoch + apiForSlot := deps.Protocol.APIForSlot(slotIndex) + futureBoundedSlotIndex := slotIndex + apiForSlot.ProtocolParameters().MinCommittableAge() + claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) // If Delegation ID is zeroed, the output is in delegating state, which means its End Epoch is not set and we must use the // "last epoch" for the rewards calculation. // In this case the calculation must be consistent with the rewards calculation at execution time, so a client can specify // a slot index explicitly, which should be equal to the slot it uses as the commitment input for the claiming transaction. if delegationOutput.DelegationID.Empty() { - apiForSlot := deps.Protocol.APIForSlot(slotIndex) - futureBoundedSlotIndex := slotIndex + apiForSlot.ProtocolParameters().MinCommittableAge() - delegationEnd = apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) - iotago.EpochIndex(1) + delegationEnd = claimingEpoch - iotago.EpochIndex(1) } - reward, actualStart, actualEnd, err = deps.Protocol.Engines.Main.Get().SybilProtection.DelegatorReward( + reward, firstRewardEpoch, lastRewardEpoch, err = deps.Protocol.Engines.Main.Get().SybilProtection.DelegatorReward( delegationOutput.ValidatorAddress.AccountID(), delegationOutput.DelegatedAmount, delegationOutput.StartEpoch, delegationEnd, + claimingEpoch, ) } if err != nil { @@ -232,8 +237,8 @@ func rewardsByOutputID(c echo.Context) (*api.ManaRewardsResponse, error) { } return &api.ManaRewardsResponse{ - StartEpoch: actualStart, - EndEpoch: actualEnd, + StartEpoch: firstRewardEpoch, + EndEpoch: lastRewardEpoch, Rewards: reward, }, nil } diff --git a/components/restapi/core/blocks.go b/components/restapi/core/blocks.go index bab9de006..cd3b91bd0 100644 --- a/components/restapi/core/blocks.go +++ b/components/restapi/core/blocks.go @@ -1,6 +1,8 @@ package core import ( + "time" + "github.com/labstack/echo/v4" "github.com/iotaledger/hive.go/ierrors" @@ -84,12 +86,28 @@ func blockIssuance() (*api.IssuanceBlockHeaderResponse, error) { return nil, ierrors.Wrap(echo.ErrServiceUnavailable, "no strong parents available") } + // get the latest parent block issuing time + var latestParentBlockIssuingTime time.Time + for _, parentType := range []iotago.ParentsType{iotago.StrongParentType, iotago.WeakParentType, iotago.ShallowLikeParentType} { + for _, blockID := range references[parentType] { + block, exists := deps.Protocol.Engines.Main.Get().Block(blockID) + if !exists { + return nil, ierrors.Wrapf(echo.ErrNotFound, "no block found for parent, block ID: %s", blockID.ToHex()) + } + + if latestParentBlockIssuingTime.Before(block.ProtocolBlock().Header.IssuingTime) { + latestParentBlockIssuingTime = block.ProtocolBlock().Header.IssuingTime + } + } + } + resp := &api.IssuanceBlockHeaderResponse{ - StrongParents: references[iotago.StrongParentType], - WeakParents: references[iotago.WeakParentType], - ShallowLikeParents: references[iotago.ShallowLikeParentType], - LatestFinalizedSlot: deps.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot(), - LatestCommitment: deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Commitment(), + StrongParents: references[iotago.StrongParentType], + WeakParents: references[iotago.WeakParentType], + ShallowLikeParents: references[iotago.ShallowLikeParentType], + LatestParentBlockIssuingTime: latestParentBlockIssuingTime, + LatestFinalizedSlot: deps.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot(), + LatestCommitment: deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Commitment(), } return resp, nil diff --git a/components/restapi/core/commitment.go b/components/restapi/core/commitment.go index 7b9a1cd8d..12912f0d9 100644 --- a/components/restapi/core/commitment.go +++ b/components/restapi/core/commitment.go @@ -76,3 +76,33 @@ func getUTXOChanges(commitmentID iotago.CommitmentID) (*api.UTXOChangesResponse, ConsumedOutputs: consumedOutputs, }, nil } + +func getUTXOChangesFull(commitmentID iotago.CommitmentID) (*api.UTXOChangesFullResponse, error) { + diffs, err := deps.Protocol.Engines.Main.Get().Ledger.SlotDiffs(commitmentID.Slot()) + if err != nil { + return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to get slot diffs, commitmentID: %s, slot: %d, error: %w", commitmentID, commitmentID.Slot(), err) + } + + createdOutputs := make([]*api.OutputWithID, len(diffs.Outputs)) + consumedOutputs := make([]*api.OutputWithID, len(diffs.Spents)) + + for i, output := range diffs.Outputs { + createdOutputs[i] = &api.OutputWithID{ + OutputID: output.OutputID(), + Output: output.Output(), + } + } + + for i, output := range diffs.Spents { + consumedOutputs[i] = &api.OutputWithID{ + OutputID: output.OutputID(), + Output: output.Output().Output(), + } + } + + return &api.UTXOChangesFullResponse{ + CommitmentID: commitmentID, + CreatedOutputs: createdOutputs, + ConsumedOutputs: consumedOutputs, + }, nil +} diff --git a/components/restapi/core/component.go b/components/restapi/core/component.go index 603b0d375..cd6104963 100644 --- a/components/restapi/core/component.go +++ b/components/restapi/core/component.go @@ -142,6 +142,26 @@ func configure() error { return responseByHeader(c, resp) }) + routeGroup.GET(api.EndpointWithEchoParameters(api.CoreEndpointCommitmentByIDUTXOChangesFull), func(c echo.Context) error { + commitmentID, err := httpserver.ParseCommitmentIDParam(c, api.ParameterCommitmentID) + if err != nil { + return err + } + + // load the commitment to check if it matches the given commitmentID + commitment, err := getCommitmentByID(commitmentID) + if err != nil { + return err + } + + resp, err := getUTXOChangesFull(commitment.ID()) + if err != nil { + return err + } + + return responseByHeader(c, resp) + }) + routeGroup.GET(api.EndpointWithEchoParameters(api.CoreEndpointCommitmentBySlot), func(c echo.Context) error { index, err := httpserver.ParseSlotParam(c, api.ParameterSlot) if err != nil { @@ -175,6 +195,25 @@ func configure() error { return responseByHeader(c, resp) }) + routeGroup.GET(api.EndpointWithEchoParameters(api.CoreEndpointCommitmentBySlotUTXOChangesFull), func(c echo.Context) error { + slot, err := httpserver.ParseSlotParam(c, api.ParameterSlot) + if err != nil { + return err + } + + commitment, err := getCommitmentBySlot(slot) + if err != nil { + return err + } + + resp, err := getUTXOChangesFull(commitment.ID()) + if err != nil { + return err + } + + return responseByHeader(c, resp) + }) + routeGroup.GET(api.EndpointWithEchoParameters(api.CoreEndpointOutput), func(c echo.Context) error { resp, err := outputByID(c) if err != nil { diff --git a/go.mod b/go.mod index 9bd6b2427..2295c1ea1 100644 --- a/go.mod +++ b/go.mod @@ -11,22 +11,22 @@ require ( github.com/gorilla/websocket v1.5.1 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/app v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39 - github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39 + github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/logger v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39 - github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221 - github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 - github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d + github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c + github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f + github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e + github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5 github.com/labstack/echo/v4 v4.11.3 github.com/labstack/gommon v0.4.1 github.com/libp2p/go-libp2p v0.32.0 @@ -140,7 +140,7 @@ require ( github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect - github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect + github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pokt-network/smt v0.6.1 // indirect @@ -155,7 +155,7 @@ require ( github.com/raulk/go-watchdog v1.3.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect @@ -175,7 +175,7 @@ require ( golang.org/x/sync v0.5.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.4.0 // indirect + golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.14.0 // indirect gonum.org/v1/gonum v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect diff --git a/go.sum b/go.sum index 7a31029ce..ea71d4d30 100644 --- a/go.sum +++ b/go.sum @@ -277,38 +277,38 @@ github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 h1:dTrD7X2PT github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7/go.mod h1:ZRdPu684P0fQ1z8sXz4dj9H5LWHhz4a9oCtvjunkSrw= github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39 h1:jxoBAPgC4I73pAwvEWI2IUCxiI1xN68IaFZ5WC1D3ek= github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39/go.mod h1:gbUvr01B5ha530GnNm8K2OsHXOd2BtzBYOMxyTX3iDg= -github.com/iotaledger/hive.go/app v0.0.0-20231205131244-472357435a39 h1:B+SzeGOUyIROHfGjoYLJRPT/GL2u2X8pe3bS5avBbZc= -github.com/iotaledger/hive.go/app v0.0.0-20231205131244-472357435a39/go.mod h1:+riYmeLApkLlj4+EpuJpEJAsj/KGfD7cqLGy7oTsPOM= -github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39 h1:zv6hp2CsJikP2jdkOjngJmpUVjhC2UfiIFN6yGvo4jA= -github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s= -github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39 h1:qAIj5vpAojkrORpOflrUYJ6iFL4osUkyP6Vr7/WK9BI= -github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39/go.mod h1:CdixkrB7VdQzEDlVuwsxPtsiJL/WXrQgz3PELIqlLko= -github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39 h1:5lXV8tI2PlMWraa9eT5xGasNdiMaAYd1159mzXdX1xM= -github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39/go.mod h1:OQ9EVTTQT1mkO/16BgwSIyQlAhEg+Cptud/yutevWsI= -github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39 h1:axE2+FtJQpAQ40KerOISEzHndqv79h7zYs8NZ7r0jNQ= -github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= -github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39 h1:KpHT3dYj+WoFnAzkW4EPluWHuhzErTree0+AF/KVBTU= -github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= +github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad h1:v7dkbVLSsmzgOWT2vjvv1MdKQXvqFbvIkx8mvh6VK7g= +github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:hTHKGFbZnuiW8yEgDuuL7ZjQTCnl8bXyHLmj3LPa648= +github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad h1:4XL7IIvdsWHxSKQfU+sgq3H9egN54053LF9TwMfDcTg= +github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s= +github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad h1:iNzb/Oy/nucIOXOzRcwSqqFsaeKwr2JZpZYSLp8xjlE= +github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad/go.mod h1:CO28KMA6Pp5LJPiigPQQ276zQofES+jMod08U5pyRFA= +github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad h1:pUL2UZbF4S8FIV7uKo9p+IGfZ658K1VNorQ6rzDMRvs= +github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:7vHoF//1Pt3nu0l8nDIw7bEgv2GfbL3kSgjp7Rdqhd4= +github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad h1:adLrD6dOEkM5Xdg6AOPt9/HYqy/pQ5FrprDpW4/VqUU= +github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:NmZRIoxtL6iQdVK6n5W+JOx58K/0Yn8k7WuSvpKPQ+M= +github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad h1:WDl58zJKHfwbzHs+ZB8Jq3YNgVQE5Neu2NeaX3FZuyU= +github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39 h1:Gp2h+Els9cTVYYnYsHX3zLuixb0XggIj2okK570aKww= github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39/go.mod h1:ytfKoHr/nF8u0y0G4mamfG0yjFtJiJVk0kgjnPOtsSY= -github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39 h1:Di2G2i/hGyhe3D8j/MsnZqnx1yJBiMdbXDIrtbWpe8g= -github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39/go.mod h1:6Ee7i6b4tuTHuRYnPP8VUb0wr9XFI5qlqtnttBd9jRg= -github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39 h1:kYj16hPQ0iH+1srDaIj4wZCGH5qrhsFpHkLbh3Ob1Bs= -github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39/go.mod h1:vzO4/wRkEJDEZb/9fD10oKU9k1bj4qLir2Uhl5U1FkM= -github.com/iotaledger/hive.go/logger v0.0.0-20231205131244-472357435a39 h1:m4b7gNQu1HI+LH1m0oAvuFnpp7/EC/iPGHK7ImWNk3w= -github.com/iotaledger/hive.go/logger v0.0.0-20231205131244-472357435a39/go.mod h1:w1psHM2MuKsen1WdsPKrpqElYH7ZOQ+YdQIgJZg4HTo= -github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39 h1:O6tJNVV544ts/DKIIfHQJNGXIPZgntR1DJ4e+jPR9rQ= -github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39/go.mod h1:DrZPvUvLarK8C2qb+3H2vdypp/MuhpQmB3iMJbDCr/Q= -github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39 h1:GPa5qfHm59jqY3pff0eCnt/mpWFm6fibVK/n/E+Pfyk= -github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8= -github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39 h1:gatLNIqLC/MAR5qlj+413/y0LmyfKC0QL2BKXLniD0M= -github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221 h1:+ozrau44uPy2kYv2fuj2Wks8+VkXR62WB9zONOJgzdE= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221/go.mod h1:6cLX3gnhP0WL+Q+mf3/rIqfACe5fWKVR8luPXWh2xiY= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 h1:XdhojOpZ0t0pJFyNO0zlBogSAUrhEI67eCpTC9H6sGM= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665/go.mod h1:obK1N42oafGA7EH6zC4VX2fKh7jTa3WnIa9h1azfxq0= -github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d h1:MPklxa8jW4/EgDm/LEzf6orxjik7U+vMUW/ToGT1Zqg= -github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d/go.mod h1:lCk9rhP3B5pX9BKhzR+Jobq4xPd+GHlqgF4Ga+eQfWA= +github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad h1:qpCsjw+InLL824QPu3lY/osck4DhucBKhCs5/E8OH+A= +github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:ETXGXymFyNcUq2t4I9e7ZK18f9bxUWYat4pjZ9W0rWc= +github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c h1:Ksts6VjPj9y0o2Nis+2tHtDGWITNJ4yju87ZlHLPuOo= +github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c/go.mod h1:Td3R6QmYw0svZI1GuZ/tN9s0VNaHassXSKLCc70aX9w= +github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad h1:fazCxogqOLDEPNDPWYDLTDpYmwgTJgIaC2Z6VN52S4M= +github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:hVaVODS+Uik0obf3SVEHFQNruUko/uqIgD/GKwhn49M= +github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad h1:HpupWK8iqFt+Sdogkh2/N8ojalmevYy+FzhjOuy7Y7E= +github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:Z9NFsByMh1Kf98f3v3ifeZRycbS2db1hjswTQG1MxnE= +github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad h1:c8uwbBZDqpiCNN9/9Jji7Z4lL0GdVnORp8WMouiuknk= +github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8= +github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad h1:VC3OgdSbyngY7/gxVj66fKd/nGmN6P0/myr348nx7vA= +github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f h1:V68Ijq1A64gB9r0Rhc4ybLGH66rXqZ2Ly0L4uuaLrMg= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f/go.mod h1:Dy3Gv4Dn1zufB177x6IXETP3zTeiWQ1+HMVQR0Bt/ew= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e h1:jbtiUlmTpTdGiRBW1pniPSqRcDMJaIW8fGS+uORryas= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e/go.mod h1:zEb9onVHnDUStl5SsFBj7H0HBKfIN0c/pUND8Llfqp8= +github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5 h1:0KgQFpVRnKd6CdCwXo3Kg/SL27xkeKh2SMoU5G1TkZk= +github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5/go.mod h1:tiswk1O1wSAi9GE6tD1j43+bLmWU9Je07aZLaJ0+Ha0= github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI= github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= @@ -521,8 +521,8 @@ github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAv github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= +github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5 h1:+qIP3OMrT7SN5kLnTcVEISPOMB/97RyAKTg1UWA738E= +github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -623,8 +623,8 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= -github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -831,8 +831,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY= -golang.org/x/time v0.4.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/pkg/protocol/chains.go b/pkg/protocol/chains.go index 9704fca55..97af7125f 100644 --- a/pkg/protocol/chains.go +++ b/pkg/protocol/chains.go @@ -55,7 +55,7 @@ func newChains(protocol *Protocol) *Chains { shutdown := lo.Batch( c.initLogger(protocol.NewChildLogger("Chains")), - c.initChainSwitching(protocol.Options.ChainSwitchingThreshold), + c.initChainSwitching(), protocol.Constructed.WithNonEmptyValue(func(_ bool) (shutdown func()) { return c.deriveLatestSeenSlot(protocol) @@ -92,7 +92,7 @@ func (c *Chains) initLogger(logger log.Logger, shutdownLogger func()) (shutdown } // initChainSwitching initializes the chain switching logic. -func (c *Chains) initChainSwitching(chainSwitchingThreshold iotago.SlotIndex) (shutdown func()) { +func (c *Chains) initChainSwitching() (shutdown func()) { mainChain := c.newChain() mainChain.StartEngine.Set(true) @@ -102,6 +102,7 @@ func (c *Chains) initChainSwitching(chainSwitchingThreshold iotago.SlotIndex) (s forkingPointBelowChainSwitchingThreshold := func(chain *Chain) func(_ *Commitment, latestCommitment *Commitment) bool { return func(_ *Commitment, latestCommitment *Commitment) bool { forkingPoint := chain.ForkingPoint.Get() + chainSwitchingThreshold := iotago.SlotIndex(c.protocol.APIForSlot(latestCommitment.Slot()).ProtocolParameters().ChainSwitchingThreshold()) return forkingPoint != nil && latestCommitment != nil && (latestCommitment.ID().Slot()-forkingPoint.ID().Slot()) > chainSwitchingThreshold } diff --git a/pkg/protocol/engine/accounts/accountsledger/testsuite_test.go b/pkg/protocol/engine/accounts/accountsledger/testsuite_test.go index 51f2247bc..fecb06637 100644 --- a/pkg/protocol/engine/accounts/accountsledger/testsuite_test.go +++ b/pkg/protocol/engine/accounts/accountsledger/testsuite_test.go @@ -38,7 +38,7 @@ type TestSuite struct { } func NewTestSuite(test *testing.T) *TestSuite { - testAPI := tpkg.TestAPI + testAPI := tpkg.ZeroCostTestAPI t := &TestSuite{ T: test, @@ -65,7 +65,7 @@ func (t *TestSuite) initAccountLedger() *accountsledger.Manager { prunableStores[slot] = mapdb.NewMapDB() } - p := slotstore.NewAccountDiffs(slot, prunableStores[slot], tpkg.TestAPI) + p := slotstore.NewAccountDiffs(slot, prunableStores[slot], tpkg.ZeroCostTestAPI) return p, nil } @@ -187,8 +187,8 @@ func (t *TestSuite) ApplySlotActions(slot iotago.SlotIndex, rmc iotago.Mana, act } func (t *TestSuite) createBlockWithRMC(accountID iotago.AccountID, slot iotago.SlotIndex, rmc iotago.Mana) *blocks.Block { - innerBlock := tpkg.RandBasicBlockWithIssuerAndRMC(tpkg.TestAPI, accountID, rmc) - innerBlock.Header.IssuingTime = tpkg.TestAPI.TimeProvider().SlotStartTime(slot) + innerBlock := tpkg.RandBasicBlockWithIssuerAndRMC(tpkg.ZeroCostTestAPI, accountID, rmc) + innerBlock.Header.IssuingTime = tpkg.ZeroCostTestAPI.TimeProvider().SlotStartTime(slot) modelBlock, err := model.BlockFromBlock(innerBlock) require.NoError(t.T, err) diff --git a/pkg/protocol/engine/accounts/mana/manager_test.go b/pkg/protocol/engine/accounts/mana/manager_test.go index 1951737f7..16511364e 100644 --- a/pkg/protocol/engine/accounts/mana/manager_test.go +++ b/pkg/protocol/engine/accounts/mana/manager_test.go @@ -24,7 +24,7 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) { switch id { case accountIDOverflow: return utxoledger.CreateOutput( - iotago.SingleVersionProvider(tpkg.TestAPI), + iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), iotago.OutputIDFromTransactionIDAndIndex(iotago.NewTransactionID(0, tpkg.Rand32ByteArray()), 0), tpkg.RandBlockID(), tpkg.RandSlot(), @@ -33,11 +33,11 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) { Mana: iotago.MaxMana/2 + iotago.MaxMana/4, AccountID: accountIDOverflow, }, - lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.TestAPI, tpkg.Rand32ByteArray(), tpkg.RandSlot(), iotago.TxEssenceOutputs{tpkg.RandBasicOutput(iotago.AddressEd25519)}, 0)), + lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.ZeroCostTestAPI, tpkg.Rand32ByteArray(), tpkg.RandSlot(), iotago.TxEssenceOutputs{tpkg.RandBasicOutput(iotago.AddressEd25519)}, 0)), ), nil case accountIDRecentOutput: return utxoledger.CreateOutput( - iotago.SingleVersionProvider(tpkg.TestAPI), + iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), iotago.OutputIDFromTransactionIDAndIndex(iotago.NewTransactionID(1, tpkg.Rand32ByteArray()), 0), tpkg.RandBlockID(), tpkg.RandSlot(), @@ -46,11 +46,11 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) { Mana: iotago.MaxMana / 2, AccountID: id, }, - lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.TestAPI, tpkg.Rand32ByteArray(), tpkg.RandSlot(), iotago.TxEssenceOutputs{tpkg.RandBasicOutput(iotago.AddressEd25519)}, 0)), + lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.ZeroCostTestAPI, tpkg.Rand32ByteArray(), tpkg.RandSlot(), iotago.TxEssenceOutputs{tpkg.RandBasicOutput(iotago.AddressEd25519)}, 0)), ), nil default: return utxoledger.CreateOutput( - iotago.SingleVersionProvider(tpkg.TestAPI), + iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), iotago.OutputIDFromTransactionIDAndIndex(iotago.NewTransactionID(0, tpkg.Rand32ByteArray()), 0), tpkg.RandBlockID(), tpkg.RandSlot(), @@ -59,7 +59,7 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) { Mana: iotago.MaxMana / 2, AccountID: id, }, - lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.TestAPI, tpkg.Rand32ByteArray(), tpkg.RandSlot(), iotago.TxEssenceOutputs{tpkg.RandBasicOutput(iotago.AddressEd25519)}, 0)), + lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.ZeroCostTestAPI, tpkg.Rand32ByteArray(), tpkg.RandSlot(), iotago.TxEssenceOutputs{tpkg.RandBasicOutput(iotago.AddressEd25519)}, 0)), ), nil } } @@ -100,7 +100,7 @@ func TestManager_GetManaOnAccountOverflow(t *testing.T) { } } - manager := NewManager(iotago.SingleVersionProvider(tpkg.TestAPI), outputRetriever, accountRetriever) + manager := NewManager(iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), outputRetriever, accountRetriever) manaDecayProvider := manager.apiProvider.LatestAPI().ManaDecayProvider() // The value for this account will overflow because component values are too big. diff --git a/pkg/protocol/engine/attestation/slotattestation/testframework_test.go b/pkg/protocol/engine/attestation/slotattestation/testframework_test.go index ed0cef175..67e428c0d 100644 --- a/pkg/protocol/engine/attestation/slotattestation/testframework_test.go +++ b/pkg/protocol/engine/attestation/slotattestation/testframework_test.go @@ -70,10 +70,8 @@ func NewTestFramework(test *testing.T) *TestFramework { } t.testAPI = iotago.V3API( - iotago.NewV3ProtocolParameters( - iotago.WithNetworkOptions("TestJungle", "tgl"), - iotago.WithSupplyOptions(10000, 0, 0, 0, 0, 0, 0), - iotago.WithLivenessOptions(10, 10, 1, 2, 8), + iotago.NewV3SnapshotProtocolParameters( + iotago.WithLivenessOptions(5, 5, 1, 2, 8), ), ) diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/drrbuffer.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/drrbuffer.go index 40207e998..9bdafe155 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/drrbuffer.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/drrbuffer.go @@ -5,6 +5,8 @@ import ( "math" "time" + "go.uber.org/atomic" + "github.com/iotaledger/hive.go/ds/shrinkingmap" "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/iota-core/pkg/protocol/engine/blocks" @@ -19,7 +21,7 @@ type BufferQueue struct { activeIssuers *shrinkingmap.ShrinkingMap[iotago.AccountID, *ring.Ring] ring *ring.Ring // size is the number of blocks in the buffer. - size int + size atomic.Int64 tokenBucket float64 lastScheduleTime time.Time @@ -57,7 +59,7 @@ func (b *BufferQueue) Clear() { // Size returns the total number of blocks in BufferQueue. func (b *BufferQueue) Size() int { - return b.size + return int(b.size.Load()) } // IssuerQueue returns the queue for the corresponding issuer. @@ -125,7 +127,7 @@ func (b *BufferQueue) RemoveIssuerQueue(issuerID iotago.AccountID) { if !isIQ { panic("buffer contains elements that are not issuer queues") } - b.size -= issuerQueue.Size() + b.size.Sub(int64(issuerQueue.Size())) b.ringRemove(element) b.activeIssuers.Delete(issuerID) @@ -156,7 +158,7 @@ func (b *BufferQueue) Submit(blk *blocks.Block, issuerQueue *IssuerQueue, quantu return nil, false } - b.size++ + b.size.Inc() // if max buffer size exceeded, drop from tail of the longest mana-scaled queue if b.Size() > maxBuffer { @@ -180,7 +182,7 @@ func (b *BufferQueue) Unsubmit(block *blocks.Block) bool { return false } - b.size-- + b.size.Dec() return true } @@ -268,7 +270,7 @@ func (b *BufferQueue) PopFront() *blocks.Block { } - b.size-- + b.size.Dec() return block } @@ -298,7 +300,7 @@ func (b *BufferQueue) dropTail(quantumFunc func(iotago.AccountID) Deficit, maxBu maxIssuerID := b.longestQueueIssuerID(quantumFunc) if longestQueue := b.IssuerQueue(maxIssuerID); longestQueue != nil { if tail := longestQueue.RemoveTail(); tail != nil { - b.size-- + b.size.Dec() droppedBlocks = append(droppedBlocks, tail) } } diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go index 3bc5ac351..cb9a1da1c 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go @@ -171,25 +171,16 @@ func (s *Scheduler) Start() { // IssuerQueueBlockCount returns the number of blocks in the queue of the given issuer. func (s *Scheduler) IssuerQueueBlockCount(issuerID iotago.AccountID) int { - s.bufferMutex.RLock() - defer s.bufferMutex.RUnlock() - return s.basicBuffer.IssuerQueueBlockCount(issuerID) } // IssuerQueueWork returns the queue size of the given issuer in work units. func (s *Scheduler) IssuerQueueWork(issuerID iotago.AccountID) iotago.WorkScore { - s.bufferMutex.RLock() - defer s.bufferMutex.RUnlock() - return s.basicBuffer.IssuerQueueWork(issuerID) } // ValidatorQueueBlockCount returns the number of validation blocks in the validator queue of the given issuer. func (s *Scheduler) ValidatorQueueBlockCount(issuerID iotago.AccountID) int { - s.bufferMutex.RLock() - defer s.bufferMutex.RUnlock() - validatorQueue, exists := s.validatorBuffer.Get(issuerID) if !exists { return 0 @@ -198,18 +189,12 @@ func (s *Scheduler) ValidatorQueueBlockCount(issuerID iotago.AccountID) int { return validatorQueue.Size() } -// BufferSize returns the current buffer size of the Scheduler as block count. +// BasicBufferSize returns the current buffer size of the Scheduler as block count. func (s *Scheduler) BasicBufferSize() int { - s.bufferMutex.RLock() - defer s.bufferMutex.RUnlock() - return s.basicBuffer.Size() } func (s *Scheduler) ValidatorBufferSize() int { - s.bufferMutex.RLock() - defer s.bufferMutex.RUnlock() - return s.validatorBuffer.Size() } @@ -418,7 +403,7 @@ func (s *Scheduler) selectBlockToScheduleWithLocking() { s.validatorBuffer.buffer.ForEach(func(accountID iotago.AccountID, validatorQueue *ValidatorQueue) bool { if s.selectValidationBlockWithoutLocking(validatorQueue) { - s.validatorBuffer.size-- + s.validatorBuffer.size.Dec() } return true diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go index 56542a0c8..f327ae556 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go @@ -176,7 +176,7 @@ func (q *ValidatorQueue) deductTokens(tokens float64) { type ValidatorBuffer struct { buffer *shrinkingmap.ShrinkingMap[iotago.AccountID, *ValidatorQueue] - size int + size atomic.Int64 } func NewValidatorBuffer() *ValidatorBuffer { @@ -190,7 +190,7 @@ func (b *ValidatorBuffer) Size() int { return 0 } - return b.size + return int(b.size.Load()) } func (b *ValidatorBuffer) Get(accountID iotago.AccountID) (*ValidatorQueue, bool) { @@ -208,10 +208,10 @@ func (b *ValidatorBuffer) Submit(block *blocks.Block, maxBuffer int) (*blocks.Bl } droppedBlock, submitted := validatorQueue.Submit(block, maxBuffer) if submitted { - b.size++ + b.size.Inc() } if droppedBlock != nil { - b.size-- + b.size.Dec() } return droppedBlock, submitted @@ -222,7 +222,7 @@ func (b *ValidatorBuffer) Delete(accountID iotago.AccountID) { if !exists { return } - b.size -= validatorQueue.Size() + b.size.Sub(int64(validatorQueue.Size())) b.buffer.Delete(accountID) } diff --git a/pkg/protocol/engine/consensus/blockgadget/testframework_test.go b/pkg/protocol/engine/consensus/blockgadget/testframework_test.go index aaea4179f..486b4a8c9 100644 --- a/pkg/protocol/engine/consensus/blockgadget/testframework_test.go +++ b/pkg/protocol/engine/consensus/blockgadget/testframework_test.go @@ -42,7 +42,7 @@ func NewTestFramework(test *testing.T) *TestFramework { T: test, blocks: shrinkingmap.New[string, *blocks.Block](), - SeatManager: mock.NewManualPOA(iotago.SingleVersionProvider(tpkg.TestAPI), epochstore.NewStore(kvstore.Realm{}, mapdb.NewMapDB(), 0, (*account.Accounts).Bytes, account.AccountsFromBytes)), + SeatManager: mock.NewManualPOA(iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), epochstore.NewStore(kvstore.Realm{}, mapdb.NewMapDB(), 0, (*account.Accounts).Bytes, account.AccountsFromBytes)), } evictionState := eviction.NewState(mapdb.NewMapDB(), func(slot iotago.SlotIndex) (*slotstore.Store[iotago.BlockID, iotago.CommitmentID], error) { @@ -53,10 +53,10 @@ func NewTestFramework(test *testing.T) *TestFramework { iotago.CommitmentIDFromBytes, ), nil }, func() iotago.BlockID { - return tpkg.TestAPI.ProtocolParameters().GenesisBlockID() + return tpkg.ZeroCostTestAPI.ProtocolParameters().GenesisBlockID() }) - t.blockCache = blocks.New(evictionState, iotago.SingleVersionProvider(tpkg.TestAPI)) + t.blockCache = blocks.New(evictionState, iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI)) instance := thresholdblockgadget.New(t.blockCache, t.SeatManager, func(err error) { fmt.Printf(">> Gadget.Error: %s\n", err) }) @@ -64,7 +64,7 @@ func NewTestFramework(test *testing.T) *TestFramework { t.Events = instance.Events() t.Instance = instance - genesisBlock := blocks.NewRootBlock(tpkg.TestAPI.ProtocolParameters().GenesisBlockID(), iotago.NewEmptyCommitment(tpkg.TestAPI).MustID(), time.Unix(tpkg.TestAPI.TimeProvider().GenesisUnixTime(), 0)) + genesisBlock := blocks.NewRootBlock(tpkg.ZeroCostTestAPI.ProtocolParameters().GenesisBlockID(), iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID(), time.Unix(tpkg.ZeroCostTestAPI.TimeProvider().GenesisUnixTime(), 0)) t.blocks.Set("Genesis", genesisBlock) genesisBlock.ID().RegisterAlias("Genesis") evictionState.AddRootBlock(genesisBlock.ID(), genesisBlock.SlotCommitmentID()) @@ -106,7 +106,7 @@ func (t *TestFramework) CreateBlock(alias string, issuerAlias string, parents .. _, priv, err := ed25519.GenerateKey(nil) require.NoError(t, err) - block, err := builder.NewValidationBlockBuilder(tpkg.TestAPI). + block, err := builder.NewValidationBlockBuilder(tpkg.ZeroCostTestAPI). StrongParents(t.BlockIDs(parents...)). Sign(t.SeatManager.AccountID(issuerAlias), priv). IssuingTime(time.Now()). diff --git a/pkg/protocol/engine/eviction/state_test.go b/pkg/protocol/engine/eviction/state_test.go index 5d77aa992..515dae6da 100644 --- a/pkg/protocol/engine/eviction/state_test.go +++ b/pkg/protocol/engine/eviction/state_test.go @@ -19,24 +19,24 @@ func TestState_RootBlocks(t *testing.T) { prunableStorage := prunable.New(database.Config{ Engine: hivedb.EngineMapDB, Directory: t.TempDir(), - }, iotago.SingleVersionProvider(tpkg.TestAPI), errorHandler) + }, iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), errorHandler) ts := NewTestFramework(t, prunableStorage, eviction.NewState(mapdb.NewMapDB(), prunableStorage.RootBlocks, func() iotago.BlockID { - return tpkg.TestAPI.ProtocolParameters().GenesisBlockID() + return tpkg.ZeroCostTestAPI.ProtocolParameters().GenesisBlockID() }, eviction.WithRootBlocksEvictionDelay(3))) - ts.CreateAndAddRootBlock("Genesis", 0, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) + ts.CreateAndAddRootBlock("Genesis", 0, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) ts.RequireActiveRootBlocks("Genesis") ts.RequireLastEvictedSlot(0) ts.Instance.Initialize(0) - ts.CreateAndAddRootBlock("Root1.0", 1, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) - ts.CreateAndAddRootBlock("Root1.1", 1, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) - ts.CreateAndAddRootBlock("Root2.0", 2, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) - ts.CreateAndAddRootBlock("Root3.0", 3, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) - ts.CreateAndAddRootBlock("Root4.0", 4, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) - ts.CreateAndAddRootBlock("Root4.1", 4, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) - ts.CreateAndAddRootBlock("Root5.0", 5, iotago.NewEmptyCommitment(tpkg.TestAPI).MustID()) + ts.CreateAndAddRootBlock("Root1.0", 1, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) + ts.CreateAndAddRootBlock("Root1.1", 1, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) + ts.CreateAndAddRootBlock("Root2.0", 2, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) + ts.CreateAndAddRootBlock("Root3.0", 3, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) + ts.CreateAndAddRootBlock("Root4.0", 4, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) + ts.CreateAndAddRootBlock("Root4.1", 4, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) + ts.CreateAndAddRootBlock("Root5.0", 5, iotago.NewEmptyCommitment(tpkg.ZeroCostTestAPI).MustID()) ts.RequireActiveRootBlocks("Genesis") ts.RequireLastEvictedSlot(0) diff --git a/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter_test.go b/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter_test.go index e996b2990..10fff4fc3 100644 --- a/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter_test.go +++ b/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter_test.go @@ -117,7 +117,7 @@ func (t *TestFramework) IssueSignedBlockAtSlotWithBurnedMana(alias string, slot } func TestPostSolidFilter_NoAccount(t *testing.T) { - testAPI := tpkg.TestAPI + testAPI := tpkg.ZeroCostTestAPI tf := NewTestFramework(t, iotago.SingleVersionProvider(testAPI), @@ -179,7 +179,7 @@ func TestPostSolidFilter_NoAccount(t *testing.T) { } func TestPostSolidFilter_BurnedMana(t *testing.T) { - testAPI := tpkg.TestAPI + testAPI := tpkg.ZeroCostTestAPI tf := NewTestFramework(t, iotago.SingleVersionProvider(testAPI), @@ -227,7 +227,7 @@ func TestPostSolidFilter_BurnedMana(t *testing.T) { } func TestPostSolidFilter_Expiry(t *testing.T) { - testAPI := tpkg.TestAPI + testAPI := tpkg.ZeroCostTestAPI tf := NewTestFramework(t, iotago.SingleVersionProvider(testAPI), diff --git a/pkg/protocol/engine/filter/presolidfilter/presolidblockfilter/pre_solid_block_filter_test.go b/pkg/protocol/engine/filter/presolidfilter/presolidblockfilter/pre_solid_block_filter_test.go index df0809625..b1e24307a 100644 --- a/pkg/protocol/engine/filter/presolidfilter/presolidblockfilter/pre_solid_block_filter_test.go +++ b/pkg/protocol/engine/filter/presolidfilter/presolidblockfilter/pre_solid_block_filter_test.go @@ -111,7 +111,7 @@ func mockedCommitteeFunc(validatorAccountID iotago.AccountID) func(iotago.SlotIn func TestFilter_WithMaxAllowedWallClockDrift(t *testing.T) { allowedDrift := 3 * time.Second - testAPI := tpkg.TestAPI + testAPI := tpkg.ZeroCostTestAPI tf := NewTestFramework(t, iotago.SingleVersionProvider(testAPI), @@ -137,12 +137,12 @@ func TestFilter_ProtocolVersion(t *testing.T) { apiProvider := iotago.NewEpochBasedProvider( iotago.WithAPIForMissingVersionCallback( func(params iotago.ProtocolParameters) (iotago.API, error) { - return iotago.V3API(iotago.NewV3ProtocolParameters(iotago.WithVersion(params.Version()))), nil + return iotago.V3API(iotago.NewV3SnapshotProtocolParameters(iotago.WithVersion(params.Version()))), nil }, ), ) - apiProvider.AddProtocolParametersAtEpoch(iotago.NewV3ProtocolParameters(iotago.WithVersion(3)), 0) - apiProvider.AddProtocolParametersAtEpoch(iotago.NewV3ProtocolParameters(iotago.WithVersion(4)), 3) + apiProvider.AddProtocolParametersAtEpoch(iotago.NewV3SnapshotProtocolParameters(iotago.WithVersion(3)), 0) + apiProvider.AddProtocolParametersAtEpoch(iotago.NewV3SnapshotProtocolParameters(iotago.WithVersion(4)), 3) timeProvider := apiProvider.CommittedAPI().TimeProvider() @@ -187,7 +187,7 @@ func TestFilter_ProtocolVersion(t *testing.T) { valid.Add("G") require.NoError(t, tf.IssueBlockAtSlotWithVersion("G", timeProvider.EpochStart(5)+5, 4, apiProvider)) - apiProvider.AddProtocolParametersAtEpoch(iotago.NewV3ProtocolParameters(iotago.WithVersion(5)), 10) + apiProvider.AddProtocolParametersAtEpoch(iotago.NewV3SnapshotProtocolParameters(iotago.WithVersion(5)), 10) valid.Add("H") require.NoError(t, tf.IssueBlockAtSlotWithVersion("H", timeProvider.EpochEnd(9), 4, apiProvider)) @@ -200,7 +200,7 @@ func TestFilter_ProtocolVersion(t *testing.T) { } func TestFilter_ValidationBlocks(t *testing.T) { - testAPI := tpkg.TestAPI + testAPI := tpkg.ZeroCostTestAPI tf := NewTestFramework(t, iotago.SingleVersionProvider(testAPI), diff --git a/pkg/protocol/engine/ledger/ledger/vm.go b/pkg/protocol/engine/ledger/ledger/vm.go index f86162e61..78fb952fd 100644 --- a/pkg/protocol/engine/ledger/ledger/vm.go +++ b/pkg/protocol/engine/ledger/ledger/vm.go @@ -97,9 +97,13 @@ func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, res accountID = iotago.AccountIDFromOutputID(outputID) } - reward, _, _, rewardErr := v.ledger.sybilProtection.ValidatorReward(accountID, stakingFeature.StakedAmount, stakingFeature.StartEpoch, stakingFeature.EndEpoch) + apiForSlot := v.ledger.apiProvider.APIForSlot(commitmentInput.Slot) + futureBoundedSlotIndex := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge() + claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) + + reward, _, _, rewardErr := v.ledger.sybilProtection.ValidatorReward(accountID, stakingFeature, claimingEpoch) if rewardErr != nil { - return nil, ierrors.Wrapf(iotago.ErrFailedToClaimStakingReward, "failed to get Validator reward for AccountOutput %s at index %d (StakedAmount: %d, StartEpoch: %d, EndEpoch: %d", outputID, inp.Index, stakingFeature.StakedAmount, stakingFeature.StartEpoch, stakingFeature.EndEpoch) + return nil, ierrors.Wrapf(iotago.ErrFailedToClaimStakingReward, "failed to get Validator reward for AccountOutput %s at index %d (StakedAmount: %d, StartEpoch: %d, EndEpoch: %d, claimingEpoch: %d", outputID, inp.Index, stakingFeature.StakedAmount, stakingFeature.StartEpoch, stakingFeature.EndEpoch, claimingEpoch) } rewardInputSet[accountID] = reward @@ -108,17 +112,19 @@ func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, res delegationID := castOutput.DelegationID delegationEnd := castOutput.EndEpoch + apiForSlot := v.ledger.apiProvider.APIForSlot(commitmentInput.Slot) + futureBoundedSlotIndex := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge() + claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) + if delegationID.Empty() { delegationID = iotago.DelegationIDFromOutputID(outputID) // If Delegation ID is zeroed, the output is in delegating state, which means its End Epoch is not set and we must use the // "last epoch", which is the epoch index corresponding to the future bounded slot index minus 1. - apiForSlot := v.ledger.apiProvider.APIForSlot(commitmentInput.Slot) - futureBoundedSlotIndex := commitmentInput.Slot + apiForSlot.ProtocolParameters().MinCommittableAge() - delegationEnd = apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) - iotago.EpochIndex(1) + delegationEnd = claimingEpoch - iotago.EpochIndex(1) } - reward, _, _, rewardErr := v.ledger.sybilProtection.DelegatorReward(castOutput.ValidatorAddress.AccountID(), castOutput.DelegatedAmount, castOutput.StartEpoch, delegationEnd) + reward, _, _, rewardErr := v.ledger.sybilProtection.DelegatorReward(castOutput.ValidatorAddress.AccountID(), castOutput.DelegatedAmount, castOutput.StartEpoch, delegationEnd, claimingEpoch) if rewardErr != nil { return nil, ierrors.Wrapf(iotago.ErrFailedToClaimDelegationReward, "failed to get Delegator reward for DelegationOutput %s at index %d (StakedAmount: %d, StartEpoch: %d, EndEpoch: %d", outputID, inp.Index, castOutput.DelegatedAmount, castOutput.StartEpoch, castOutput.EndEpoch) } diff --git a/pkg/protocol/engine/mempool/v1/mempool_test.go b/pkg/protocol/engine/mempool/v1/mempool_test.go index 13c786fee..606e02efd 100644 --- a/pkg/protocol/engine/mempool/v1/mempool_test.go +++ b/pkg/protocol/engine/mempool/v1/mempool_test.go @@ -39,7 +39,7 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { spendDAG := spenddagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](func() int { return 0 }) memPoolInstance := New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { return ledgerState.ResolveOutputState(reference) - }, mutationsFunc, workers, spendDAG, iotago.SingleVersionProvider(tpkg.TestAPI), func(error) {}) + }, mutationsFunc, workers, spendDAG, iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), func(error) {}) tf := mempooltests.NewTestFramework(t, memPoolInstance, spendDAG, ledgerState, workers) @@ -149,5 +149,5 @@ func newTestFramework(t *testing.T) *mempooltests.TestFramework { return mempooltests.NewTestFramework(t, New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { return ledgerState.ResolveOutputState(reference) - }, mutationsFunc, workers, spendDAG, iotago.SingleVersionProvider(tpkg.TestAPI), func(error) {}), spendDAG, ledgerState, workers) + }, mutationsFunc, workers, spendDAG, iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), func(error) {}), spendDAG, ledgerState, workers) } diff --git a/pkg/protocol/engine/tipmanager/tests/testframework.go b/pkg/protocol/engine/tipmanager/tests/testframework.go index 7b67a1524..781dc41b9 100644 --- a/pkg/protocol/engine/tipmanager/tests/testframework.go +++ b/pkg/protocol/engine/tipmanager/tests/testframework.go @@ -34,7 +34,7 @@ func NewTestFramework(test *testing.T) *TestFramework { tipMetadataByAlias: make(map[string]tipmanager.TipMetadata), blocksByID: make(map[iotago.BlockID]*blocks.Block), test: test, - API: tpkg.TestAPI, + API: tpkg.ZeroCostTestAPI, } t.blockIDsByAlias["Genesis"] = iotago.EmptyBlockID diff --git a/pkg/protocol/engine/utxoledger/iteration_test.go b/pkg/protocol/engine/utxoledger/iteration_test.go index 12a3ab370..b2243e2d6 100644 --- a/pkg/protocol/engine/utxoledger/iteration_test.go +++ b/pkg/protocol/engine/utxoledger/iteration_test.go @@ -14,7 +14,7 @@ import ( ) func TestUTXOComputeBalance(t *testing.T) { - manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) initialOutput := tpkg.RandLedgerStateOutputOnAddressWithAmount(iotago.OutputBasic, iotago_tpkg.RandAddress(iotago.AddressEd25519), 2_134_656_365) require.NoError(t, manager.AddGenesisUnspentOutput(initialOutput)) @@ -51,7 +51,7 @@ func TestUTXOComputeBalance(t *testing.T) { } func TestUTXOIteration(t *testing.T) { - manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) outputs := utxoledger.Outputs{ tpkg.RandLedgerStateOutputOnAddress(iotago.OutputBasic, iotago_tpkg.RandAddress(iotago.AddressEd25519)), diff --git a/pkg/protocol/engine/utxoledger/manager_test.go b/pkg/protocol/engine/utxoledger/manager_test.go index 1e046fc27..0f2f179d3 100644 --- a/pkg/protocol/engine/utxoledger/manager_test.go +++ b/pkg/protocol/engine/utxoledger/manager_test.go @@ -14,7 +14,7 @@ import ( ) func TestConfirmationApplyAndRollbackToEmptyLedger(t *testing.T) { - manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) outputs := utxoledger.Outputs{ tpkg.RandLedgerStateOutputWithType(iotago.OutputBasic), @@ -88,7 +88,7 @@ func TestConfirmationApplyAndRollbackToEmptyLedger(t *testing.T) { } func TestConfirmationApplyAndRollbackToPreviousLedger(t *testing.T) { - manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) previousOutputs := utxoledger.Outputs{ tpkg.RandLedgerStateOutputWithType(iotago.OutputBasic), diff --git a/pkg/protocol/engine/utxoledger/output_test.go b/pkg/protocol/engine/utxoledger/output_test.go index 65968b7b5..c9ce53097 100644 --- a/pkg/protocol/engine/utxoledger/output_test.go +++ b/pkg/protocol/engine/utxoledger/output_test.go @@ -21,7 +21,7 @@ import ( func AssertOutputUnspentAndSpentTransitions(t *testing.T, output *utxoledger.Output, spent *utxoledger.Spent) { outputID := output.OutputID() - manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, manager.AddGenesisUnspentOutput(output)) @@ -80,7 +80,7 @@ func CreateOutputAndAssertSerialization(t *testing.T, blockID iotago.BlockID, in outputID, err := outputProof.OutputID(iotaOutput) require.NoError(t, err) - iotagoAPI := iotago_tpkg.TestAPI + iotagoAPI := iotago_tpkg.ZeroCostTestAPI output := utxoledger.CreateOutput(iotago.SingleVersionProvider(iotagoAPI), outputID, blockID, indexBooked, iotaOutput, outputProof) outputBytes, err := iotagoAPI.Encode(output.Output()) require.NoError(t, err) @@ -152,7 +152,7 @@ func TestBasicOutputOnEd25519WithoutSpendConstraintsSerialization(t *testing.T) }, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) @@ -190,7 +190,7 @@ func TestBasicOutputOnEd25519WithSpendConstraintsSerialization(t *testing.T) { }, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) @@ -229,7 +229,7 @@ func TestNFTOutputSerialization(t *testing.T) { }, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) @@ -276,7 +276,7 @@ func TestNFTOutputWithSpendConstraintsSerialization(t *testing.T) { }, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) @@ -318,7 +318,7 @@ func TestAccountOutputSerialization(t *testing.T) { }, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) @@ -364,7 +364,7 @@ func TestAnchorOutputSerialization(t *testing.T) { }, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) @@ -401,7 +401,7 @@ func TestFoundryOutputSerialization(t *testing.T) { ImmutableFeatures: iotago.FoundryOutputImmFeatures{}, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) @@ -433,7 +433,7 @@ func TestDelegationOutputSerialization(t *testing.T) { }, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txCommitment, txCreationSlot, iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) output := CreateOutputAndAssertSerialization(t, blockID, index, iotaOutput, outputProof) diff --git a/pkg/protocol/engine/utxoledger/slot_diff_test.go b/pkg/protocol/engine/utxoledger/slot_diff_test.go index e39a3b510..ad8982831 100644 --- a/pkg/protocol/engine/utxoledger/slot_diff_test.go +++ b/pkg/protocol/engine/utxoledger/slot_diff_test.go @@ -35,10 +35,10 @@ func TestSimpleSlotDiffSerialization(t *testing.T) { Features: iotago.BasicOutputFeatures{}, } - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) - output := utxoledger.CreateOutput(iotago.SingleVersionProvider(iotago_tpkg.TestAPI), outputID, blockID, indexBooked, iotaOutput, outputProof) + output := utxoledger.CreateOutput(iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI), outputID, blockID, indexBooked, iotaOutput, outputProof) transactionIDSpent := iotago_tpkg.RandTransactionID() @@ -63,7 +63,7 @@ func TestSimpleSlotDiffSerialization(t *testing.T) { } func TestSlotDiffSerialization(t *testing.T) { - manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) outputs := utxoledger.Outputs{ tpkg.RandLedgerStateOutputWithType(iotago.OutputBasic), diff --git a/pkg/protocol/engine/utxoledger/snapshot_test.go b/pkg/protocol/engine/utxoledger/snapshot_test.go index ba1c5dd38..1e220077d 100644 --- a/pkg/protocol/engine/utxoledger/snapshot_test.go +++ b/pkg/protocol/engine/utxoledger/snapshot_test.go @@ -23,16 +23,16 @@ func TestOutput_SnapshotBytes(t *testing.T) { txID := iotago_tpkg.RandTransactionID() slotBooked := iotago_tpkg.RandSlot() iotaOutput := iotago_tpkg.RandOutput(iotago.OutputBasic) - iotaOutputBytes, err := iotago_tpkg.TestAPI.Encode(iotaOutput) + iotaOutputBytes, err := iotago_tpkg.ZeroCostTestAPI.Encode(iotaOutput) require.NoError(t, err) - proof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) + proof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) proofBytes, err := proof.Bytes() require.NoError(t, err) - output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.TestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, proof, proofBytes) + output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, proof, proofBytes) snapshotBytes := output.SnapshotBytes() @@ -58,19 +58,19 @@ func TestOutputFromSnapshotReader(t *testing.T) { blockID := iotago_tpkg.RandBlockID() slotBooked := iotago_tpkg.RandSlot() iotaOutput := iotago_tpkg.RandOutput(iotago.OutputBasic) - iotaOutputBytes, err := iotago_tpkg.TestAPI.Encode(iotaOutput) + iotaOutputBytes, err := iotago_tpkg.ZeroCostTestAPI.Encode(iotaOutput) require.NoError(t, err) - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) outputProofBytes, err := outputProof.Bytes() require.NoError(t, err) - output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.TestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, outputProof, outputProofBytes) + output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, outputProof, outputProofBytes) snapshotBytes := output.SnapshotBytes() buf := bytes.NewReader(snapshotBytes) - readOutput, err := utxoledger.OutputFromSnapshotReader(buf, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + readOutput, err := utxoledger.OutputFromSnapshotReader(buf, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) require.Equal(t, output, readOutput) @@ -82,15 +82,15 @@ func TestSpent_SnapshotBytes(t *testing.T) { blockID := iotago_tpkg.RandBlockID() slotBooked := iotago_tpkg.RandSlot() iotaOutput := iotago_tpkg.RandOutput(iotago.OutputBasic) - iotaOutputBytes, err := iotago_tpkg.TestAPI.Encode(iotaOutput) + iotaOutputBytes, err := iotago_tpkg.ZeroCostTestAPI.Encode(iotaOutput) require.NoError(t, err) - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) outputProofBytes, err := outputProof.Bytes() require.NoError(t, err) - output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.TestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, outputProof, outputProofBytes) + output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, outputProof, outputProofBytes) outputSnapshotBytes := output.SnapshotBytes() transactionID := iotago_tpkg.RandTransactionID() @@ -111,15 +111,15 @@ func TestSpentFromSnapshotReader(t *testing.T) { blockID := iotago_tpkg.RandBlockID() slotBooked := iotago_tpkg.RandSlot() iotaOutput := iotago_tpkg.RandOutput(iotago.OutputBasic) - iotaOutputBytes, err := iotago_tpkg.TestAPI.Encode(iotaOutput) + iotaOutputBytes, err := iotago_tpkg.ZeroCostTestAPI.Encode(iotaOutput) require.NoError(t, err) - outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.TestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) + outputProof, err := iotago.NewOutputIDProof(iotago_tpkg.ZeroCostTestAPI, txID.Identifier(), txID.Slot(), iotago.TxEssenceOutputs{iotaOutput}, 0) require.NoError(t, err) outputProofBytes, err := outputProof.Bytes() require.NoError(t, err) - output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.TestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, outputProof, outputProofBytes) + output := utxoledger.NewOutput(iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI), outputID, blockID, slotBooked, iotaOutput, iotaOutputBytes, outputProof, outputProofBytes) transactionID := iotago_tpkg.RandTransactionID() slotSpent := iotago_tpkg.RandSlot() @@ -128,7 +128,7 @@ func TestSpentFromSnapshotReader(t *testing.T) { snapshotBytes := spent.SnapshotBytes() buf := bytes.NewReader(snapshotBytes) - readSpent, err := utxoledger.SpentFromSnapshotReader(buf, iotago.SingleVersionProvider(iotago_tpkg.TestAPI), slotSpent) + readSpent, err := utxoledger.SpentFromSnapshotReader(buf, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI), slotSpent) require.NoError(t, err) require.Equal(t, spent, readSpent) @@ -154,7 +154,7 @@ func TestReadSlotDiffToSnapshotReader(t *testing.T) { require.NoError(t, err) reader := writer.Reader() - readSlotDiff, err := utxoledger.ReadSlotDiffToSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + readSlotDiff, err := utxoledger.ReadSlotDiffToSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) require.Equal(t, slotDiff.Slot, readSlotDiff.Slot) @@ -193,7 +193,7 @@ func TestWriteSlotDiffToSnapshotWriter(t *testing.T) { var snapshotOutputs utxoledger.Outputs for i := 0; i < len(slotDiff.Outputs); i++ { - readOutput, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + readOutput, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) snapshotOutputs = append(snapshotOutputs, readOutput) } @@ -206,7 +206,7 @@ func TestWriteSlotDiffToSnapshotWriter(t *testing.T) { var snapshotSpents utxoledger.Spents for i := 0; i < len(slotDiff.Spents); i++ { - readSpent, err := utxoledger.SpentFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI), readSlot) + readSpent, err := utxoledger.SpentFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI), readSlot) require.NoError(t, err) snapshotSpents = append(snapshotSpents, readSpent) } @@ -216,7 +216,7 @@ func TestWriteSlotDiffToSnapshotWriter(t *testing.T) { func TestManager_Import(t *testing.T) { mapDB := mapdb.NewMapDB() - manager := utxoledger.New(mapDB, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapDB, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) output1 := tpkg.RandLedgerStateOutput() @@ -270,7 +270,7 @@ func TestManager_Import(t *testing.T) { reader := writer.Reader() - importedSlot2 := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + importedSlot2 := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, importedSlot2.Import(reader)) require.Equal(t, iotago.SlotIndex(2), lo.PanicOnErr(importedSlot2.ReadLedgerSlot())) @@ -284,10 +284,10 @@ func TestManager_Import(t *testing.T) { reader := writer.Reader() - importedSlot1 := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + importedSlot1 := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, importedSlot1.Import(reader)) - managerAtSlot1 := utxoledger.New(mapDBAtSlot1, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + managerAtSlot1 := utxoledger.New(mapDBAtSlot1, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.Equal(t, iotago.SlotIndex(1), lo.PanicOnErr(importedSlot1.ReadLedgerSlot())) require.Equal(t, iotago.SlotIndex(1), lo.PanicOnErr(managerAtSlot1.ReadLedgerSlot())) @@ -301,10 +301,10 @@ func TestManager_Import(t *testing.T) { reader := writer.Reader() - importedSlot0 := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + importedSlot0 := utxoledger.New(mapdb.NewMapDB(), iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, importedSlot0.Import(reader)) - managerAtSlot0 := utxoledger.New(mapDBAtSlot0, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + managerAtSlot0 := utxoledger.New(mapDBAtSlot0, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.Equal(t, iotago.SlotIndex(0), lo.PanicOnErr(importedSlot0.ReadLedgerSlot())) require.Equal(t, iotago.SlotIndex(0), lo.PanicOnErr(managerAtSlot0.ReadLedgerSlot())) @@ -314,7 +314,7 @@ func TestManager_Import(t *testing.T) { func TestManager_Export(t *testing.T) { mapDB := mapdb.NewMapDB() - manager := utxoledger.New(mapDB, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + manager := utxoledger.New(mapDB, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) output1 := tpkg.RandLedgerStateOutput() @@ -367,7 +367,7 @@ func TestManager_Export(t *testing.T) { var snapshotOutputs utxoledger.Outputs for i := uint64(0); i < outputCount; i++ { - output, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + output, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) snapshotOutputs = append(snapshotOutputs, output) } @@ -400,7 +400,7 @@ func TestManager_Export(t *testing.T) { var snapshotOutputs utxoledger.Outputs for i := uint64(0); i < outputCount; i++ { - output, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + output, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) snapshotOutputs = append(snapshotOutputs, output) } @@ -415,7 +415,7 @@ func TestManager_Export(t *testing.T) { require.Equal(t, uint32(1), slotDiffCount) for i := uint32(0); i < slotDiffCount; i++ { - diff, err := utxoledger.ReadSlotDiffToSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + diff, err := utxoledger.ReadSlotDiffToSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) require.Equal(t, snapshotLedgerSlot-iotago.SlotIndex(i), diff.Slot) } @@ -438,7 +438,7 @@ func TestManager_Export(t *testing.T) { var snapshotOutputs utxoledger.Outputs for i := uint64(0); i < outputCount; i++ { - output, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + output, err := utxoledger.OutputFromSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) snapshotOutputs = append(snapshotOutputs, output) } @@ -453,7 +453,7 @@ func TestManager_Export(t *testing.T) { require.Equal(t, uint32(2), slotDiffCount) for i := uint32(0); i < slotDiffCount; i++ { - diff, err := utxoledger.ReadSlotDiffToSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.TestAPI)) + diff, err := utxoledger.ReadSlotDiffToSnapshotReader(reader, iotago.SingleVersionProvider(iotago_tpkg.ZeroCostTestAPI)) require.NoError(t, err) require.Equal(t, snapshotLedgerSlot-iotago.SlotIndex(i), diff.Slot) } diff --git a/pkg/protocol/engine/utxoledger/tpkg/random.go b/pkg/protocol/engine/utxoledger/tpkg/random.go index 627516475..20804f477 100644 --- a/pkg/protocol/engine/utxoledger/tpkg/random.go +++ b/pkg/protocol/engine/utxoledger/tpkg/random.go @@ -14,9 +14,9 @@ func RandLedgerStateOutput() *utxoledger.Output { func RandLedgerStateOutputWithOutput(output iotago.Output) *utxoledger.Output { outputs := iotago.TxEssenceOutputs{output} txID := tpkg.RandTransactionID() - proof := lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.TestAPI, txID.Identifier(), txID.Slot(), outputs, 0)) + proof := lo.PanicOnErr(iotago.NewOutputIDProof(tpkg.ZeroCostTestAPI, txID.Identifier(), txID.Slot(), outputs, 0)) - return utxoledger.CreateOutput(iotago.SingleVersionProvider(tpkg.TestAPI), tpkg.RandOutputID(), tpkg.RandBlockID(), tpkg.RandSlot(), outputs[0], proof) + return utxoledger.CreateOutput(iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), tpkg.RandOutputID(), tpkg.RandBlockID(), tpkg.RandSlot(), outputs[0], proof) } func RandLedgerStateOutputWithType(outputType iotago.OutputType) *utxoledger.Output { diff --git a/pkg/protocol/options.go b/pkg/protocol/options.go index ac9605bf8..c3b260923 100644 --- a/pkg/protocol/options.go +++ b/pkg/protocol/options.go @@ -51,10 +51,6 @@ type Options struct { // SnapshotPath is the path to the snapshot file that should be used to initialize the protocol. SnapshotPath string - // ChainSwitchingThreshold is the threshold that defines how far away a heavier chain needs to be from its forking - // point to be considered for switching. - ChainSwitchingThreshold iotago.SlotIndex - // EngineOptions contains the options for the Engines. EngineOptions []options.Option[engine.Engine] @@ -120,8 +116,7 @@ type Options struct { // NewDefaultOptions creates new default options instance for the Protocol. func NewDefaultOptions() *Options { return &Options{ - BaseDirectory: "", - ChainSwitchingThreshold: 3, + BaseDirectory: "", PreSolidFilterProvider: presolidblockfilter.NewProvider(), PostSolidFilterProvider: postsolidblockfilter.NewProvider(), @@ -157,13 +152,6 @@ func WithSnapshotPath(snapshot string) options.Option[Protocol] { } } -// WithChainSwitchingThreshold is an option for the Protocol that allows to set the chain switching threshold. -func WithChainSwitchingThreshold(threshold iotago.SlotIndex) options.Option[Protocol] { - return func(p *Protocol) { - p.Options.ChainSwitchingThreshold = threshold - } -} - // WithPreSolidFilterProvider is an option for the Protocol that allows to set the PreSolidFilterProvider. func WithPreSolidFilterProvider(optsFilterProvider module.Provider[*engine.Engine, presolidfilter.PreSolidFilter]) options.Option[Protocol] { return func(p *Protocol) { diff --git a/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers_test.go b/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers_test.go index 53a49290a..a45851b45 100644 --- a/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers_test.go +++ b/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers_test.go @@ -22,9 +22,7 @@ import ( func TestTopStakers_InitializeCommittee(t *testing.T) { var testAPI = iotago.V3API( - iotago.NewV3ProtocolParameters( - iotago.WithNetworkOptions("TestJungle", "tgl"), - iotago.WithSupplyOptions(2_779_530_283_277_761, 0, 0, 0, 0, 0, 0), + iotago.NewV3SnapshotProtocolParameters( iotago.WithWorkScoreOptions(0, 1, 0, 0, 0, 0, 0, 0, 0, 0), // all zero except block offset gives all blocks workscore = 1 iotago.WithTargetCommitteeSize(3), ), @@ -76,9 +74,7 @@ func TestTopStakers_InitializeCommittee(t *testing.T) { func TestTopStakers_RotateCommittee(t *testing.T) { var testAPI = iotago.V3API( - iotago.NewV3ProtocolParameters( - iotago.WithNetworkOptions("TestJungle", "tgl"), - iotago.WithSupplyOptions(2_779_530_283_277_761, 0, 0, 0, 0, 0, 0), + iotago.NewV3SnapshotProtocolParameters( iotago.WithWorkScoreOptions(0, 1, 0, 0, 0, 0, 0, 0, 0, 0), // all zero except block offset gives all blocks workscore = 1 iotago.WithTargetCommitteeSize(10), ), diff --git a/pkg/protocol/sybilprotection/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotection.go index 147e8580c..675ee1f4a 100644 --- a/pkg/protocol/sybilprotection/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotection.go @@ -16,12 +16,18 @@ type SybilProtection interface { EligibleValidators(epoch iotago.EpochIndex) (accounts.AccountsData, error) OrderedRegisteredCandidateValidatorsList(epoch iotago.EpochIndex) ([]*api.ValidatorResponse, error) IsCandidateActive(validatorID iotago.AccountID, epoch iotago.EpochIndex) (bool, error) - // ValidatorReward returns the amount of mana that a validator has earned in a given epoch range. - // The actual used epoch range is returned, only until usedEnd the decay was applied. - ValidatorReward(validatorID iotago.AccountID, stakeAmount iotago.BaseToken, epochStart, epochEnd iotago.EpochIndex) (validatorReward iotago.Mana, decayedStart, decayedEnd iotago.EpochIndex, err error) + // ValidatorReward returns the amount of mana that a validator with the given staking feature has earned in the feature's epoch range. + // + // The first epoch in which rewards existed is returned (firstRewardEpoch). + // Since the validator may still be active and the EndEpoch might be in the future, the epoch until which rewards were calculated is returned in addition to the first epoch in which rewards existed (lastRewardEpoch). + // The rewards are decayed until claimingEpoch, which should be set to the epoch in which the rewards would be claimed. + ValidatorReward(validatorID iotago.AccountID, stakingFeature *iotago.StakingFeature, claimingEpoch iotago.EpochIndex) (validatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) // DelegatorReward returns the amount of mana that a delegator has earned in a given epoch range. - // The actual used epoch range is returned, only until usedEnd the decay was applied. - DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart, epochEnd iotago.EpochIndex) (delegatorsReward iotago.Mana, decayedStart, decayedEnd iotago.EpochIndex, err error) + // + // The first epoch in which rewards existed is returned (firstRewardEpoch). + // Since the Delegation Output's EndEpoch might be unset due to an ongoing delegation, the epoch until which rewards were calculated is also returned (lastRewardEpoch). + // The rewards are decayed until claimingEpoch, which should be set to the epoch in which the rewards would be claimed. + DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex, claimingEpoch iotago.EpochIndex) (delegatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) SeatManager() seatmanager.SeatManager CommitSlot(iotago.SlotIndex) (iotago.Identifier, iotago.Identifier, error) Import(io.ReadSeeker) error diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go index 965c57562..56c7249f0 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go @@ -8,6 +8,7 @@ import ( "github.com/iotaledger/hive.go/ds/shrinkingmap" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/kvstore" + "github.com/iotaledger/hive.go/log" "github.com/iotaledger/hive.go/runtime/syncutils" "github.com/iotaledger/iota-core/pkg/core/account" "github.com/iotaledger/iota-core/pkg/model" @@ -32,6 +33,8 @@ type Tracker struct { performanceFactorsMutex syncutils.RWMutex mutex syncutils.RWMutex + + log.Logger } func NewTracker( @@ -43,6 +46,7 @@ func NewTracker( latestAppliedEpoch iotago.EpochIndex, apiProvider iotago.APIProvider, errHandler func(error), + logger log.Logger, ) *Tracker { return &Tracker{ nextEpochCommitteeCandidates: shrinkingmap.New[iotago.AccountID, iotago.SlotIndex](), @@ -54,6 +58,7 @@ func NewTracker( latestAppliedEpoch: latestAppliedEpoch, apiProvider: apiProvider, errHandler: errHandler, + Logger: logger, } } @@ -212,12 +217,12 @@ func (t *Tracker) ApplyEpoch(epoch iotago.EpochIndex, committee *account.Account } committee.ForEach(func(accountID iotago.AccountID, pool *account.Pool) bool { - validatorPerformances := make([]*model.ValidatorPerformance, timeProvider.EpochDurationSlots()) + validatorPerformances := make([]*model.ValidatorPerformance, 0, timeProvider.EpochDurationSlots()) + for slot := epochStartSlot; slot <= epochEndSlot; slot++ { validatorSlotPerformances, err := t.validatorPerformancesFunc(slot) if err != nil { validatorPerformances = append(validatorPerformances, nil) - continue } @@ -233,8 +238,11 @@ func (t *Tracker) ApplyEpoch(epoch iotago.EpochIndex, committee *account.Account validatorPerformances = append(validatorPerformances, validatorPerformance) } - pf := t.aggregatePerformanceFactors(validatorPerformances, epoch) - if pf == 0 { + + // Aggregate the performance factor of the epoch which approximates the average of the slot's performance factor. + epochPerformanceFactor := t.aggregatePerformanceFactors(validatorPerformances, epoch) + + if epochPerformanceFactor == 0 { // no rewards for this pool, we do not set pool rewards at all, // to differientiate between situation when poolReward == fixedCost (no reward for delegators) @@ -247,11 +255,14 @@ func (t *Tracker) ApplyEpoch(epoch iotago.EpochIndex, committee *account.Account committee.TotalStake(), pool.PoolStake, pool.ValidatorStake, - pf, + epochPerformanceFactor, ) if err != nil { panic(ierrors.Wrapf(err, "failed to calculate pool rewards for account %s", accountID)) } + + t.LogDebug("PerformanceFactor", "accountID", accountID, "epochPerformanceFactor", epochPerformanceFactor, "poolReward", poolReward) + if err = rewardsMap.Set(accountID, &model.PoolRewards{ PoolStake: pool.PoolStake, PoolRewards: poolReward, @@ -286,6 +297,7 @@ func (t *Tracker) aggregatePerformanceFactors(slotActivityVector []*model.Valida if pf == nil { continue } + // each one bit represents at least one block issued in that subslot, // we reward not only total number of blocks issued, but also regularity based on block timestamp slotPerformanceFactor := bits.OnesCount32(pf.SlotActivityVector) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go index 31d13e58d..61b344e69 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go @@ -4,6 +4,7 @@ import ( "github.com/iotaledger/hive.go/ads" "github.com/iotaledger/hive.go/core/safemath" "github.com/iotaledger/hive.go/ierrors" + "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/iota-core/pkg/model" iotago "github.com/iotaledger/iota.go/v4" ) @@ -20,18 +21,23 @@ func (t *Tracker) RewardsRoot(epoch iotago.EpochIndex) (iotago.Identifier, error return m.Root(), nil } -func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (iotago.Mana, iotago.EpochIndex, iotago.EpochIndex, error) { +func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakingFeature *iotago.StakingFeature, claimingEpoch iotago.EpochIndex) (validatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) { t.mutex.RLock() defer t.mutex.RUnlock() - var validatorReward iotago.Mana + validatorReward = 0 + stakedAmount := stakingFeature.StakedAmount + firstRewardEpoch = stakingFeature.StartEpoch + lastRewardEpoch = stakingFeature.EndEpoch - // limit looping to committed epochs - if epochEnd > t.latestAppliedEpoch { - epochEnd = t.latestAppliedEpoch + // Limit reward fetching only to committed epochs. + if lastRewardEpoch > t.latestAppliedEpoch { + lastRewardEpoch = t.latestAppliedEpoch } - for epoch := epochStart; epoch <= epochEnd; epoch++ { + decayEndEpoch := t.decayEndEpoch(claimingEpoch, lastRewardEpoch) + + for epoch := firstRewardEpoch; epoch <= lastRewardEpoch; epoch++ { rewardsForAccountInEpoch, exists, err := t.rewardsForAccount(validatorID, epoch) if err != nil { return 0, 0, 0, ierrors.Wrapf(err, "failed to get rewards for account %s in epoch %d", validatorID, epoch) @@ -39,8 +45,8 @@ func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iota if !exists || rewardsForAccountInEpoch.PoolStake == 0 { // updating epoch start for beginning epochs without the reward - if epoch < epochEnd && epochStart == epoch { - epochStart = epoch + 1 + if epoch < lastRewardEpoch && firstRewardEpoch == epoch { + firstRewardEpoch = epoch + 1 } continue @@ -55,7 +61,7 @@ func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iota return 0, 0, 0, ierrors.Errorf("pool stats for epoch %d and validator accountID %s are nil", epoch, validatorID) } - // if validator's fixed cost is greater than earned reward, all reward goes for delegators + // If a validator's fixed cost is greater than the earned reward, all rewards go to the delegators. if rewardsForAccountInEpoch.PoolRewards < rewardsForAccountInEpoch.FixedCost { continue } @@ -79,7 +85,7 @@ func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iota return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate profit margin factor due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } - residualValidatorFactor, err := safemath.Safe64MulDiv(result>>profitMarginExponent, uint64(stakeAmount), uint64(rewardsForAccountInEpoch.PoolStake)) + residualValidatorFactor, err := safemath.Safe64MulDiv(result>>profitMarginExponent, uint64(stakedAmount), uint64(rewardsForAccountInEpoch.PoolStake)) if err != nil { return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate residual validator factor due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } @@ -89,13 +95,13 @@ func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iota return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate un-decayed epoch reward due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } - unDecayedEpochRewards, err := safemath.SafeAdd(result, residualValidatorFactor) + undecayedEpochRewards, err := safemath.SafeAdd(result, residualValidatorFactor) if err != nil { return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate un-decayed epoch rewards due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } decayProvider := t.apiProvider.APIForEpoch(epoch).ManaDecayProvider() - decayedEpochRewards, err := decayProvider.DecayManaByEpochs(iotago.Mana(unDecayedEpochRewards), epoch, epochEnd) + decayedEpochRewards, err := decayProvider.DecayManaByEpochs(iotago.Mana(undecayedEpochRewards), epoch, decayEndEpoch) if err != nil { return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate rewards with decay for epoch %d and validator accountID %s", epoch, validatorID) } @@ -106,21 +112,26 @@ func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iota } } - return validatorReward, epochStart, epochEnd, nil + return validatorReward, firstRewardEpoch, lastRewardEpoch, nil } -func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (iotago.Mana, iotago.EpochIndex, iotago.EpochIndex, error) { +func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex, claimingEpoch iotago.EpochIndex) (delegatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) { t.mutex.RLock() defer t.mutex.RUnlock() var delegatorsReward iotago.Mana + firstRewardEpoch = epochStart + lastRewardEpoch = epochEnd + // limit looping to committed epochs - if epochEnd > t.latestAppliedEpoch { - epochEnd = t.latestAppliedEpoch + if lastRewardEpoch > t.latestAppliedEpoch { + lastRewardEpoch = t.latestAppliedEpoch } - for epoch := epochStart; epoch <= epochEnd; epoch++ { + decayEndEpoch := t.decayEndEpoch(claimingEpoch, lastRewardEpoch) + + for epoch := firstRewardEpoch; epoch <= lastRewardEpoch; epoch++ { rewardsForAccountInEpoch, exists, err := t.rewardsForAccount(validatorID, epoch) if err != nil { return 0, 0, 0, ierrors.Wrapf(err, "failed to get rewards for account %s in epoch %d", validatorID, epoch) @@ -128,8 +139,8 @@ func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount if !exists || rewardsForAccountInEpoch.PoolStake == 0 { // updating epoch start for beginning epochs without the reward - if epochStart == epoch { - epochStart = epoch + 1 + if firstRewardEpoch == epoch { + firstRewardEpoch = epoch + 1 } continue @@ -166,13 +177,13 @@ func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate unDecayedEpochRewards due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } - unDecayedEpochRewards, err := safemath.SafeDiv(result, uint64(rewardsForAccountInEpoch.PoolStake)) + undecayedEpochRewards, err := safemath.SafeDiv(result, uint64(rewardsForAccountInEpoch.PoolStake)) if err != nil { return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate unDecayedEpochRewards due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } decayProvider := t.apiProvider.APIForEpoch(epoch).ManaDecayProvider() - decayedEpochRewards, err := decayProvider.DecayManaByEpochs(iotago.Mana(unDecayedEpochRewards), epoch, epochEnd) + decayedEpochRewards, err := decayProvider.DecayManaByEpochs(iotago.Mana(undecayedEpochRewards), epoch, decayEndEpoch) if err != nil { return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate rewards with decay for epoch %d and validator accountID %s", epoch, validatorID) } @@ -180,7 +191,24 @@ func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount delegatorsReward += decayedEpochRewards } - return delegatorsReward, epochStart, epochEnd, nil + return delegatorsReward, firstRewardEpoch, lastRewardEpoch, nil +} + +// Returns the epoch until which rewards are decayed. +// +// When claiming rewards in epoch X for epoch X-1, decay of X-(X-1) = 1 would be applied. Since epoch X is the +// very first epoch in which one can claim those rewards, decaying by 1 is odd, as one could never claim the full reward then. +// Hence, one epoch worth of decay is deducted in general. +// +// The decay end epoch must however be greater or equal than the last epoch for which rewards are claimed, otherwise +// the decay operation would fail since the amount of epochs to decay would be negative. +// Hence, the smallest returned decay end epoch will be the lastRewardEpoch. +func (t *Tracker) decayEndEpoch(claimingEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex) iotago.EpochIndex { + if claimingEpoch >= 1 { + claimingEpoch = claimingEpoch - 1 + } + + return lo.Max(claimingEpoch, lastRewardEpoch) } func (t *Tracker) rewardsMap(epoch iotago.EpochIndex) (ads.Map[iotago.Identifier, iotago.AccountID, *model.PoolRewards], error) { diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go index d27730805..79423b77b 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go @@ -10,6 +10,7 @@ import ( "github.com/iotaledger/hive.go/kvstore" "github.com/iotaledger/hive.go/kvstore/mapdb" "github.com/iotaledger/hive.go/lo" + "github.com/iotaledger/hive.go/log" "github.com/iotaledger/iota-core/pkg/core/account" "github.com/iotaledger/iota-core/pkg/model" "github.com/iotaledger/iota-core/pkg/protocol/engine/blocks" @@ -40,9 +41,10 @@ func NewTestSuite(t *testing.T) *TestSuite { poolRewards: make(map[iotago.EpochIndex]map[string]*model.PoolRewards), epochStats: make(map[iotago.EpochIndex]*model.PoolsStats), api: iotago.V3API( - iotago.NewV3ProtocolParameters( + iotago.NewV3SnapshotProtocolParameters( iotago.WithTimeProviderOptions(0, time.Now().Unix(), 10, 3), - iotago.WithRewardsOptions(8, 8, 11, 1154, 2, 1), + iotago.WithLivenessOptions(5, 5, 1, 2, 3), + iotago.WithRewardsOptions(8, 8, 11, 2, 1), ), ), } @@ -89,6 +91,7 @@ func (t *TestSuite) InitPerformanceTracker() { t.latestCommittedEpoch, iotago.SingleVersionProvider(t.api), func(err error) {}, + log.NewLogger("PerfTestsuite"), ) } @@ -164,13 +167,19 @@ func (t *TestSuite) AssertEpochRewards(epoch iotago.EpochIndex, actions map[stri expectedValidatorReward := t.validatorReward(alias, epoch, t.epochStats[epoch].ProfitMargin, uint64(poolRewards), uint64(action.ValidatorStake), uint64(action.PoolStake), uint64(action.FixedCost), action) accountID := t.Account(alias, true) - actualValidatorReward, _, _, err := t.Instance.ValidatorReward(accountID, actions[alias].ValidatorStake, epoch, epoch) + actualValidatorReward, _, _, err := t.Instance.ValidatorReward(accountID, + &iotago.StakingFeature{ + StakedAmount: actions[alias].ValidatorStake, + StartEpoch: epoch, + EndEpoch: epoch, + }, + epoch) require.NoError(t.T, err) require.Equal(t.T, expectedValidatorReward, actualValidatorReward) for delegatedAmount := range action.Delegators { expectedDelegatorReward := t.delegatorReward(epoch, t.epochStats[epoch].ProfitMargin, uint64(poolRewards), uint64(delegatedAmount), uint64(action.PoolStake), uint64(action.FixedCost), action) - actualDelegatorReward, _, _, err := t.Instance.DelegatorReward(accountID, iotago.BaseToken(delegatedAmount), epoch, epoch) + actualDelegatorReward, _, _, err := t.Instance.DelegatorReward(accountID, iotago.BaseToken(delegatedAmount), epoch, epoch, epoch) require.NoError(t.T, err) require.Equal(t.T, expectedDelegatorReward, actualDelegatorReward) } @@ -180,13 +189,19 @@ func (t *TestSuite) AssertEpochRewards(epoch iotago.EpochIndex, actions map[stri func (t *TestSuite) AssertNoReward(alias string, epoch iotago.EpochIndex, actions map[string]*EpochActions) { accID := t.Account(alias, false) - actualValidatorReward, _, _, err := t.Instance.ValidatorReward(accID, actions[alias].ValidatorStake, epoch, epoch) + actualValidatorReward, _, _, err := t.Instance.ValidatorReward(accID, + &iotago.StakingFeature{ + StakedAmount: actions[alias].ValidatorStake, + StartEpoch: epoch, + EndEpoch: epoch, + }, + epoch) require.NoError(t.T, err) require.Equal(t.T, iotago.Mana(0), actualValidatorReward) action, exists := actions[alias] require.True(t.T, exists) for delegatedAmount := range action.Delegators { - actualDelegatorReward, _, _, err := t.Instance.DelegatorReward(accID, iotago.BaseToken(delegatedAmount), epoch, epoch) + actualDelegatorReward, _, _, err := t.Instance.DelegatorReward(accID, iotago.BaseToken(delegatedAmount), epoch, epoch, epoch) require.NoError(t.T, err) require.Equal(t.T, iotago.Mana(0), actualDelegatorReward) } @@ -194,14 +209,20 @@ func (t *TestSuite) AssertNoReward(alias string, epoch iotago.EpochIndex, action func (t *TestSuite) AssertRewardForDelegatorsOnly(alias string, epoch iotago.EpochIndex, actions map[string]*EpochActions) { accID := t.Account(alias, false) - actualValidatorReward, _, _, err := t.Instance.ValidatorReward(accID, actions[alias].ValidatorStake, epoch, epoch) + actualValidatorReward, _, _, err := t.Instance.ValidatorReward(accID, + &iotago.StakingFeature{ + StakedAmount: actions[alias].ValidatorStake, + StartEpoch: epoch, + EndEpoch: epoch, + }, + epoch) require.NoError(t.T, err) require.Equal(t.T, iotago.Mana(0), actualValidatorReward) action, exists := actions[alias] require.True(t.T, exists) for delegatedAmount := range action.Delegators { - actualDelegatorReward, _, _, err := t.Instance.DelegatorReward(accID, iotago.BaseToken(delegatedAmount), epoch, epoch) + actualDelegatorReward, _, _, err := t.Instance.DelegatorReward(accID, iotago.BaseToken(delegatedAmount), epoch, epoch, epoch) expectedDelegatorReward := t.delegatorReward(epoch, t.epochStats[epoch].ProfitMargin, uint64(t.poolRewards[epoch][alias].PoolRewards), uint64(delegatedAmount), uint64(action.PoolStake), uint64(action.FixedCost), action) require.NoError(t.T, err) @@ -319,12 +340,18 @@ func (t *TestSuite) calculateExpectedRewards(epochsCount int, epochActions map[s delegatorRewardPerAccount[epoch] = make(map[string]iotago.Mana) validatorRewardPerAccount[epoch] = make(map[string]iotago.Mana) for aliasAccount := range epochActions { - reward, _, _, err := t.Instance.DelegatorReward(t.Account(aliasAccount, false), 1, epoch, epoch) + reward, _, _, err := t.Instance.DelegatorReward(t.Account(aliasAccount, false), 1, epoch, epoch, epoch) require.NoError(t.T, err) delegatorRewardPerAccount[epoch][aliasAccount] = reward } for aliasAccount := range epochActions { - reward, _, _, err := t.Instance.ValidatorReward(t.Account(aliasAccount, true), 1, epoch, epoch) + reward, _, _, err := t.Instance.ValidatorReward(t.Account(aliasAccount, true), + &iotago.StakingFeature{ + StakedAmount: 1, + StartEpoch: epoch, + EndEpoch: epoch, + }, + epoch) require.NoError(t.T, err) validatorRewardPerAccount[epoch][aliasAccount] = reward } @@ -334,11 +361,23 @@ func (t *TestSuite) calculateExpectedRewards(epochsCount int, epochActions map[s func (t *TestSuite) AssertValidatorRewardGreaterThan(alias1 string, alias2 string, epoch iotago.EpochIndex, actions map[string]*EpochActions) { accID1 := t.Account(alias1, false) - actualValidatorReward1, _, _, err := t.Instance.ValidatorReward(accID1, actions[alias1].ValidatorStake, epoch, epoch) + actualValidatorReward1, _, _, err := t.Instance.ValidatorReward(accID1, + &iotago.StakingFeature{ + StakedAmount: actions[alias1].ValidatorStake, + StartEpoch: epoch, + EndEpoch: epoch, + }, + epoch) require.NoError(t.T, err) accID2 := t.Account(alias2, false) - actualValidatorReward2, _, _, err := t.Instance.ValidatorReward(accID2, actions[alias2].ValidatorStake, epoch, epoch) + actualValidatorReward2, _, _, err := t.Instance.ValidatorReward(accID2, + &iotago.StakingFeature{ + StakedAmount: actions[alias2].ValidatorStake, + StartEpoch: epoch, + EndEpoch: epoch, + }, + epoch) require.NoError(t.T, err) require.Greater(t.T, actualValidatorReward1, actualValidatorReward2) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index 487c1e0f3..7ca6a4a32 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -59,10 +59,10 @@ func NewProvider(opts ...options.Option[SybilProtection]) module.Provider[*engin e.Constructed.OnTrigger(func() { o.ledger = e.Ledger o.errHandler = e.ErrorHandler("SybilProtection") - + logger, _ := e.NewChildLogger("PerformanceTracker") latestCommittedSlot := e.Storage.Settings().LatestCommitment().Slot() latestCommittedEpoch := o.apiProvider.APIForSlot(latestCommittedSlot).TimeProvider().EpochFromSlot(latestCommittedSlot) - o.performanceTracker = performance.NewTracker(e.Storage.RewardsForEpoch, e.Storage.PoolStats(), e.Storage.Committee(), e.Storage.CommitteeCandidates, e.Storage.ValidatorPerformances, latestCommittedEpoch, e, o.errHandler) + o.performanceTracker = performance.NewTracker(e.Storage.RewardsForEpoch, e.Storage.PoolStats(), e.Storage.Committee(), e.Storage.CommitteeCandidates, e.Storage.ValidatorPerformances, latestCommittedEpoch, e, o.errHandler, logger) o.lastCommittedSlot = latestCommittedSlot if o.optsInitialCommittee != nil { @@ -246,12 +246,12 @@ func (o *SybilProtection) SeatManager() seatmanager.SeatManager { return o.seatManager } -func (o *SybilProtection) ValidatorReward(validatorID iotago.AccountID, stakeAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (validatorReward iotago.Mana, actualEpochStart iotago.EpochIndex, actualEpochEnd iotago.EpochIndex, err error) { - return o.performanceTracker.ValidatorReward(validatorID, stakeAmount, epochStart, epochEnd) +func (o *SybilProtection) ValidatorReward(validatorID iotago.AccountID, stakingFeature *iotago.StakingFeature, claimingEpoch iotago.EpochIndex) (validatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) { + return o.performanceTracker.ValidatorReward(validatorID, stakingFeature, claimingEpoch) } -func (o *SybilProtection) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (delegatorsReward iotago.Mana, actualEpochStart iotago.EpochIndex, actualEpochEnd iotago.EpochIndex, err error) { - return o.performanceTracker.DelegatorReward(validatorID, delegatedAmount, epochStart, epochEnd) +func (o *SybilProtection) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex, claimingEpoch iotago.EpochIndex) (delegatorReward iotago.Mana, firstRewardEpoch iotago.EpochIndex, lastRewardEpoch iotago.EpochIndex, err error) { + return o.performanceTracker.DelegatorReward(validatorID, delegatedAmount, epochStart, epochEnd, claimingEpoch) } func (o *SybilProtection) Import(reader io.ReadSeeker) error { diff --git a/pkg/storage/permanent/settings.go b/pkg/storage/permanent/settings.go index a9bf979b2..96c89497b 100644 --- a/pkg/storage/permanent/settings.go +++ b/pkg/storage/permanent/settings.go @@ -30,13 +30,14 @@ const ( ) type Settings struct { - mutex syncutils.RWMutex store kvstore.KVStore storeSnapshotImported *kvstore.TypedValue[bool] storeLatestCommitment *kvstore.TypedValue[*model.Commitment] storeLatestFinalizedSlot *kvstore.TypedValue[iotago.SlotIndex] storeLatestProcessedSlot *kvstore.TypedValue[iotago.SlotIndex] storeLatestIssuedValidationBlock *kvstore.TypedValue[*model.Block] + + mutex syncutils.RWMutex storeProtocolVersionEpochMapping *kvstore.TypedStore[iotago.Version, iotago.EpochIndex] storeFutureProtocolParameters *kvstore.TypedStore[iotago.Version, *types.Tuple[iotago.EpochIndex, iotago.Identifier]] storeProtocolParameters *kvstore.TypedStore[iotago.Version, iotago.ProtocolParameters] @@ -235,30 +236,18 @@ func (s *Settings) StoreFutureProtocolParametersHash(version iotago.Version, has } func (s *Settings) IsSnapshotImported() bool { - s.mutex.RLock() - defer s.mutex.RUnlock() - return lo.PanicOnErr(s.storeSnapshotImported.Has()) } func (s *Settings) SetSnapshotImported() (err error) { - s.mutex.Lock() - defer s.mutex.Unlock() - return s.storeSnapshotImported.Set(true) } func (s *Settings) LatestCommitment() *model.Commitment { - s.mutex.RLock() - defer s.mutex.RUnlock() - return s.latestCommitment() } func (s *Settings) SetLatestCommitment(latestCommitment *model.Commitment) (err error) { - s.mutex.Lock() - defer s.mutex.Unlock() - s.apiProvider.SetCommittedSlot(latestCommitment.Slot()) // Delete the old future protocol parameters if they exist. @@ -280,13 +269,6 @@ func (s *Settings) latestCommitment() *model.Commitment { return commitment } -func (s *Settings) LatestFinalizedSlot() iotago.SlotIndex { - s.mutex.RLock() - defer s.mutex.RUnlock() - - return s.latestFinalizedSlot() -} - func (s *Settings) SetLatestFinalizedSlot(slot iotago.SlotIndex) (err error) { s.mutex.Lock() defer s.mutex.Unlock() @@ -294,7 +276,7 @@ func (s *Settings) SetLatestFinalizedSlot(slot iotago.SlotIndex) (err error) { return s.storeLatestFinalizedSlot.Set(slot) } -func (s *Settings) latestFinalizedSlot() iotago.SlotIndex { +func (s *Settings) LatestFinalizedSlot() iotago.SlotIndex { latestFinalizedSlot, err := s.storeLatestFinalizedSlot.Get() if err != nil { if ierrors.Is(err, kvstore.ErrKeyNotFound) { @@ -307,22 +289,19 @@ func (s *Settings) latestFinalizedSlot() iotago.SlotIndex { } func (s *Settings) LatestStoredSlot() iotago.SlotIndex { - s.mutex.RLock() - defer s.mutex.RUnlock() - return read(s.storeLatestProcessedSlot) } func (s *Settings) SetLatestStoredSlot(slot iotago.SlotIndex) (err error) { - s.mutex.Lock() - defer s.mutex.Unlock() - return s.storeLatestProcessedSlot.Set(slot) } func (s *Settings) AdvanceLatestStoredSlot(slot iotago.SlotIndex) (err error) { - s.mutex.Lock() - defer s.mutex.Unlock() + // We don't need to advance the latest stored slot if it's already ahead of the given slot. + // We check this before Compute to avoid contention inside the TypedValue. + if s.LatestStoredSlot() >= slot { + return nil + } if _, err = s.storeLatestProcessedSlot.Compute(func(latestStoredSlot iotago.SlotIndex, _ bool) (newValue iotago.SlotIndex, err error) { if latestStoredSlot >= slot { @@ -338,9 +317,6 @@ func (s *Settings) AdvanceLatestStoredSlot(slot iotago.SlotIndex) (err error) { } func (s *Settings) LatestIssuedValidationBlock() *model.Block { - s.mutex.RLock() - defer s.mutex.RUnlock() - return read(s.storeLatestIssuedValidationBlock) } diff --git a/pkg/storage/testframework_test.go b/pkg/storage/testframework_test.go index e3a98772e..8495409bf 100644 --- a/pkg/storage/testframework_test.go +++ b/pkg/storage/testframework_test.go @@ -48,7 +48,7 @@ func NewTestFramework(t *testing.T, baseDir string, storageOpts ...options.Optio storageFactoryFunc := func() *storage.Storage { instance := storage.Create(baseDir, 0, errorHandler, storageOpts...) - require.NoError(t, instance.Settings().StoreProtocolParametersForStartEpoch(iotago.NewV3ProtocolParameters(), 0)) + require.NoError(t, instance.Settings().StoreProtocolParametersForStartEpoch(iotago.NewV3SnapshotProtocolParameters(), 0)) return instance } diff --git a/pkg/tests/accounts_test.go b/pkg/tests/accounts_test.go index 3c2b2c15a..dc5a54e16 100644 --- a/pkg/tests/accounts_test.go +++ b/pkg/tests/accounts_test.go @@ -26,14 +26,7 @@ func Test_TransitionAndDestroyAccount(t *testing.T) { 0, testsuite.GenesisTimeWithOffsetBySlots(200, testsuite.DefaultSlotDurationInSeconds), testsuite.DefaultSlotDurationInSeconds, - 8, - ), - iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, - testsuite.DefaultMinCommittableAge, - 100, - 120, + testsuite.DefaultSlotsPerEpochExponent, ), ), ) @@ -171,14 +164,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) { 0, testsuite.GenesisTimeWithOffsetBySlots(100, testsuite.DefaultSlotDurationInSeconds), testsuite.DefaultSlotDurationInSeconds, - 8, - ), - iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, - testsuite.DefaultMinCommittableAge, - 100, - 120, + testsuite.DefaultSlotsPerEpochExponent, ), ), ) @@ -355,14 +341,7 @@ func Test_ImplicitAccounts(t *testing.T) { 0, testsuite.GenesisTimeWithOffsetBySlots(100, testsuite.DefaultSlotDurationInSeconds), testsuite.DefaultSlotDurationInSeconds, - 8, - ), - iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, - testsuite.DefaultMinCommittableAge, - 100, - 120, + testsuite.DefaultSlotsPerEpochExponent, ), ), ) @@ -483,14 +462,7 @@ func Test_NegativeBIC_BlockIssuerLocked(t *testing.T) { iotago.SlotIndex(0), testsuite.GenesisTimeWithOffsetBySlots(iotago.SlotIndex(200), testsuite.DefaultSlotDurationInSeconds), testsuite.DefaultSlotDurationInSeconds, - 8, - ), - iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, - testsuite.DefaultMinCommittableAge, - 100, - testsuite.DefaultEpochNearingThreshold, + testsuite.DefaultSlotsPerEpochExponent, ), ), ) @@ -681,14 +653,7 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) { 0, testsuite.GenesisTimeWithOffsetBySlots(200, testsuite.DefaultSlotDurationInSeconds), testsuite.DefaultSlotDurationInSeconds, - 8, - ), - iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, - testsuite.DefaultMinCommittableAge, - 100, - testsuite.DefaultEpochNearingThreshold, + testsuite.DefaultSlotsPerEpochExponent, ), ), ) @@ -885,8 +850,8 @@ func Test_NegativeBIC_AccountOutput(t *testing.T) { // assert diff of the destroyed account. ts.AssertAccountDiff(wallet1.BlockIssuer.AccountID, block4Slot, &model.AccountDiff{ - BICChange: -iotago.BlockIssuanceCredits(9500), - PreviousUpdatedSlot: 21, + BICChange: -iotago.BlockIssuanceCredits(wallet1BIC), + PreviousUpdatedSlot: block3Slot, NewExpirySlot: 0, PreviousExpirySlot: newExpirySlot, NewOutputID: iotago.EmptyOutputID, @@ -908,14 +873,7 @@ func Test_NegativeBIC_AccountOwnedBasicOutputLocked(t *testing.T) { 0, testsuite.GenesisTimeWithOffsetBySlots(200, testsuite.DefaultSlotDurationInSeconds), testsuite.DefaultSlotDurationInSeconds, - 8, - ), - iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, - testsuite.DefaultMinCommittableAge, - 100, - testsuite.DefaultEpochNearingThreshold, + testsuite.DefaultSlotsPerEpochExponent, ), ), ) diff --git a/pkg/tests/booker_test.go b/pkg/tests/booker_test.go index 79654b44f..36b31c2e0 100644 --- a/pkg/tests/booker_test.go +++ b/pkg/tests/booker_test.go @@ -328,8 +328,8 @@ func Test_SpendRejectedCommittedRace(t *testing.T) { testsuite.DefaultSlotsPerEpochExponent, ), iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, + 15, + 15, 2, 5, testsuite.DefaultEpochNearingThreshold, @@ -601,8 +601,8 @@ func Test_SpendPendingCommittedRace(t *testing.T) { testsuite.DefaultSlotsPerEpochExponent, ), iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, + 15, + 15, 2, 5, testsuite.DefaultEpochNearingThreshold, diff --git a/pkg/tests/reward_test.go b/pkg/tests/reward_test.go index 2b3000f76..dbca89541 100644 --- a/pkg/tests/reward_test.go +++ b/pkg/tests/reward_test.go @@ -22,13 +22,7 @@ func setupRewardTestsuite(t *testing.T) (*testsuite.TestSuite, *mock.Node, *mock testsuite.DefaultSlotDurationInSeconds, 8, ), - iotago.WithLivenessOptions( - testsuite.DefaultLivenessThresholdLowerBoundInSeconds, - testsuite.DefaultLivenessThresholdUpperBoundInSeconds, - testsuite.DefaultMinCommittableAge, - 100, - 120, - ), + iotago.WithStakingOptions(2, 10, 10), ), ) diff --git a/pkg/tests/upgrade_signaling_test.go b/pkg/tests/upgrade_signaling_test.go index 511ca05c0..a9d81f508 100644 --- a/pkg/tests/upgrade_signaling_test.go +++ b/pkg/tests/upgrade_signaling_test.go @@ -49,7 +49,7 @@ func Test_Upgrade_Signaling(t *testing.T) { defer ts.Shutdown() // We "pretend" to have version 5 but reuse the same protocol parameters as for version 3. - v5ProtocolParameters := iotago.NewV3ProtocolParameters( + v5ProtocolParameters := iotago.NewV3SnapshotProtocolParameters( append( ts.ProtocolParameterOptions, iotago.WithVersion(5), diff --git a/pkg/tests/validator_test.go b/pkg/tests/validator_test.go new file mode 100644 index 000000000..b6aa29915 --- /dev/null +++ b/pkg/tests/validator_test.go @@ -0,0 +1,384 @@ +package tests + +import ( + "fmt" + "testing" + "time" + + "github.com/iotaledger/hive.go/core/safemath" + "github.com/iotaledger/hive.go/lo" + "github.com/iotaledger/hive.go/log" + "github.com/iotaledger/hive.go/runtime/options" + "github.com/iotaledger/iota-core/pkg/testsuite" + "github.com/iotaledger/iota-core/pkg/testsuite/mock" + "github.com/stretchr/testify/require" + + iotago "github.com/iotaledger/iota.go/v4" +) + +// IOTA Mainnet Max Supply. +const MAX_SUPPLY = iotago.BaseToken(4_600_000_000_000_000) + +func setupValidatorTestsuite(t *testing.T, walletOpts ...options.Option[testsuite.WalletOptions]) *testsuite.TestSuite { + var slotDuration uint8 = 5 + var slotsPerEpochExponent uint8 = 5 + var validationBlocksPerSlot uint8 = 5 + + ts := testsuite.NewTestSuite(t, + testsuite.WithProtocolParametersOptions( + iotago.WithSupplyOptions(MAX_SUPPLY, 63, 1, 17, 32, 21, 70), + iotago.WithStakingOptions(1, validationBlocksPerSlot, 1), + // Pick larger values for ManaShareCoefficient and DecayBalancingConstant for more precision in the calculations. + iotago.WithRewardsOptions(8, 8, 11, 200, 200), + // Pick Increase/Decrease threshold in accordance with sanity checks (necessary because we changed slot duration). + iotago.WithCongestionControlOptions(1, 0, 0, 400_000, 300_000, 100_000, 1000, 100), + iotago.WithTimeProviderOptions( + 0, + testsuite.GenesisTimeWithOffsetBySlots(1000, slotDuration), + slotDuration, + slotsPerEpochExponent, + ), + iotago.WithLivenessOptions( + 10, + 20, + 5, + 10, + 15, + ), + ), + ) + + // Add validator nodes to the network. This will add validator accounts to the snapshot. + vnode1 := ts.AddValidatorNode("node1", append( + []options.Option[testsuite.WalletOptions]{ + testsuite.WithWalletAmount(20_000_000), + }, + walletOpts..., + )...) + vnode2 := ts.AddValidatorNode("node2", append( + []options.Option[testsuite.WalletOptions]{ + testsuite.WithWalletAmount(25_000_000), + }, + walletOpts..., + )...) + + // Add a non-validator node to the network. This will not add any accounts to the snapshot. + node3 := ts.AddNode("node3") + // Add a default block issuer to the network. This will add another block issuer account to the snapshot. + ts.AddDefaultWallet(vnode1) + + ts.Run(true) + + // For debugging set the log level appropriately. + vnode1.Protocol.SetLogLevel(log.LevelInfo) + vnode2.Protocol.SetLogLevel(log.LevelError) + node3.Protocol.SetLogLevel(log.LevelError) + + ts.SetCurrentSlot(ts.API.ProtocolParameters().GenesisSlot() + 1) + + return ts +} + +type EpochPerformanceMap = map[iotago.EpochIndex]uint64 +type ValidatorTest struct { + ts *testsuite.TestSuite + + // How many validation blocks per slot the validator test nodes are supposed to issue. + // Can be set to a different value than validationBlocksPerSlot to model under- or overissuance. + issuancePerSlot uint8 + // The expected performance factor for each epoch. + // The length of the map determines how many epochs the validators issue blocks. + epochPerformanceFactors EpochPerformanceMap +} + +func Test_Validator_PerfectIssuance(t *testing.T) { + ts := setupValidatorTestsuite(t) + defer ts.Shutdown() + + validationBlocksPerSlot := ts.API.ProtocolParameters().ValidationBlocksPerSlot() + epochDurationSlots := uint64(ts.API.TimeProvider().EpochDurationSlots()) + + test := ValidatorTest{ + ts: ts, + issuancePerSlot: validationBlocksPerSlot, + epochPerformanceFactors: EpochPerformanceMap{ + // A validator cannot issue blocks in the genesis slot, so we deduct one slot worth of blocks. + 0: (uint64(validationBlocksPerSlot) * (epochDurationSlots - 1)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 1: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 2: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + }, + } + + validatorTest(t, test) +} + +func Test_Validator_PerfectIssuanceWithNonZeroFixedCost(t *testing.T) { + ts := setupValidatorTestsuite(t, testsuite.WithWalletFixedCost(1000)) + defer ts.Shutdown() + + validationBlocksPerSlot := ts.API.ProtocolParameters().ValidationBlocksPerSlot() + epochDurationSlots := uint64(ts.API.TimeProvider().EpochDurationSlots()) + + test := ValidatorTest{ + ts: ts, + issuancePerSlot: validationBlocksPerSlot, + epochPerformanceFactors: EpochPerformanceMap{ + // A validator cannot issue blocks in the genesis slot, so we deduct one slot worth of blocks. + 0: (uint64(validationBlocksPerSlot) * (epochDurationSlots - 1)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 1: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 2: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + }, + } + + validatorTest(t, test) +} + +func Test_Validator_PerfectIssuanceWithHugeStake(t *testing.T) { + // This gives both validators the max supply as stake, which is unrealistic, + // but is supposed to test if one validator with a huge stake causes an overflow in the rewards calculation. + ts := setupValidatorTestsuite(t, testsuite.WithWalletAmount(MAX_SUPPLY)) + defer ts.Shutdown() + + validationBlocksPerSlot := ts.API.ProtocolParameters().ValidationBlocksPerSlot() + epochDurationSlots := uint64(ts.API.TimeProvider().EpochDurationSlots()) + + test := ValidatorTest{ + ts: ts, + issuancePerSlot: validationBlocksPerSlot, + epochPerformanceFactors: EpochPerformanceMap{ + // A validator cannot issue blocks in the genesis slot, so we deduct one slot worth of blocks. + 0: (uint64(validationBlocksPerSlot) * (epochDurationSlots - 1)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 1: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 2: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + }, + } + + validatorTest(t, test) +} + +func Test_Validator_OverIssuance(t *testing.T) { + ts := setupValidatorTestsuite(t) + defer ts.Shutdown() + + test := ValidatorTest{ + ts: ts, + // Issue one more block than supposed to. + issuancePerSlot: ts.API.ProtocolParameters().ValidationBlocksPerSlot() + 1, + epochPerformanceFactors: EpochPerformanceMap{ + // We expect 0 rewards for overissuance. + // We model that in this test by setting performance factor to 0. + 0: 0, + 1: 0, + 2: 0, + }, + } + + validatorTest(t, test) +} + +func Test_Validator_UnderIssuance(t *testing.T) { + ts := setupValidatorTestsuite(t) + defer ts.Shutdown() + + // Issue less than supposed to. + validationBlocksPerSlot := ts.API.ProtocolParameters().ValidationBlocksPerSlot() - 2 + epochDurationSlots := uint64(ts.API.TimeProvider().EpochDurationSlots()) + + test := ValidatorTest{ + ts: ts, + issuancePerSlot: validationBlocksPerSlot, + epochPerformanceFactors: EpochPerformanceMap{ + // A validator cannot issue blocks in the genesis slot, so we deduct one slot worth of blocks. + 0: (uint64(validationBlocksPerSlot) * (epochDurationSlots - 1)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 1: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + 2: (uint64(validationBlocksPerSlot) * (epochDurationSlots)) >> uint64(ts.API.ProtocolParameters().SlotsPerEpochExponent()), + }, + } + + validatorTest(t, test) +} + +func Test_Validator_FixedCostExceedsRewards(t *testing.T) { + ts := setupValidatorTestsuite(t, testsuite.WithWalletFixedCost(iotago.MaxMana)) + defer ts.Shutdown() + + validationBlocksPerSlot := ts.API.ProtocolParameters().ValidationBlocksPerSlot() + + test := ValidatorTest{ + ts: ts, + issuancePerSlot: validationBlocksPerSlot, + epochPerformanceFactors: EpochPerformanceMap{ + 0: 0, + 1: 0, + 2: 0, + }, + } + + validatorTest(t, test) +} + +func validatorTest(t *testing.T, test ValidatorTest) { + ts := test.ts + + tip := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().TipSelection.SelectTips(1)[iotago.StrongParentType][0] + startEpoch := iotago.EpochIndex(0) + endEpoch := iotago.EpochIndex(len(test.epochPerformanceFactors) - 1) + fmt.Printf("ValidatorTest: startEpoch=%d, endEpoch=%d\n", startEpoch, endEpoch) + + // Calculate the period in which the validator will issue blocks. + issuancePeriod := time.Duration(ts.API.ProtocolParameters().SlotDurationInSeconds()/test.issuancePerSlot) * time.Second + // Validate until the last slot of the epoch is definitely committed. + var endEpochSlot iotago.SlotIndex = ts.API.TimeProvider().EpochEnd(endEpoch) + ts.API.ProtocolParameters().MaxCommittableAge() + // Needed to increase the block timestamp monotonically relative to the parent. + subSlotBlockCounter := time.Duration(0) + + for slot := ts.CurrentSlot(); slot <= endEpochSlot; slot++ { + ts.SetCurrentSlot(slot) + + slotStartTime := ts.API.TimeProvider().SlotStartTime(ts.CurrentSlot()).UTC() + for subslotIdx := uint8(0); subslotIdx < test.issuancePerSlot; subslotIdx++ { + for _, node := range ts.Validators() { + blockName := fmt.Sprintf("block-%s-%d/%d", node.Name, ts.CurrentSlot(), subslotIdx) + latestCommitment := node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment() + + issuingTime := slotStartTime. + Add(issuancePeriod * time.Duration(subslotIdx)). + Add(time.Duration(subSlotBlockCounter)) + + validationBlock := ts.IssueValidationBlockWithHeaderOptions(blockName, node, + mock.WithSlotCommitment(latestCommitment), + mock.WithIssuingTime(issuingTime), + mock.WithStrongParents(tip), + ) + + tip = validationBlock.ID() + subSlotBlockCounter += 1 + } + } + } + + ts.Wait(ts.Nodes()...) + + // Determine total stakes required for rewards calculation. + var totalStake iotago.BaseToken = 0 + var totalValidatorStake iotago.BaseToken = 0 + lo.ForEach(ts.Validators(), func(n *mock.Node) { + latestCommittedSlot := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() + accountData, exists, err := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().Ledger.Account(n.Validator.AccountID, latestCommittedSlot) + if err != nil || !exists { + t.Fatal(exists, err) + } + + totalStake += accountData.ValidatorStake + accountData.DelegationStake + totalValidatorStake += accountData.ValidatorStake + }) + + // Determine the rewards the validators actually got. + actualRewards := make(map[iotago.AccountID]iotago.Mana, len(ts.Validators())) + claimingEpoch := ts.API.TimeProvider().EpochFromSlot(ts.CurrentSlot()) + + for _, validatorAccount := range []string{"Genesis:1", "Genesis:2"} { + output := ts.DefaultWallet().Output(validatorAccount) + accountID := output.Output().(*iotago.AccountOutput).AccountID + + rewardMana, _, _, err := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().SybilProtection.ValidatorReward( + accountID, + output.Output().FeatureSet().Staking(), + claimingEpoch, + ) + if err != nil { + panic(err) + } + + actualRewards[accountID] = rewardMana + } + + for accountID, actualReward := range actualRewards { + lastRewardEpoch := iotago.EpochIndex(len(test.epochPerformanceFactors)) + rewards := make([]epochReward, 0, lastRewardEpoch) + for epoch := iotago.EpochIndex(0); epoch < lastRewardEpoch; epoch++ { + epochPerformanceFactor := test.epochPerformanceFactors[epoch] + epochReward := calculateEpochReward(t, ts, accountID, epoch, epochPerformanceFactor, totalStake, totalValidatorStake) + rewards = append(rewards, epochReward) + } + + expectedReward := calculateValidatorReward(t, ts, accountID, rewards, startEpoch, claimingEpoch) + + require.Equal(t, expectedReward, actualReward, "expected reward for account %s to be %d, was %d", accountID, expectedReward, actualReward) + } +} + +type epochReward struct { + Mana iotago.Mana + ProfitMargin uint64 +} + +// Calculates the reward according to +// https://github.com/iotaledger/tips/blob/tip40/tips/TIP-0040/tip-0040.md#calculations-3. +// +// For testing purposes, assumes that the account's staking data is the same in the latest committed slot +// as in the epoch for which to calculate rewards. +func calculateEpochReward(t *testing.T, ts *testsuite.TestSuite, accountID iotago.AccountID, epoch iotago.EpochIndex, epochPerformanceFactor uint64, totalStake iotago.BaseToken, totalValidatorStake iotago.BaseToken) epochReward { + + latestCommittedSlot := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() + targetReward := lo.PanicOnErr(ts.API.ProtocolParameters().RewardsParameters().TargetReward(epoch, ts.API)) + accountData, exists, err := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().Ledger.Account(accountID, latestCommittedSlot) + if err != nil || !exists { + t.Fatal(exists, err) + } + + poolStake := accountData.ValidatorStake + accountData.DelegationStake + poolCoefficientExp := iotago.BaseToken(ts.API.ProtocolParameters().RewardsParameters().PoolCoefficientExponent) + + validationBlocksPerSlot := ts.API.ProtocolParameters().ValidationBlocksPerSlot() + poolCoefficient := ((poolStake << poolCoefficientExp) / totalStake) + (accountData.ValidatorStake<> (poolCoefficientExp + 1) + + profitMargin := (totalValidatorStake << iotago.BaseToken(ts.API.ProtocolParameters().RewardsParameters().ProfitMarginExponent)) / (totalValidatorStake + totalStake) + + return epochReward{Mana: poolReward, ProfitMargin: uint64(profitMargin)} +} + +// Calculates a validator's reward according to +// https://github.com/iotaledger/tips/blob/tip40/tips/TIP-0040/tip-0040.md#calculations-4. +// +// For testing purposes, assumes that the account's staking data is the same in the latest committed slot +// as in the epoch for which to calculate rewards. +func calculateValidatorReward(t *testing.T, ts *testsuite.TestSuite, accountID iotago.AccountID, epochRewards []epochReward, startEpoch iotago.EpochIndex, claimingEpoch iotago.EpochIndex) iotago.Mana { + latestCommittedSlot := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() + accountData, exists, err := ts.DefaultWallet().Node.Protocol.Engines.Main.Get().Ledger.Account(accountID, latestCommittedSlot) + if err != nil || !exists { + t.Fatal(exists, err) + } + + profitMarginExponent := ts.API.ProtocolParameters().RewardsParameters().ProfitMarginExponent + stakedAmount := accountData.ValidatorStake + fixedCost := accountData.FixedCost + poolStake := accountData.ValidatorStake + accountData.DelegationStake + rewardEpoch := startEpoch + decayedRewards := iotago.Mana(0) + + for _, reward := range epochRewards { + if reward.Mana >= fixedCost { + rewardWithoutFixedCost := uint64(reward.Mana) - uint64(fixedCost) + + profitMarginComplement := (1 << profitMarginExponent) - reward.ProfitMargin + profitMarginFactor := (reward.ProfitMargin * rewardWithoutFixedCost) >> profitMarginExponent + + intermediate := ((profitMarginComplement * rewardWithoutFixedCost) >> profitMarginExponent) + residualValidatorFactor := lo.PanicOnErr(safemath.Safe64MulDiv(intermediate, uint64(stakedAmount), uint64(poolStake))) + + undecayedRewards := uint64(fixedCost) + profitMarginFactor + residualValidatorFactor + + decayedRewards += lo.PanicOnErr(ts.API.ManaDecayProvider().DecayManaByEpochs(iotago.Mana(undecayedRewards), rewardEpoch, claimingEpoch-1)) + } else { + decayedRewards += 0 + } + + rewardEpoch++ + } + + return decayedRewards +} diff --git a/pkg/testsuite/accounts.go b/pkg/testsuite/accounts.go index 80d2b659f..d324e78d5 100644 --- a/pkg/testsuite/accounts.go +++ b/pkg/testsuite/accounts.go @@ -14,7 +14,6 @@ func (t *TestSuite) AssertAccountStake(accountID iotago.AccountID, validatorStak nodes ...*mock.Node) { for _, node := range nodes { t.Eventually(func() error { - actualAccountData, exists, err := node.Protocol.Engines.Main.Get().Ledger.Account(accountID, node.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()) if err != nil { return ierrors.Wrap(err, "AssertAccountData: failed to load account data") diff --git a/pkg/testsuite/depositcalculator/depositcalculator_test.go b/pkg/testsuite/depositcalculator/depositcalculator_test.go index 562e1831a..b93271fe3 100644 --- a/pkg/testsuite/depositcalculator/depositcalculator_test.go +++ b/pkg/testsuite/depositcalculator/depositcalculator_test.go @@ -13,7 +13,7 @@ import ( func TestCalculate(t *testing.T) { - protocolParams := iotago.NewV3ProtocolParameters(iotago.WithVersion(3)) + protocolParams := iotago.NewV3SnapshotProtocolParameters(iotago.WithVersion(3)) storageScoreStructure := iotago.NewStorageScoreStructure(protocolParams.StorageScoreParameters()) type test struct { diff --git a/pkg/testsuite/mock/blockissuer.go b/pkg/testsuite/mock/blockissuer.go index 10b848f9f..bf6ef6340 100644 --- a/pkg/testsuite/mock/blockissuer.go +++ b/pkg/testsuite/mock/blockissuer.go @@ -583,7 +583,7 @@ func (i *BlockIssuer) validateReferences(issuingTime time.Time, slotCommitmentIn } if b.IssuingTime().After(issuingTime) { - return ierrors.Errorf("cannot issue block if the parents issuingTime is ahead block's issuingTime: %s vs %s", b.IssuingTime(), issuingTime) + return ierrors.Errorf("cannot issue block if the parents issuingTime is ahead block's issuingTime: %s vs %s", b.IssuingTime(), issuingTime.UTC()) } if b.SlotCommitmentID().Slot() > slotCommitmentIndex { return ierrors.Errorf("cannot issue block if the commitment is ahead of its parents' commitment: %s vs %s", b.SlotCommitmentID().Slot(), slotCommitmentIndex) diff --git a/pkg/testsuite/mock/wallet_transactions.go b/pkg/testsuite/mock/wallet_transactions.go index 911ba4622..62f489aad 100644 --- a/pkg/testsuite/mock/wallet_transactions.go +++ b/pkg/testsuite/mock/wallet_transactions.go @@ -453,17 +453,20 @@ func (w *Wallet) ClaimValidatorRewards(transactionName string, inputName string) panic(fmt.Sprintf("output with alias %s is not *iotago.AccountOutput", inputName)) } + apiForSlot := w.Node.Protocol.APIForSlot(w.currentSlot) + latestCommittedSlot := w.Node.Protocol.Chains.Main.Get().LatestCommitment.Get().Slot() + futureBoundedSlotIndex := latestCommittedSlot + apiForSlot.ProtocolParameters().MinCommittableAge() + claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) + rewardMana, _, _, err := w.Node.Protocol.Engines.Main.Get().SybilProtection.ValidatorReward( inputAccount.AccountID, - inputAccount.FeatureSet().Staking().StakedAmount, - inputAccount.FeatureSet().Staking().StartEpoch, - inputAccount.FeatureSet().Staking().EndEpoch, + inputAccount.FeatureSet().Staking(), + claimingEpoch, ) if err != nil { panic(fmt.Sprintf("failed to calculate reward for output %s: %s", inputName, err)) } - apiForSlot := w.Node.Protocol.APIForSlot(w.currentSlot) potentialMana := w.PotentialMana(apiForSlot, input) storedMana := w.StoredMana(apiForSlot, input) @@ -541,12 +544,14 @@ func (w *Wallet) ClaimDelegatorRewards(transactionName string, inputName string) } apiForSlot := w.Node.Protocol.APIForSlot(w.currentSlot) + futureBoundedSlotIndex := w.currentSlot + apiForSlot.ProtocolParameters().MinCommittableAge() + claimingEpoch := apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) + delegationEnd := inputDelegation.EndEpoch // If Delegation ID is zeroed, the output is in delegating state, which means its End Epoch is not set and we must use the // "last epoch" for the rewards calculation. if inputDelegation.DelegationID.Empty() { - futureBoundedSlotIndex := w.currentSlot + apiForSlot.ProtocolParameters().MinCommittableAge() - delegationEnd = apiForSlot.TimeProvider().EpochFromSlot(futureBoundedSlotIndex) - iotago.EpochIndex(1) + delegationEnd = claimingEpoch - iotago.EpochIndex(1) } rewardMana, _, _, err := w.Node.Protocol.Engines.Main.Get().SybilProtection.DelegatorReward( @@ -554,7 +559,9 @@ func (w *Wallet) ClaimDelegatorRewards(transactionName string, inputName string) inputDelegation.DelegatedAmount, inputDelegation.StartEpoch, delegationEnd, + claimingEpoch, ) + if err != nil { panic(fmt.Sprintf("failed to calculate reward for output %s: %s", inputName, err)) } diff --git a/pkg/testsuite/testsuite.go b/pkg/testsuite/testsuite.go index da0f023e7..373129411 100644 --- a/pkg/testsuite/testsuite.go +++ b/pkg/testsuite/testsuite.go @@ -32,52 +32,9 @@ import ( "github.com/iotaledger/iota.go/v4/wallet" ) -func DefaultProtocolParameterOptions(networkName string) []options.Option[iotago.V3ProtocolParameters] { - return []options.Option[iotago.V3ProtocolParameters]{ - iotago.WithNetworkOptions( - networkName, - "rms", - ), - iotago.WithSupplyOptions( - 1_000_0000, - 100, - 1, - 10, - 100, - 100, - 100, - ), - iotago.WithRewardsOptions(8, 8, 11, 1154, 2, 1), - iotago.WithStakingOptions(1, 100, 1), - - iotago.WithTimeProviderOptions( - 0, - GenesisTimeWithOffsetBySlots(0, DefaultSlotDurationInSeconds), - DefaultSlotDurationInSeconds, - DefaultSlotsPerEpochExponent, - ), - iotago.WithLivenessOptions( - DefaultLivenessThresholdLowerBoundInSeconds, - DefaultLivenessThresholdUpperBoundInSeconds, - DefaultMinCommittableAge, - DefaultMaxCommittableAge, - DefaultEpochNearingThreshold, - ), - iotago.WithCongestionControlOptions( - DefaultMinReferenceManaCost, - DefaultRMCIncrease, - DefaultRMCDecrease, - DefaultRMCIncreaseThreshold, - DefaultRMCDecreaseThreshold, - DefaultSchedulerRate, - DefaultMaxBufferSize, - DefaultMaxValBufferSize, - ), - } -} - type WalletOptions struct { Amount iotago.BaseToken + FixedCost iotago.Mana BlockIssuanceCredits iotago.BlockIssuanceCredits } @@ -87,6 +44,12 @@ func WithWalletAmount(amount iotago.BaseToken) options.Option[WalletOptions] { } } +func WithWalletFixedCost(fixedCost iotago.Mana) options.Option[WalletOptions] { + return func(opts *WalletOptions) { + opts.FixedCost = fixedCost + } +} + func WithWalletBlockIssuanceCredits(blockIssuanceCredits iotago.BlockIssuanceCredits) options.Option[WalletOptions] { return func(opts *WalletOptions) { opts.BlockIssuanceCredits = blockIssuanceCredits @@ -141,8 +104,8 @@ func NewTestSuite(testingT *testing.T, opts ...options.Option[TestSuite]) *TestS }, opts, func(t *TestSuite) { fmt.Println("Setup TestSuite -", testingT.Name(), " @ ", time.Now()) - t.ProtocolParameterOptions = append(DefaultProtocolParameterOptions(testingT.Name()), t.ProtocolParameterOptions...) - t.API = iotago.V3API(iotago.NewV3ProtocolParameters(t.ProtocolParameterOptions...)) + t.ProtocolParameterOptions = append(t.ProtocolParameterOptions, iotago.WithNetworkOptions(testingT.Name(), iotago.PrefixTestnet)) + t.API = iotago.V3API(iotago.NewV3SnapshotProtocolParameters(t.ProtocolParameterOptions...)) genesisBlock := blocks.NewRootBlock(t.API.ProtocolParameters().GenesisBlockID(), iotago.NewEmptyCommitment(t.API).MustID(), time.Unix(t.API.ProtocolParameters().GenesisUnixTimestamp(), 0)) t.RegisterBlock("Genesis", genesisBlock) @@ -394,7 +357,7 @@ func (t *TestSuite) addNodeToPartition(name string, partition string, validator BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, StakedAmount: walletOptions.Amount, StakingEndEpoch: iotago.MaxEpochIndex, - FixedCost: iotago.Mana(0), + FixedCost: walletOptions.FixedCost, AccountID: node.Validator.AccountID, } diff --git a/pkg/testsuite/testsuite_issue_blocks.go b/pkg/testsuite/testsuite_issue_blocks.go index 65d9e59f4..5c712216b 100644 --- a/pkg/testsuite/testsuite_issue_blocks.go +++ b/pkg/testsuite/testsuite_issue_blocks.go @@ -71,7 +71,8 @@ func (t *TestSuite) IssueValidationBlockWithHeaderOptions(blockName string, node timeProvider := t.API.TimeProvider() issuingTime := timeProvider.SlotStartTime(t.currentSlot).Add(time.Duration(t.uniqueBlockTimeCounter.Add(1))) - blockHeaderOptions := append(blockHeaderOpts, mock.WithIssuingTime(issuingTime)) + // Prepend the issuing time so it can be overridden via the passed options. + blockHeaderOptions := append([]options.Option[mock.BlockHeaderParams]{mock.WithIssuingTime(issuingTime)}, blockHeaderOpts...) block := node.IssueValidationBlock(context.Background(), blockName, mock.WithValidationBlockHeaderOptions(blockHeaderOptions...)) @@ -267,15 +268,21 @@ func (t *TestSuite) CommitUntilSlot(slot iotago.SlotIndex, parents ...iotago.Blo if latestCommittedSlot >= slot { return parents } + t.SetCurrentSlot(lo.Min(slot+t.API.ProtocolParameters().MinCommittableAge(), latestCommittedSlot+t.API.ProtocolParameters().MinCommittableAge())) + tips := parents chainIndex := 0 + for { // preacceptance of nextBlockSlot for _, node := range activeValidators { require.True(t.Testing, node.IsValidator(), "node: %s: is not a validator node", node.Name) + committeeAtBlockSlot, exists := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().CommitteeInSlot(t.currentSlot) + require.True(t.Testing, exists, "node: %s: does not have committee selected for slot %d", node.Name, t.currentSlot) + if committeeAtBlockSlot.HasAccount(node.Validator.AccountID) { blockName := fmt.Sprintf("chain-%s-%d-%s", parents[0].Alias(), chainIndex, node.Name) latestCommitment := node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment() diff --git a/pkg/testsuite/testsuite_options.go b/pkg/testsuite/testsuite_options.go index 5f5d9aab9..79b4398f3 100644 --- a/pkg/testsuite/testsuite_options.go +++ b/pkg/testsuite/testsuite_options.go @@ -64,22 +64,23 @@ func durationFromEnvOrDefault(defaultDuration time.Duration, envKey string) time return d } -const ( - DefaultSlotDurationInSeconds uint8 = 10 - DefaultSlotsPerEpochExponent uint8 = 5 +var ( + defaultProtocolParams = iotago.NewV3SnapshotProtocolParameters() + DefaultSlotDurationInSeconds uint8 = defaultProtocolParams.SlotDurationInSeconds() + DefaultSlotsPerEpochExponent uint8 = defaultProtocolParams.SlotsPerEpochExponent() - DefaultLivenessThresholdLowerBoundInSeconds uint16 = 30 - DefaultLivenessThresholdUpperBoundInSeconds uint16 = 30 - DefaultMinCommittableAge iotago.SlotIndex = 10 - DefaultMaxCommittableAge iotago.SlotIndex = 20 - DefaultEpochNearingThreshold iotago.SlotIndex = 24 + DefaultLivenessThresholdLowerBoundInSeconds uint16 = uint16(defaultProtocolParams.LivenessThresholdLowerBound().Seconds()) + DefaultLivenessThresholdUpperBoundInSeconds uint16 = uint16(defaultProtocolParams.LivenessThresholdUpperBound().Seconds()) + DefaultMinCommittableAge iotago.SlotIndex = defaultProtocolParams.MinCommittableAge() + DefaultMaxCommittableAge iotago.SlotIndex = defaultProtocolParams.MaxCommittableAge() + DefaultEpochNearingThreshold iotago.SlotIndex = defaultProtocolParams.EpochNearingThreshold() - DefaultMinReferenceManaCost iotago.Mana = 500 - DefaultRMCIncrease iotago.Mana = 500 - DefaultRMCDecrease iotago.Mana = 500 - DefaultRMCIncreaseThreshold iotago.WorkScore = 8 * DefaultSchedulerRate - DefaultRMCDecreaseThreshold iotago.WorkScore = 5 * DefaultSchedulerRate - DefaultSchedulerRate iotago.WorkScore = 100000 - DefaultMaxBufferSize uint32 = 100 * iotago.MaxBlockSize - DefaultMaxValBufferSize uint32 = 100 * iotago.MaxBlockSize + DefaultMinReferenceManaCost iotago.Mana = defaultProtocolParams.CongestionControlParameters().MinReferenceManaCost + DefaultRMCIncrease iotago.Mana = defaultProtocolParams.CongestionControlParameters().Increase + DefaultRMCDecrease iotago.Mana = defaultProtocolParams.CongestionControlParameters().Decrease + DefaultRMCIncreaseThreshold iotago.WorkScore = defaultProtocolParams.CongestionControlParameters().IncreaseThreshold + DefaultRMCDecreaseThreshold iotago.WorkScore = defaultProtocolParams.CongestionControlParameters().DecreaseThreshold + DefaultSchedulerRate iotago.WorkScore = defaultProtocolParams.CongestionControlParameters().SchedulerRate + DefaultMaxBufferSize uint32 = defaultProtocolParams.CongestionControlParameters().MaxBufferSize + DefaultMaxValBufferSize uint32 = defaultProtocolParams.CongestionControlParameters().MaxValidationBufferSize ) diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index a5ba98a30..13874cbf0 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -5,7 +5,7 @@ go 1.21 replace github.com/iotaledger/iota-core => ../../ require ( - github.com/iotaledger/hive.go/app v0.0.0-20231205131244-472357435a39 + github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad github.com/iotaledger/hive.go/apputils v0.0.0-20230829152614-7afc7a4d89b3 github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 ) @@ -57,21 +57,21 @@ require ( github.com/iancoleman/orderedmap v0.3.0 // indirect github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39 // indirect + github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad // indirect github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/logger v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221 // indirect - github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 // indirect - github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d // indirect + github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c // indirect + github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f // indirect + github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e // indirect + github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5 // indirect github.com/ipfs/boxo v0.13.1 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect @@ -131,7 +131,7 @@ require ( github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect - github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect + github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pokt-network/smt v0.6.1 // indirect github.com/polydawn/refmt v0.89.0 // indirect @@ -146,7 +146,7 @@ require ( github.com/raulk/go-watchdog v1.3.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect @@ -172,7 +172,7 @@ require ( golang.org/x/sync v0.5.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.4.0 // indirect + golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.14.0 // indirect gonum.org/v1/gonum v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index 09a38ec6e..3d2ccafdd 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -279,40 +279,40 @@ github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 h1:dTrD7X2PT github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7/go.mod h1:ZRdPu684P0fQ1z8sXz4dj9H5LWHhz4a9oCtvjunkSrw= github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39 h1:jxoBAPgC4I73pAwvEWI2IUCxiI1xN68IaFZ5WC1D3ek= github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39/go.mod h1:gbUvr01B5ha530GnNm8K2OsHXOd2BtzBYOMxyTX3iDg= -github.com/iotaledger/hive.go/app v0.0.0-20231205131244-472357435a39 h1:B+SzeGOUyIROHfGjoYLJRPT/GL2u2X8pe3bS5avBbZc= -github.com/iotaledger/hive.go/app v0.0.0-20231205131244-472357435a39/go.mod h1:+riYmeLApkLlj4+EpuJpEJAsj/KGfD7cqLGy7oTsPOM= +github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad h1:v7dkbVLSsmzgOWT2vjvv1MdKQXvqFbvIkx8mvh6VK7g= +github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:hTHKGFbZnuiW8yEgDuuL7ZjQTCnl8bXyHLmj3LPa648= github.com/iotaledger/hive.go/apputils v0.0.0-20230829152614-7afc7a4d89b3 h1:4aVJTc0KS77uEw0Tny4r0n1ORwcbAQDECaCclgf/6lE= github.com/iotaledger/hive.go/apputils v0.0.0-20230829152614-7afc7a4d89b3/go.mod h1:TZeAqieDu+xDOZp2e9+S+8pZp1PrfgcwLUnxmd8IgLU= -github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39 h1:zv6hp2CsJikP2jdkOjngJmpUVjhC2UfiIFN6yGvo4jA= -github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s= -github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39 h1:qAIj5vpAojkrORpOflrUYJ6iFL4osUkyP6Vr7/WK9BI= -github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39/go.mod h1:CdixkrB7VdQzEDlVuwsxPtsiJL/WXrQgz3PELIqlLko= -github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39 h1:5lXV8tI2PlMWraa9eT5xGasNdiMaAYd1159mzXdX1xM= -github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39/go.mod h1:OQ9EVTTQT1mkO/16BgwSIyQlAhEg+Cptud/yutevWsI= -github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39 h1:axE2+FtJQpAQ40KerOISEzHndqv79h7zYs8NZ7r0jNQ= -github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= -github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39 h1:KpHT3dYj+WoFnAzkW4EPluWHuhzErTree0+AF/KVBTU= -github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= +github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad h1:4XL7IIvdsWHxSKQfU+sgq3H9egN54053LF9TwMfDcTg= +github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s= +github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad h1:iNzb/Oy/nucIOXOzRcwSqqFsaeKwr2JZpZYSLp8xjlE= +github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad/go.mod h1:CO28KMA6Pp5LJPiigPQQ276zQofES+jMod08U5pyRFA= +github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad h1:pUL2UZbF4S8FIV7uKo9p+IGfZ658K1VNorQ6rzDMRvs= +github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:7vHoF//1Pt3nu0l8nDIw7bEgv2GfbL3kSgjp7Rdqhd4= +github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad h1:adLrD6dOEkM5Xdg6AOPt9/HYqy/pQ5FrprDpW4/VqUU= +github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:NmZRIoxtL6iQdVK6n5W+JOx58K/0Yn8k7WuSvpKPQ+M= +github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad h1:WDl58zJKHfwbzHs+ZB8Jq3YNgVQE5Neu2NeaX3FZuyU= +github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39 h1:Gp2h+Els9cTVYYnYsHX3zLuixb0XggIj2okK570aKww= github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39/go.mod h1:ytfKoHr/nF8u0y0G4mamfG0yjFtJiJVk0kgjnPOtsSY= -github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39 h1:Di2G2i/hGyhe3D8j/MsnZqnx1yJBiMdbXDIrtbWpe8g= -github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39/go.mod h1:6Ee7i6b4tuTHuRYnPP8VUb0wr9XFI5qlqtnttBd9jRg= -github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39 h1:kYj16hPQ0iH+1srDaIj4wZCGH5qrhsFpHkLbh3Ob1Bs= -github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39/go.mod h1:vzO4/wRkEJDEZb/9fD10oKU9k1bj4qLir2Uhl5U1FkM= -github.com/iotaledger/hive.go/logger v0.0.0-20231205131244-472357435a39 h1:m4b7gNQu1HI+LH1m0oAvuFnpp7/EC/iPGHK7ImWNk3w= -github.com/iotaledger/hive.go/logger v0.0.0-20231205131244-472357435a39/go.mod h1:w1psHM2MuKsen1WdsPKrpqElYH7ZOQ+YdQIgJZg4HTo= -github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39 h1:O6tJNVV544ts/DKIIfHQJNGXIPZgntR1DJ4e+jPR9rQ= -github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39/go.mod h1:DrZPvUvLarK8C2qb+3H2vdypp/MuhpQmB3iMJbDCr/Q= -github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39 h1:GPa5qfHm59jqY3pff0eCnt/mpWFm6fibVK/n/E+Pfyk= -github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8= -github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39 h1:gatLNIqLC/MAR5qlj+413/y0LmyfKC0QL2BKXLniD0M= -github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221 h1:+ozrau44uPy2kYv2fuj2Wks8+VkXR62WB9zONOJgzdE= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231201123347-1c44b3f24221/go.mod h1:6cLX3gnhP0WL+Q+mf3/rIqfACe5fWKVR8luPXWh2xiY= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665 h1:XdhojOpZ0t0pJFyNO0zlBogSAUrhEI67eCpTC9H6sGM= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231201114846-3bb5c3fd5665/go.mod h1:obK1N42oafGA7EH6zC4VX2fKh7jTa3WnIa9h1azfxq0= -github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d h1:MPklxa8jW4/EgDm/LEzf6orxjik7U+vMUW/ToGT1Zqg= -github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d/go.mod h1:lCk9rhP3B5pX9BKhzR+Jobq4xPd+GHlqgF4Ga+eQfWA= +github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad h1:qpCsjw+InLL824QPu3lY/osck4DhucBKhCs5/E8OH+A= +github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:ETXGXymFyNcUq2t4I9e7ZK18f9bxUWYat4pjZ9W0rWc= +github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c h1:Ksts6VjPj9y0o2Nis+2tHtDGWITNJ4yju87ZlHLPuOo= +github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c/go.mod h1:Td3R6QmYw0svZI1GuZ/tN9s0VNaHassXSKLCc70aX9w= +github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad h1:fazCxogqOLDEPNDPWYDLTDpYmwgTJgIaC2Z6VN52S4M= +github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:hVaVODS+Uik0obf3SVEHFQNruUko/uqIgD/GKwhn49M= +github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad h1:HpupWK8iqFt+Sdogkh2/N8ojalmevYy+FzhjOuy7Y7E= +github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:Z9NFsByMh1Kf98f3v3ifeZRycbS2db1hjswTQG1MxnE= +github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad h1:c8uwbBZDqpiCNN9/9Jji7Z4lL0GdVnORp8WMouiuknk= +github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8= +github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad h1:VC3OgdSbyngY7/gxVj66fKd/nGmN6P0/myr348nx7vA= +github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f h1:V68Ijq1A64gB9r0Rhc4ybLGH66rXqZ2Ly0L4uuaLrMg= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f/go.mod h1:Dy3Gv4Dn1zufB177x6IXETP3zTeiWQ1+HMVQR0Bt/ew= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e h1:jbtiUlmTpTdGiRBW1pniPSqRcDMJaIW8fGS+uORryas= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e/go.mod h1:zEb9onVHnDUStl5SsFBj7H0HBKfIN0c/pUND8Llfqp8= +github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5 h1:0KgQFpVRnKd6CdCwXo3Kg/SL27xkeKh2SMoU5G1TkZk= +github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5/go.mod h1:tiswk1O1wSAi9GE6tD1j43+bLmWU9Je07aZLaJ0+Ha0= github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI= github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= @@ -525,8 +525,8 @@ github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAv github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= +github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5 h1:+qIP3OMrT7SN5kLnTcVEISPOMB/97RyAKTg1UWA738E= +github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -627,8 +627,8 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= -github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -835,8 +835,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY= -golang.org/x/time v0.4.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/tools/genesis-snapshot/go.mod b/tools/genesis-snapshot/go.mod index 7d9bebabd..756d9ce51 100644 --- a/tools/genesis-snapshot/go.mod +++ b/tools/genesis-snapshot/go.mod @@ -5,12 +5,12 @@ go 1.21 replace github.com/iotaledger/iota-core => ../../ require ( - github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39 - github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39 + github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad + github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d + github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5 github.com/mr-tron/base58 v1.2.0 github.com/spf13/pflag v1.0.5 golang.org/x/crypto v0.16.0 @@ -27,13 +27,13 @@ require ( github.com/iancoleman/orderedmap v0.3.0 // indirect github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39 // indirect + github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad // indirect github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39 // indirect - github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39 // indirect + github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c // indirect + github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad // indirect + github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/kr/text v0.2.0 // indirect @@ -50,7 +50,7 @@ require ( github.com/otiai10/copy v1.14.0 // indirect github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect - github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect + github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pokt-network/smt v0.6.1 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index ccad4de99..578c00428 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -30,30 +30,30 @@ github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 h1:dTrD7X2PT github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7/go.mod h1:ZRdPu684P0fQ1z8sXz4dj9H5LWHhz4a9oCtvjunkSrw= github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39 h1:jxoBAPgC4I73pAwvEWI2IUCxiI1xN68IaFZ5WC1D3ek= github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39/go.mod h1:gbUvr01B5ha530GnNm8K2OsHXOd2BtzBYOMxyTX3iDg= -github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39 h1:zv6hp2CsJikP2jdkOjngJmpUVjhC2UfiIFN6yGvo4jA= -github.com/iotaledger/hive.go/constraints v0.0.0-20231205131244-472357435a39/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s= -github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39 h1:qAIj5vpAojkrORpOflrUYJ6iFL4osUkyP6Vr7/WK9BI= -github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231205131244-472357435a39/go.mod h1:CdixkrB7VdQzEDlVuwsxPtsiJL/WXrQgz3PELIqlLko= -github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39 h1:5lXV8tI2PlMWraa9eT5xGasNdiMaAYd1159mzXdX1xM= -github.com/iotaledger/hive.go/crypto v0.0.0-20231205131244-472357435a39/go.mod h1:OQ9EVTTQT1mkO/16BgwSIyQlAhEg+Cptud/yutevWsI= -github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39 h1:axE2+FtJQpAQ40KerOISEzHndqv79h7zYs8NZ7r0jNQ= -github.com/iotaledger/hive.go/ds v0.0.0-20231205131244-472357435a39/go.mod h1:JE8cbZSvzbB5TrwXibg6M0B7ck35YxF30ItHBzQRlgc= -github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39 h1:KpHT3dYj+WoFnAzkW4EPluWHuhzErTree0+AF/KVBTU= -github.com/iotaledger/hive.go/ierrors v0.0.0-20231205131244-472357435a39/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= +github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad h1:4XL7IIvdsWHxSKQfU+sgq3H9egN54053LF9TwMfDcTg= +github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s= +github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad h1:iNzb/Oy/nucIOXOzRcwSqqFsaeKwr2JZpZYSLp8xjlE= +github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad/go.mod h1:CO28KMA6Pp5LJPiigPQQ276zQofES+jMod08U5pyRFA= +github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad h1:pUL2UZbF4S8FIV7uKo9p+IGfZ658K1VNorQ6rzDMRvs= +github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:7vHoF//1Pt3nu0l8nDIw7bEgv2GfbL3kSgjp7Rdqhd4= +github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad h1:adLrD6dOEkM5Xdg6AOPt9/HYqy/pQ5FrprDpW4/VqUU= +github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:NmZRIoxtL6iQdVK6n5W+JOx58K/0Yn8k7WuSvpKPQ+M= +github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad h1:WDl58zJKHfwbzHs+ZB8Jq3YNgVQE5Neu2NeaX3FZuyU= +github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8= github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39 h1:Gp2h+Els9cTVYYnYsHX3zLuixb0XggIj2okK570aKww= github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39/go.mod h1:ytfKoHr/nF8u0y0G4mamfG0yjFtJiJVk0kgjnPOtsSY= -github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39 h1:Di2G2i/hGyhe3D8j/MsnZqnx1yJBiMdbXDIrtbWpe8g= -github.com/iotaledger/hive.go/lo v0.0.0-20231205131244-472357435a39/go.mod h1:6Ee7i6b4tuTHuRYnPP8VUb0wr9XFI5qlqtnttBd9jRg= -github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39 h1:kYj16hPQ0iH+1srDaIj4wZCGH5qrhsFpHkLbh3Ob1Bs= -github.com/iotaledger/hive.go/log v0.0.0-20231205131244-472357435a39/go.mod h1:vzO4/wRkEJDEZb/9fD10oKU9k1bj4qLir2Uhl5U1FkM= -github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39 h1:O6tJNVV544ts/DKIIfHQJNGXIPZgntR1DJ4e+jPR9rQ= -github.com/iotaledger/hive.go/runtime v0.0.0-20231205131244-472357435a39/go.mod h1:DrZPvUvLarK8C2qb+3H2vdypp/MuhpQmB3iMJbDCr/Q= -github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39 h1:GPa5qfHm59jqY3pff0eCnt/mpWFm6fibVK/n/E+Pfyk= -github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231205131244-472357435a39/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8= -github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39 h1:gatLNIqLC/MAR5qlj+413/y0LmyfKC0QL2BKXLniD0M= -github.com/iotaledger/hive.go/stringify v0.0.0-20231205131244-472357435a39/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d h1:MPklxa8jW4/EgDm/LEzf6orxjik7U+vMUW/ToGT1Zqg= -github.com/iotaledger/iota.go/v4 v4.0.0-20231204142547-416c9a87403d/go.mod h1:lCk9rhP3B5pX9BKhzR+Jobq4xPd+GHlqgF4Ga+eQfWA= +github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad h1:qpCsjw+InLL824QPu3lY/osck4DhucBKhCs5/E8OH+A= +github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:ETXGXymFyNcUq2t4I9e7ZK18f9bxUWYat4pjZ9W0rWc= +github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c h1:Ksts6VjPj9y0o2Nis+2tHtDGWITNJ4yju87ZlHLPuOo= +github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c/go.mod h1:Td3R6QmYw0svZI1GuZ/tN9s0VNaHassXSKLCc70aX9w= +github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad h1:HpupWK8iqFt+Sdogkh2/N8ojalmevYy+FzhjOuy7Y7E= +github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:Z9NFsByMh1Kf98f3v3ifeZRycbS2db1hjswTQG1MxnE= +github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad h1:c8uwbBZDqpiCNN9/9Jji7Z4lL0GdVnORp8WMouiuknk= +github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8= +github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad h1:VC3OgdSbyngY7/gxVj66fKd/nGmN6P0/myr348nx7vA= +github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= +github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5 h1:0KgQFpVRnKd6CdCwXo3Kg/SL27xkeKh2SMoU5G1TkZk= +github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5/go.mod h1:tiswk1O1wSAi9GE6tD1j43+bLmWU9Je07aZLaJ0+Ha0= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= @@ -93,8 +93,8 @@ github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c/go.mod h1:1iCZ0433 github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA= -github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= +github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5 h1:+qIP3OMrT7SN5kLnTcVEISPOMB/97RyAKTg1UWA738E= +github.com/petermattis/goid v0.0.0-20231126143041-f558c26febf5/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pokt-network/smt v0.6.1 h1:u5yTGNNND6edXv3vMQrAcjku1Ig4osehdu+EMYSXHUU= diff --git a/tools/genesis-snapshot/presets/presets.go b/tools/genesis-snapshot/presets/presets.go index 208e15859..a8e72f12e 100644 --- a/tools/genesis-snapshot/presets/presets.go +++ b/tools/genesis-snapshot/presets/presets.go @@ -16,34 +16,21 @@ import ( ) var ( - protocolParamsBase = iotago.NewV3ProtocolParameters( - iotago.WithNetworkOptions("default", "rms"), - iotago.WithSupplyOptions(4_600_000_000_000_000, 250, 1, 1000, 100000, 500000, 100000), - iotago.WithTimeProviderOptions(0, 1696841745, 10, 13), - iotago.WithLivenessOptions(30, 30, 7, 14, 30), - // increase/decrease threshold = fraction * slotDurationInSeconds * schedulerRate - iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1000, 100), - iotago.WithWorkScoreOptions(25, 1, 100, 50, 10, 10, 50, 1, 10, 250), + // use defaults from iota.go + protocolParamsBase = iotago.NewV3SnapshotProtocolParameters( + iotago.WithNetworkOptions("default", iotago.PrefixTestnet), ) - protocolParamsDocker = iotago.NewV3ProtocolParameters( - iotago.WithNetworkOptions("docker", "rms"), - iotago.WithSupplyOptions(4_600_000_000_000_000, 250, 1, 1000, 100000, 500000, 100000), + // use defaults from iota.go + protocolParamsDocker = iotago.NewV3SnapshotProtocolParameters( + iotago.WithNetworkOptions("docker", iotago.PrefixTestnet), iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 13), - iotago.WithLivenessOptions(30, 30, 7, 14, 30), - // increase/decrease threshold = fraction * slotDurationInSeconds * schedulerRate - iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1000, 100), - iotago.WithWorkScoreOptions(25, 1, 100, 50, 10, 10, 50, 1, 10, 250), ) - protocolParamsFeature = iotago.NewV3ProtocolParameters( - iotago.WithNetworkOptions("feature", "rms"), - iotago.WithSupplyOptions(4_600_000_000_000_000, 250, 1, 1000, 100000, 500000, 100000), - iotago.WithTimeProviderOptions(666666, time.Now().Unix()-100_000, 10, 13), // Let's fix genesis at 10_000 slots back. - iotago.WithLivenessOptions(30, 30, 10, 20, 30), - // increase/decrease threshold = fraction * slotDurationInSeconds * schedulerRate - iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1000, 100), - iotago.WithWorkScoreOptions(25, 1, 100, 50, 10, 10, 50, 1, 10, 250), + // use defaults from iota.go + protocolParamsFeature = iotago.NewV3SnapshotProtocolParameters( + iotago.WithNetworkOptions("feature", iotago.PrefixTestnet), + iotago.WithTimeProviderOptions(666666, time.Now().Unix()-100_000, 10, 13), ) )