From d2e9d12ed2a1b6581b8fd414cbfb89a6cfa64551 Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:39:51 -0400 Subject: [PATCH 1/9] Remove unused `meteredHandler` struct type (#3450) Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- network/p2p/router.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/network/p2p/router.go b/network/p2p/router.go index 9c020ab49356..dba1bd124d19 100644 --- a/network/p2p/router.go +++ b/network/p2p/router.go @@ -33,12 +33,6 @@ type pendingAppRequest struct { callback AppResponseCallback } -// meteredHandler emits metrics for a Handler -type meteredHandler struct { - *responder - metrics -} - type metrics struct { msgTime *prometheus.GaugeVec msgCount *prometheus.CounterVec @@ -69,7 +63,7 @@ type router struct { metrics metrics lock sync.RWMutex - handlers map[uint64]*meteredHandler + handlers map[uint64]*responder pendingAppRequests map[uint32]pendingAppRequest requestID uint32 } @@ -84,7 +78,7 @@ func newRouter( log: log, sender: sender, metrics: metrics, - handlers: make(map[uint64]*meteredHandler), + handlers: make(map[uint64]*responder), pendingAppRequests: make(map[uint32]pendingAppRequest), // invariant: sdk uses odd-numbered requestIDs requestID: 1, @@ -99,14 +93,11 @@ func (r *router) addHandler(handlerID uint64, handler Handler) error { return fmt.Errorf("failed to register handler id %d: %w", handlerID, ErrExistingAppProtocol) } - r.handlers[handlerID] = &meteredHandler{ - responder: &responder{ - Handler: handler, - handlerID: handlerID, - log: r.log, - sender: r.sender, - }, - metrics: r.metrics, + r.handlers[handlerID] = &responder{ + Handler: handler, + handlerID: handlerID, + log: r.log, + sender: r.sender, } return nil @@ -235,7 +226,7 @@ func (r *router) AppGossip(ctx context.Context, nodeID ids.NodeID, gossip []byte // - A boolean indicating that parsing succeeded. // // Invariant: Assumes [r.lock] isn't held. -func (r *router) parse(prefixedMsg []byte) ([]byte, *meteredHandler, string, bool) { +func (r *router) parse(prefixedMsg []byte) ([]byte, *responder, string, bool) { handlerID, msg, ok := ParseMessage(prefixedMsg) if !ok { return nil, nil, "", false From ab58a805404bc03a56a10eb1bde0908ea65709b4 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 9 Oct 2024 15:58:18 -0400 Subject: [PATCH 2/9] Add ACP-118 caching support (#3451) --- network/p2p/acp118/handler.go | 23 +++++++++ network/p2p/acp118/handler_test.go | 79 ++++++++++++++++++++++-------- 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/network/p2p/acp118/handler.go b/network/p2p/acp118/handler.go index ebceefb1fb85..fd7ac8dc4f36 100644 --- a/network/p2p/acp118/handler.go +++ b/network/p2p/acp118/handler.go @@ -10,6 +10,7 @@ import ( "google.golang.org/protobuf/proto" + "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/proto/pb/sdk" @@ -30,7 +31,22 @@ type Verifier interface { // NewHandler returns an instance of Handler func NewHandler(verifier Verifier, signer warp.Signer) *Handler { + return NewCachedHandler( + &cache.Empty[ids.ID, []byte]{}, + verifier, + signer, + ) +} + +// NewCachedHandler returns an instance of Handler that caches successful +// requests. +func NewCachedHandler( + cacher cache.Cacher[ids.ID, []byte], + verifier Verifier, + signer warp.Signer, +) *Handler { return &Handler{ + cacher: cacher, verifier: verifier, signer: signer, } @@ -40,6 +56,7 @@ func NewHandler(verifier Verifier, signer warp.Signer) *Handler { type Handler struct { p2p.NoOpHandler + cacher cache.Cacher[ids.ID, []byte] verifier Verifier signer warp.Signer } @@ -66,6 +83,11 @@ func (h *Handler) AppRequest( } } + msgID := msg.ID() + if responseBytes, ok := h.cacher.Get(msgID); ok { + return responseBytes, nil + } + if err := h.verifier.Verify(ctx, msg, request.Justification); err != nil { return nil, err } @@ -90,5 +112,6 @@ func (h *Handler) AppRequest( } } + h.cacher.Put(msgID, responseBytes) return responseBytes, nil } diff --git a/network/p2p/acp118/handler_test.go b/network/p2p/acp118/handler_test.go index 4ca7add318da..081ecd1f0351 100644 --- a/network/p2p/acp118/handler_test.go +++ b/network/p2p/acp118/handler_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" + "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/network/p2p/p2ptest" "github.com/ava-labs/avalanchego/proto/pb/sdk" @@ -23,20 +24,46 @@ var _ Verifier = (*testVerifier)(nil) func TestHandler(t *testing.T) { tests := []struct { - name string - verifier Verifier - expectedErr error - expectedVerify bool + name string + cacher cache.Cacher[ids.ID, []byte] + verifier Verifier + expectedErrs []error }{ { - name: "signature fails verification", - verifier: &testVerifier{Err: &common.AppError{Code: 123}}, - expectedErr: &common.AppError{Code: 123}, + name: "signature fails verification", + cacher: &cache.Empty[ids.ID, []byte]{}, + verifier: &testVerifier{ + Errs: []*common.AppError{ + {Code: 123}, + }, + }, + expectedErrs: []error{ + &common.AppError{Code: 123}, + }, }, { - name: "signature signed", - verifier: &testVerifier{}, - expectedVerify: true, + name: "signature signed", + cacher: &cache.Empty[ids.ID, []byte]{}, + verifier: &testVerifier{}, + expectedErrs: []error{ + nil, + }, + }, + { + name: "signature is cached", + cacher: &cache.LRU[ids.ID, []byte]{ + Size: 1, + }, + verifier: &testVerifier{ + Errs: []*common.AppError{ + nil, + {Code: 123}, // The valid response should be cached + }, + }, + expectedErrs: []error{ + nil, + nil, + }, }, } @@ -51,7 +78,7 @@ func TestHandler(t *testing.T) { networkID := uint32(123) chainID := ids.GenerateTestID() signer := warp.NewSigner(sk, networkID, chainID) - h := NewHandler(tt.verifier, signer) + h := NewCachedHandler(tt.cacher, tt.verifier, signer) clientNodeID := ids.GenerateTestNodeID() serverNodeID := ids.GenerateTestNodeID() c := p2ptest.NewClient( @@ -77,12 +104,17 @@ func TestHandler(t *testing.T) { requestBytes, err := proto.Marshal(request) require.NoError(err) - done := make(chan struct{}) + var ( + expectedErr error + handled = make(chan struct{}) + ) onResponse := func(_ context.Context, _ ids.NodeID, responseBytes []byte, appErr error) { - defer close(done) + defer func() { + handled <- struct{}{} + }() + require.ErrorIs(appErr, expectedErr) if appErr != nil { - require.ErrorIs(tt.expectedErr, appErr) return } @@ -92,24 +124,31 @@ func TestHandler(t *testing.T) { signature, err := bls.SignatureFromBytes(response.Signature) require.NoError(err) - require.Equal(tt.expectedVerify, bls.Verify(pk, signature, request.Message)) + require.True(bls.Verify(pk, signature, request.Message)) } - require.NoError(c.AppRequest(ctx, set.Of(clientNodeID), requestBytes, onResponse)) - <-done + for _, expectedErr = range tt.expectedErrs { + require.NoError(c.AppRequest(ctx, set.Of(clientNodeID), requestBytes, onResponse)) + <-handled + } }) } } // The zero value of testVerifier allows signing type testVerifier struct { - Err *common.AppError + Errs []*common.AppError } -func (t testVerifier) Verify( +func (t *testVerifier) Verify( context.Context, *warp.UnsignedMessage, []byte, ) *common.AppError { - return t.Err + if len(t.Errs) == 0 { + return nil + } + err := t.Errs[0] + t.Errs = t.Errs[1:] + return err } From 9d6dba8e032fbc6c95d7364c5db2deaa0beae7bb Mon Sep 17 00:00:00 2001 From: marun Date: Fri, 11 Oct 2024 08:37:25 -0700 Subject: [PATCH 3/9] [testing] Enable verbose image build output for bootstrap-monitor e2e (#3461) --- tests/fixture/bootstrapmonitor/e2e/e2e_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go index 2f5a319fc02d..45de49bce990 100644 --- a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go +++ b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go @@ -234,7 +234,10 @@ func buildImage(tc tests.TestContext, imageName string, forceNewHash bool, scrip repoRoot, err := e2e.GetRepoRootPath(repoRelativePath) require.NoError(err) - var args []string + args := []string{ + "-x", // Ensure script output to aid in debugging + filepath.Join(repoRoot, "scripts", scriptName), + } if forceNewHash { // Ensure the build results in a new image hash by preventing use of a cached final stage args = append(args, "--no-cache-filter", "execution") @@ -242,7 +245,7 @@ func buildImage(tc tests.TestContext, imageName string, forceNewHash bool, scrip cmd := exec.CommandContext( tc.DefaultContext(), - filepath.Join(repoRoot, "scripts", scriptName), + "bash", args..., ) // #nosec G204 cmd.Env = append(os.Environ(), From a7fe93b971052b27d6aede653f597fe487b1aa4e Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 11 Oct 2024 15:08:33 -0400 Subject: [PATCH 4/9] Remove unexpected block unwrapping (#3455) --- vms/platformvm/block/executor/verifier.go | 56 ++++++++++++++----- .../block/executor/verifier_test.go | 5 +- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/vms/platformvm/block/executor/verifier.go b/vms/platformvm/block/executor/verifier.go index abcbc566a303..38320050af21 100644 --- a/vms/platformvm/block/executor/verifier.go +++ b/vms/platformvm/block/executor/verifier.go @@ -90,7 +90,8 @@ func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error { } return v.proposalBlock( - &b.ApricotProposalBlock, + b, + b.Tx, onDecisionState, onCommitState, onAbortState, @@ -129,7 +130,12 @@ func (v *verifier) BanffStandardBlock(b *block.BanffStandardBlock) error { } feeCalculator := state.PickFeeCalculator(v.txExecutorBackend.Config, onAcceptState) - return v.standardBlock(&b.ApricotStandardBlock, feeCalculator, onAcceptState) + return v.standardBlock( + b, + b.Transactions, + feeCalculator, + onAcceptState, + ) } func (v *verifier) ApricotAbortBlock(b *block.ApricotAbortBlock) error { @@ -165,7 +171,17 @@ func (v *verifier) ApricotProposalBlock(b *block.ApricotProposalBlock) error { timestamp = onCommitState.GetTimestamp() // Equal to parent timestamp feeCalculator = state.NewStaticFeeCalculator(v.txExecutorBackend.Config, timestamp) ) - return v.proposalBlock(b, nil, onCommitState, onAbortState, feeCalculator, nil, nil, nil) + return v.proposalBlock( + b, + b.Tx, + nil, + onCommitState, + onAbortState, + feeCalculator, + nil, + nil, + nil, + ) } func (v *verifier) ApricotStandardBlock(b *block.ApricotStandardBlock) error { @@ -183,7 +199,12 @@ func (v *verifier) ApricotStandardBlock(b *block.ApricotStandardBlock) error { timestamp = onAcceptState.GetTimestamp() // Equal to parent timestamp feeCalculator = state.NewStaticFeeCalculator(v.txExecutorBackend.Config, timestamp) ) - return v.standardBlock(b, feeCalculator, onAcceptState) + return v.standardBlock( + b, + b.Transactions, + feeCalculator, + onAcceptState, + ) } func (v *verifier) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error { @@ -360,7 +381,8 @@ func (v *verifier) commitBlock(b block.Block) error { // proposalBlock populates the state of this block if [nil] is returned func (v *verifier) proposalBlock( - b *block.ApricotProposalBlock, + b block.Block, + tx *txs.Tx, onDecisionState state.Diff, onCommitState state.Diff, onAbortState state.Diff, @@ -374,19 +396,19 @@ func (v *verifier) proposalBlock( OnAbortState: onAbortState, Backend: v.txExecutorBackend, FeeCalculator: feeCalculator, - Tx: b.Tx, + Tx: tx, } - if err := b.Tx.Unsigned.Visit(&txExecutor); err != nil { - txID := b.Tx.ID() + if err := tx.Unsigned.Visit(&txExecutor); err != nil { + txID := tx.ID() v.MarkDropped(txID, err) // cache tx as dropped return err } - onCommitState.AddTx(b.Tx, status.Committed) - onAbortState.AddTx(b.Tx, status.Aborted) + onCommitState.AddTx(tx, status.Committed) + onAbortState.AddTx(tx, status.Aborted) - v.Mempool.Remove(b.Tx) + v.Mempool.Remove(tx) blkID := b.ID() v.blkIDToState[blkID] = &blockState{ @@ -413,16 +435,22 @@ func (v *verifier) proposalBlock( // standardBlock populates the state of this block if [nil] is returned func (v *verifier) standardBlock( - b *block.ApricotStandardBlock, + b block.Block, + txs []*txs.Tx, feeCalculator fee.Calculator, onAcceptState state.Diff, ) error { - inputs, atomicRequests, onAcceptFunc, err := v.processStandardTxs(b.Transactions, feeCalculator, onAcceptState, b.Parent()) + inputs, atomicRequests, onAcceptFunc, err := v.processStandardTxs( + txs, + feeCalculator, + onAcceptState, + b.Parent(), + ) if err != nil { return err } - v.Mempool.Remove(b.Transactions...) + v.Mempool.Remove(txs...) blkID := b.ID() v.blkIDToState[blkID] = &blockState{ diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index 5b786b0e33d8..f57b8fb4ed58 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -1184,8 +1184,9 @@ func TestBlockExecutionWithComplexity(t *testing.T) { } require.Contains(verifier.blkIDToState, blkID) - onAcceptState := verifier.blkIDToState[blkID].onAcceptState - require.Equal(test.expectedFeeState, onAcceptState.GetFeeState()) + blockState := verifier.blkIDToState[blkID] + require.Equal(blk, blockState.statelessBlock) + require.Equal(test.expectedFeeState, blockState.onAcceptState.GetFeeState()) }) } } From 724bd36fa7e5c3f02c5cd436f3b6a3233c93ba7e Mon Sep 17 00:00:00 2001 From: marun Date: Fri, 11 Oct 2024 14:28:57 -0700 Subject: [PATCH 5/9] [ci] Update MacOS jobs to macos-14 (#3462) --- .github/workflows/build-macos-release.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-macos-release.yml b/.github/workflows/build-macos-release.yml index 62856e8131da..b37d1dc01545 100644 --- a/.github/workflows/build-macos-release.yml +++ b/.github/workflows/build-macos-release.yml @@ -18,7 +18,7 @@ jobs: # This workflow contains a single job called "build" build-mac: # The type of runner that the job will run on - runs-on: macos-12 + runs-on: macos-14 permissions: id-token: write contents: read diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0851d0cf44a..4a489b3c16c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-12, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-2022, custom-arm64-jammy, custom-arm64-noble] + os: [macos-14, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-2022, custom-arm64-jammy, custom-arm64-noble] steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project From b9e2af216df3818ad6339e29967c2157a6c30958 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 11 Oct 2024 17:54:46 -0400 Subject: [PATCH 6/9] ACP-77: Include validator capacity into the fee config (#3464) --- config/config.go | 2 +- config/flags.go | 2 +- genesis/genesis_fuji.go | 2 +- genesis/genesis_local.go | 2 +- genesis/genesis_mainnet.go | 2 +- genesis/params.go | 9 ++++----- node/node.go | 1 - vms/platformvm/config/config.go | 3 +-- vms/platformvm/validators/fee/fee.go | 1 + 9 files changed, 11 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index 46fd0aac8af5..8a95045b7f77 100644 --- a/config/config.go +++ b/config/config.go @@ -793,8 +793,8 @@ func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig { MinPrice: gas.Price(v.GetUint64(DynamicFeesMinGasPriceKey)), ExcessConversionConstant: gas.Gas(v.GetUint64(DynamicFeesExcessConversionConstantKey)), }, - ValidatorFeeCapacity: gas.Gas(v.GetUint64(ValidatorFeesCapacityKey)), ValidatorFeeConfig: validatorfee.Config{ + Capacity: gas.Gas(v.GetUint64(ValidatorFeesCapacityKey)), Target: gas.Gas(v.GetUint64(ValidatorFeesTargetKey)), MinPrice: gas.Price(v.GetUint64(ValidatorFeesMinPriceKey)), ExcessConversionConstant: gas.Gas(v.GetUint64(ValidatorFeesExcessConversionConstantKey)), diff --git a/config/flags.go b/config/flags.go index c20b243c8079..d8397ce40a2c 100644 --- a/config/flags.go +++ b/config/flags.go @@ -106,7 +106,7 @@ func addNodeFlags(fs *pflag.FlagSet) { // AVAX fees: // Validator fees: - fs.Uint64(ValidatorFeesCapacityKey, uint64(genesis.LocalParams.ValidatorFeeCapacity), "Maximum number of validators") + fs.Uint64(ValidatorFeesCapacityKey, uint64(genesis.LocalParams.ValidatorFeeConfig.Capacity), "Maximum number of validators") fs.Uint64(ValidatorFeesTargetKey, uint64(genesis.LocalParams.ValidatorFeeConfig.Target), "Target number of validators") fs.Uint64(ValidatorFeesMinPriceKey, uint64(genesis.LocalParams.ValidatorFeeConfig.MinPrice), "Minimum validator price in nAVAX per second") fs.Uint64(ValidatorFeesExcessConversionConstantKey, uint64(genesis.LocalParams.ValidatorFeeConfig.ExcessConversionConstant), "Constant to convert validator excess price") diff --git a/genesis/genesis_fuji.go b/genesis/genesis_fuji.go index 82a8ffecaa3c..509396c5af8f 100644 --- a/genesis/genesis_fuji.go +++ b/genesis/genesis_fuji.go @@ -48,8 +48,8 @@ var ( MinPrice: 1, ExcessConversionConstant: 5_000, }, - ValidatorFeeCapacity: 20_000, ValidatorFeeConfig: validatorfee.Config{ + Capacity: 20_000, Target: 10_000, MinPrice: gas.Price(512 * units.NanoAvax), // ExcessConversionConstant = (Capacity - Target) * NumberOfSecondsPerDoubling / ln(2) diff --git a/genesis/genesis_local.go b/genesis/genesis_local.go index aefdbf2c25be..f40d866caa65 100644 --- a/genesis/genesis_local.go +++ b/genesis/genesis_local.go @@ -66,8 +66,8 @@ var ( MinPrice: 1, ExcessConversionConstant: 5_000, }, - ValidatorFeeCapacity: 20_000, ValidatorFeeConfig: validatorfee.Config{ + Capacity: 20_000, Target: 10_000, MinPrice: gas.Price(1 * units.NanoAvax), // ExcessConversionConstant = (Capacity - Target) * NumberOfSecondsPerDoubling / ln(2) diff --git a/genesis/genesis_mainnet.go b/genesis/genesis_mainnet.go index 2395d88d34b4..1927762cda8f 100644 --- a/genesis/genesis_mainnet.go +++ b/genesis/genesis_mainnet.go @@ -48,8 +48,8 @@ var ( MinPrice: 1, ExcessConversionConstant: 5_000, }, - ValidatorFeeCapacity: 20_000, ValidatorFeeConfig: validatorfee.Config{ + Capacity: 20_000, Target: 10_000, MinPrice: gas.Price(512 * units.NanoAvax), // ExcessConversionConstant = (Capacity - Target) * NumberOfSecondsPerDoubling / ln(2) diff --git a/genesis/params.go b/genesis/params.go index 43c2f1c1301c..c591c9ed67d8 100644 --- a/genesis/params.go +++ b/genesis/params.go @@ -38,11 +38,10 @@ type StakingConfig struct { } type TxFeeConfig struct { - CreateAssetTxFee uint64 `json:"createAssetTxFee"` - StaticFeeConfig txfee.StaticConfig `json:"staticFeeConfig"` - DynamicFeeConfig gas.Config `json:"dynamicFeeConfig"` - ValidatorFeeCapacity gas.Gas `json:"validatorFeeCapacity"` - ValidatorFeeConfig validatorfee.Config `json:"validatorFeeConfig"` + CreateAssetTxFee uint64 `json:"createAssetTxFee"` + StaticFeeConfig txfee.StaticConfig `json:"staticFeeConfig"` + DynamicFeeConfig gas.Config `json:"dynamicFeeConfig"` + ValidatorFeeConfig validatorfee.Config `json:"validatorFeeConfig"` } type Params struct { diff --git a/node/node.go b/node/node.go index 3eb2f9b18447..1fedf35eb97e 100644 --- a/node/node.go +++ b/node/node.go @@ -1217,7 +1217,6 @@ func (n *Node) initVMs() error { CreateAssetTxFee: n.Config.CreateAssetTxFee, StaticFeeConfig: n.Config.StaticFeeConfig, DynamicFeeConfig: n.Config.DynamicFeeConfig, - ValidatorFeeCapacity: n.Config.ValidatorFeeCapacity, ValidatorFeeConfig: n.Config.ValidatorFeeConfig, UptimePercentage: n.Config.UptimeRequirement, MinValidatorStake: n.Config.MinValidatorStake, diff --git a/vms/platformvm/config/config.go b/vms/platformvm/config/config.go index f8bda923455c..897f910a1380 100644 --- a/vms/platformvm/config/config.go +++ b/vms/platformvm/config/config.go @@ -42,8 +42,7 @@ type Config struct { DynamicFeeConfig gas.Config // ACP-77 validator fees are active after Etna - ValidatorFeeCapacity gas.Gas - ValidatorFeeConfig validatorfee.Config + ValidatorFeeConfig validatorfee.Config // Provides access to the uptime manager as a thread safe data structure UptimeLockedCalculator uptime.LockedCalculator diff --git a/vms/platformvm/validators/fee/fee.go b/vms/platformvm/validators/fee/fee.go index 23705d8b25a2..df466a70770f 100644 --- a/vms/platformvm/validators/fee/fee.go +++ b/vms/platformvm/validators/fee/fee.go @@ -13,6 +13,7 @@ import ( // Config contains all the static parameters of the dynamic fee mechanism. type Config struct { + Capacity gas.Gas `json:"capacity"` Target gas.Gas `json:"target"` MinPrice gas.Price `json:"minPrice"` ExcessConversionConstant gas.Gas `json:"excessConversionConstant"` From 915de36538a8dde567a46bf7d1f27608e7b7b310 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sun, 13 Oct 2024 23:17:05 -0400 Subject: [PATCH 7/9] Fix merge --- .../txs/executor/standard_tx_executor.go | 2 +- .../txs/executor/standard_tx_executor_test.go | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index 098051c0dab6..828917435f83 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -569,7 +569,7 @@ func (e *StandardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { } if vdr.Balance != 0 { // We are attempting to add an active validator - if gas.Gas(e.State.NumActiveSubnetOnlyValidators()) >= e.Backend.Config.ValidatorFeeCapacity { + if gas.Gas(e.State.NumActiveSubnetOnlyValidators()) >= e.Backend.Config.ValidatorFeeConfig.Capacity { return errMaxNumActiveValidators } diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index afdd3ec14940..f5eaf19a0a25 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -37,13 +37,15 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" "github.com/ava-labs/avalanchego/vms/platformvm/status" "github.com/ava-labs/avalanchego/vms/platformvm/txs" - "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee" "github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest" "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/platformvm/utxo/utxomock" "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" + + txfee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee" + validatorfee "github.com/ava-labs/avalanchego/vms/platformvm/validators/fee" ) // This tests that the math performed during TransformSubnetTx execution can @@ -2384,10 +2386,9 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { var ( ctx = snowtest.Context(t, constants.PlatformChainID) defaultConfig = &config.Config{ - DynamicFeeConfig: genesis.LocalParams.DynamicFeeConfig, - ValidatorFeeCapacity: genesis.LocalParams.ValidatorFeeCapacity, - ValidatorFeeConfig: genesis.LocalParams.ValidatorFeeConfig, - UpgradeConfig: upgradetest.GetConfig(upgradetest.Latest), + DynamicFeeConfig: genesis.LocalParams.DynamicFeeConfig, + ValidatorFeeConfig: genesis.LocalParams.ValidatorFeeConfig, + UpgradeConfig: upgradetest.GetConfig(upgradetest.Latest), } baseState = statetest.New(t, statetest.Config{ Upgrades: defaultConfig.UpgradeConfig, @@ -2501,19 +2502,23 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { { name: "invalid fee calculation", updateExecutor: func(e *StandardTxExecutor) error { - e.FeeCalculator = fee.NewStaticCalculator(e.Config.StaticFeeConfig) + e.FeeCalculator = txfee.NewStaticCalculator(e.Config.StaticFeeConfig) return nil }, - expectedErr: fee.ErrUnsupportedTx, + expectedErr: txfee.ErrUnsupportedTx, }, { name: "too many active validators", updateExecutor: func(e *StandardTxExecutor) error { e.Backend.Config = &config.Config{ - DynamicFeeConfig: genesis.LocalParams.DynamicFeeConfig, - ValidatorFeeCapacity: 0, - ValidatorFeeConfig: genesis.LocalParams.ValidatorFeeConfig, - UpgradeConfig: upgradetest.GetConfig(upgradetest.Latest), + DynamicFeeConfig: genesis.LocalParams.DynamicFeeConfig, + ValidatorFeeConfig: validatorfee.Config{ + Capacity: 0, + Target: genesis.LocalParams.ValidatorFeeConfig.Target, + MinPrice: genesis.LocalParams.ValidatorFeeConfig.MinPrice, + ExcessConversionConstant: genesis.LocalParams.ValidatorFeeConfig.ExcessConversionConstant, + }, + UpgradeConfig: upgradetest.GetConfig(upgradetest.Latest), } return nil }, @@ -2534,7 +2539,7 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { { name: "insufficient fee", updateExecutor: func(e *StandardTxExecutor) error { - e.FeeCalculator = fee.NewDynamicCalculator( + e.FeeCalculator = txfee.NewDynamicCalculator( e.Config.DynamicFeeConfig.Weights, 100*genesis.LocalParams.DynamicFeeConfig.MinPrice, ) From 96625ae9c5c7b1fc5df67e785fc4e7c554fe5ad3 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sun, 13 Oct 2024 23:27:41 -0400 Subject: [PATCH 8/9] Fix merge --- vms/platformvm/txs/executor/standard_tx_executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index 4068dca732ff..64ab3e5db8cf 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -772,7 +772,7 @@ func (e *StandardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVal } if tx.Balance != 0 { // We are attempting to add an active validator - if gas.Gas(e.State.NumActiveSubnetOnlyValidators()) >= e.Backend.Config.ValidatorFeeCapacity { + if gas.Gas(e.State.NumActiveSubnetOnlyValidators()) >= e.Backend.Config.ValidatorFeeConfig.Capacity { return errMaxNumActiveValidators } From e8c8b87fad3e82aee8a96047f89cbf183548655e Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sun, 13 Oct 2024 23:54:17 -0400 Subject: [PATCH 9/9] Add capacity check --- vms/platformvm/txs/executor/standard_tx_executor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index fcdfdfc01cb6..2d582efe4656 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -981,6 +981,10 @@ func (e *StandardTxExecutor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error // If the validator is currently inactive, we are activating it. if sov.EndAccumulatedFee == 0 { + if gas.Gas(e.State.NumActiveSubnetOnlyValidators()) >= e.Backend.Config.ValidatorFeeConfig.Capacity { + return errMaxNumActiveValidators + } + sov.EndAccumulatedFee = e.State.GetAccruedFees() } sov.EndAccumulatedFee, err = safemath.Add(sov.EndAccumulatedFee, tx.Balance)