Skip to content

Commit

Permalink
Pass VM configs rather than factories (ava-labs#2645)
Browse files Browse the repository at this point in the history
Co-authored-by: Chloe <[email protected]>
  • Loading branch information
StephenButtolph and coffeeavax authored Feb 23, 2023
1 parent a7b20ed commit 1f8a494
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 130 deletions.
11 changes: 7 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ import (
"github.com/ava-labs/avalanchego/vms/avm"
"github.com/ava-labs/avalanchego/vms/nftfx"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/config"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/propertyfx"
"github.com/ava-labs/avalanchego/vms/registry"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

ipcsapi "github.com/ava-labs/avalanchego/api/ipcs"
avmconfig "github.com/ava-labs/avalanchego/vms/avm/config"
platformconfig "github.com/ava-labs/avalanchego/vms/platformvm/config"
)

var (
Expand Down Expand Up @@ -763,7 +764,7 @@ func (n *Node) initVMs() error {
errs := wrappers.Errs{}
errs.Add(
vmRegisterer.Register(context.TODO(), constants.PlatformVMID, &platformvm.Factory{
Config: config.Config{
Config: platformconfig.Config{
Chains: n.chainManager,
Validators: vdrs,
UptimeLockedCalculator: n.uptimeCalculator,
Expand Down Expand Up @@ -794,8 +795,10 @@ func (n *Node) initVMs() error {
},
}),
vmRegisterer.Register(context.TODO(), constants.AVMID, &avm.Factory{
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
Config: avmconfig.Config{
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
},
}),
vmRegisterer.Register(context.TODO(), constants.EVMID, &coreth.Factory{}),
n.Config.VMManager.RegisterFactory(context.TODO(), secp256k1fx.ID, &secp256k1fx.Factory{}),
Expand Down
13 changes: 13 additions & 0 deletions vms/avm/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package config

// Struct collecting all the foundational parameters of the AVM
type Config struct {
// Fee that is burned by every non-asset creating transaction
TxFee uint64

// Fee that must be burned by every asset creating transaction
CreateAssetTxFee uint64
}
6 changes: 3 additions & 3 deletions vms/avm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package avm
import (
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms"
"github.com/ava-labs/avalanchego/vms/avm/config"
)

var _ vms.Factory = (*Factory)(nil)

type Factory struct {
TxFee uint64
CreateAssetTxFee uint64
config.Config
}

func (f *Factory) New(*snow.Context) (interface{}, error) {
return &VM{Factory: *f}, nil
return &VM{Config: f.Config}, nil
}
3 changes: 2 additions & 1 deletion vms/avm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/avm/blocks"
"github.com/ava-labs/avalanchego/vms/avm/config"
"github.com/ava-labs/avalanchego/vms/avm/states"
"github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/components/avax"
Expand Down Expand Up @@ -73,7 +74,7 @@ var (
type VM struct {
common.AppHandler

Factory
config.Config
metrics
avax.AddressManager
avax.AtomicUTXOManager
Expand Down
3 changes: 2 additions & 1 deletion vms/avm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ava-labs/avalanchego/utils/json"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/avm/config"
"github.com/ava-labs/avalanchego/vms/avm/fxs"
"github.com/ava-labs/avalanchego/vms/avm/states"
"github.com/ava-labs/avalanchego/vms/avm/txs"
Expand Down Expand Up @@ -303,7 +304,7 @@ func GenesisVMWithArgs(tb testing.TB, additionalFxs []*common.Fx, args *BuildGen
ctx.Keystore = userKeystore.NewBlockchainKeyStore(ctx.ChainID)

issuer := make(chan common.Message, 1)
vm := &VM{Factory: Factory{
vm := &VM{Config: config.Config{
TxFee: testTxFee,
CreateAssetTxFee: testTxFee,
}}
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ type Factory struct {

// New returns a new instance of the Platform Chain
func (f *Factory) New(*snow.Context) (interface{}, error) {
return &VM{Factory: *f}, nil
return &VM{Config: f.Config}, nil
}
3 changes: 2 additions & 1 deletion vms/platformvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/platformvm/api"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
"github.com/ava-labs/avalanchego/vms/platformvm/config"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/metrics"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
Expand Down Expand Up @@ -71,7 +72,7 @@ var (
)

type VM struct {
Factory
config.Config
blockbuilder.Builder

metrics metrics.Metrics
Expand Down
18 changes: 8 additions & 10 deletions vms/platformvm/vm_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,14 @@ func TestUnverifiedParentPanicRegression(t *testing.T) {
vdrs := validators.NewManager()
primaryVdrs := validators.NewSet()
_ = vdrs.Add(constants.PrimaryNetworkID, primaryVdrs)
vm := &VM{Factory: Factory{
Config: config.Config{
Chains: chains.TestManager,
Validators: vdrs,
UptimeLockedCalculator: uptime.NewLockedCalculator(),
MinStakeDuration: defaultMinStakingDuration,
MaxStakeDuration: defaultMaxStakingDuration,
RewardConfig: defaultRewardConfig,
BanffTime: banffForkTime,
},
vm := &VM{Config: config.Config{
Chains: chains.TestManager,
Validators: vdrs,
UptimeLockedCalculator: uptime.NewLockedCalculator(),
MinStakeDuration: defaultMinStakingDuration,
MaxStakeDuration: defaultMaxStakingDuration,
RewardConfig: defaultRewardConfig,
BanffTime: banffForkTime,
}}

ctx := defaultContext()
Expand Down
Loading

0 comments on commit 1f8a494

Please sign in to comment.