Skip to content

Commit

Permalink
Dynamic Fees - Add E Upgrade boilerplate (#2597)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Buttolph <[email protected]>
  • Loading branch information
abi87 and StephenButtolph authored Mar 18, 2024
1 parent 6a3661b commit 6249bab
Show file tree
Hide file tree
Showing 23 changed files with 404 additions and 332 deletions.
3 changes: 3 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ func (n *Node) initVMs() error {
}

// Register the VMs that Avalanche supports
eUpgradeTime := version.GetEUpgradeTime(n.Config.NetworkID)
err := utils.Err(
n.VMManager.RegisterFactory(context.TODO(), constants.PlatformVMID, &platformvm.Factory{
Config: platformconfig.Config{
Expand Down Expand Up @@ -1153,13 +1154,15 @@ func (n *Node) initVMs() error {
BanffTime: version.GetBanffTime(n.Config.NetworkID),
CortinaTime: version.GetCortinaTime(n.Config.NetworkID),
DurangoTime: version.GetDurangoTime(n.Config.NetworkID),
EUpgradeTime: eUpgradeTime,
UseCurrentHeight: n.Config.UseCurrentHeight,
},
}),
n.VMManager.RegisterFactory(context.TODO(), constants.AVMID, &avm.Factory{
Config: avmconfig.Config{
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
EUpgradeTime: eUpgradeTime,
},
}),
n.VMManager.RegisterFactory(context.TODO(), constants.EVMID, &coreth.Factory{}),
Expand Down
12 changes: 12 additions & 0 deletions version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ var (
constants.MainnetID: time.Date(2024, time.March, 6, 16, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(2024, time.February, 13, 16, 0, 0, 0, time.UTC),
}

EUpgradeTimes = map[uint32]time.Time{
constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
constants.FujiID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
}
)

func init() {
Expand Down Expand Up @@ -240,6 +245,13 @@ func GetDurangoTime(networkID uint32) time.Time {
return DefaultUpgradeTime
}

func GetEUpgradeTime(networkID uint32) time.Time {
if upgradeTime, exists := EUpgradeTimes[networkID]; exists {
return upgradeTime
}
return DefaultUpgradeTime
}

func GetCompatibility(networkID uint32) Compatibility {
return NewCompatibility(
CurrentApp,
Expand Down
99 changes: 48 additions & 51 deletions vms/avm/block/executor/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/vms/avm/block"
"github.com/ava-labs/avalanchego/vms/avm/config"
"github.com/ava-labs/avalanchego/vms/avm/metrics"
"github.com/ava-labs/avalanchego/vms/avm/state"
"github.com/ava-labs/avalanchego/vms/avm/txs"
Expand All @@ -45,6 +46,7 @@ func TestBlockVerify(t *testing.T) {
b := &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{},
},
}
Expand All @@ -62,8 +64,10 @@ func TestBlockVerify(t *testing.T) {
mockBlock.EXPECT().ID().Return(ids.Empty).AnyTimes()
mockBlock.EXPECT().MerkleRoot().Return(ids.GenerateTestID()).AnyTimes()
return &Block{
Block: mockBlock,
manager: &manager{},
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
},
}
},
expectedErr: ErrUnexpectedMerkleRoot,
Expand All @@ -82,7 +86,8 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
clk: clk,
backend: defaultTestBackend(false, nil),
clk: clk,
},
}
},
Expand All @@ -99,6 +104,7 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{},
clk: &mockable.Clock{},
},
Expand All @@ -125,6 +131,7 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
blkIDToState: map[ids.ID]*blockState{},
Expand Down Expand Up @@ -157,6 +164,7 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
state: mockState,
blkIDToState: map[ids.ID]*blockState{},
clk: &mockable.Clock{},
Expand Down Expand Up @@ -193,6 +201,7 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
state: mockState,
blkIDToState: map[ids.ID]*blockState{},
clk: &mockable.Clock{},
Expand Down Expand Up @@ -232,6 +241,7 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{
parentID: {
onAcceptState: mockParentState,
Expand Down Expand Up @@ -279,6 +289,7 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
blkIDToState: map[ids.ID]*blockState{
Expand Down Expand Up @@ -331,7 +342,7 @@ func TestBlockVerify(t *testing.T) {
manager: &manager{
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
backend: &executor.Backend{},
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{
parentID: {
onAcceptState: mockParentState,
Expand Down Expand Up @@ -409,7 +420,7 @@ func TestBlockVerify(t *testing.T) {
manager: &manager{
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
backend: &executor.Backend{},
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{
parentID: {
onAcceptState: mockParentState,
Expand Down Expand Up @@ -467,7 +478,7 @@ func TestBlockVerify(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: &executor.Backend{},
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{
parentID: {
onAcceptState: mockParentState,
Expand Down Expand Up @@ -519,7 +530,7 @@ func TestBlockVerify(t *testing.T) {
manager: &manager{
mempool: mockMempool,
metrics: metrics.NewMockMetrics(ctrl),
backend: &executor.Backend{},
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{
parentID: {
onAcceptState: mockParentState,
Expand Down Expand Up @@ -591,13 +602,9 @@ func TestBlockAccept(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
backend: &executor.Backend{
Ctx: &snow.Context{
Log: logging.NoLog{},
},
},
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{},
},
}
Expand Down Expand Up @@ -627,11 +634,7 @@ func TestBlockAccept(t *testing.T) {
manager: &manager{
state: mockManagerState,
mempool: mempool,
backend: &executor.Backend{
Ctx: &snow.Context{
Log: logging.NoLog{},
},
},
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{
blockID: {
onAcceptState: mockOnAcceptState,
Expand Down Expand Up @@ -670,12 +673,7 @@ func TestBlockAccept(t *testing.T) {
manager: &manager{
state: mockManagerState,
mempool: mempool,
backend: &executor.Backend{
Ctx: &snow.Context{
SharedMemory: mockSharedMemory,
Log: logging.NoLog{},
},
},
backend: defaultTestBackend(false, mockSharedMemory),
blkIDToState: map[ids.ID]*blockState{
blockID: {
onAcceptState: mockOnAcceptState,
Expand Down Expand Up @@ -718,12 +716,7 @@ func TestBlockAccept(t *testing.T) {
state: mockManagerState,
mempool: mempool,
metrics: metrics,
backend: &executor.Backend{
Ctx: &snow.Context{
SharedMemory: mockSharedMemory,
Log: logging.NoLog{},
},
},
backend: defaultTestBackend(false, mockSharedMemory),
blkIDToState: map[ids.ID]*blockState{
blockID: {
onAcceptState: mockOnAcceptState,
Expand Down Expand Up @@ -769,12 +762,7 @@ func TestBlockAccept(t *testing.T) {
state: mockManagerState,
mempool: mempool,
metrics: metrics,
backend: &executor.Backend{
Ctx: &snow.Context{
SharedMemory: mockSharedMemory,
Log: logging.NoLog{},
},
},
backend: defaultTestBackend(false, mockSharedMemory),
blkIDToState: map[ids.ID]*blockState{
blockID: {
onAcceptState: mockOnAcceptState,
Expand Down Expand Up @@ -869,13 +857,8 @@ func TestBlockReject(t *testing.T) {
lastAccepted: lastAcceptedID,
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
backend: &executor.Backend{
Bootstrapped: true,
Ctx: &snow.Context{
Log: logging.NoLog{},
},
},
state: mockState,
backend: defaultTestBackend(true, nil),
state: mockState,
blkIDToState: map[ids.ID]*blockState{
blockID: {},
},
Expand Down Expand Up @@ -927,13 +910,8 @@ func TestBlockReject(t *testing.T) {
lastAccepted: lastAcceptedID,
mempool: mempool,
metrics: metrics.NewMockMetrics(ctrl),
backend: &executor.Backend{
Bootstrapped: true,
Ctx: &snow.Context{
Log: logging.NoLog{},
},
},
state: mockState,
backend: defaultTestBackend(true, nil),
state: mockState,
blkIDToState: map[ids.ID]*blockState{
blockID: {},
},
Expand Down Expand Up @@ -981,6 +959,7 @@ func TestBlockStatus(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
lastAccepted: blockID,
},
}
Expand All @@ -996,6 +975,7 @@ func TestBlockStatus(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{
blockID: {},
},
Expand All @@ -1017,6 +997,7 @@ func TestBlockStatus(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{},
state: mockState,
},
Expand All @@ -1037,6 +1018,7 @@ func TestBlockStatus(t *testing.T) {
return &Block{
Block: mockBlock,
manager: &manager{
backend: defaultTestBackend(false, nil),
blkIDToState: map[ids.ID]*blockState{},
state: mockState,
},
Expand All @@ -1055,3 +1037,18 @@ func TestBlockStatus(t *testing.T) {
})
}
}

func defaultTestBackend(bootstrapped bool, sharedMemory atomic.SharedMemory) *executor.Backend {
return &executor.Backend{
Bootstrapped: bootstrapped,
Ctx: &snow.Context{
SharedMemory: sharedMemory,
Log: logging.NoLog{},
},
Config: &config.Config{
EUpgradeTime: mockable.MaxTime,
TxFee: 0,
CreateAssetTxFee: 0,
},
}
}
19 changes: 5 additions & 14 deletions vms/avm/block/executor/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/ava-labs/avalanchego/vms/avm/block"
"github.com/ava-labs/avalanchego/vms/avm/state"
"github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/avm/txs/executor"
)

var (
Expand Down Expand Up @@ -123,7 +122,7 @@ func TestManagerVerifyTx(t *testing.T) {
},
managerF: func(*gomock.Controller) *manager {
return &manager{
backend: &executor.Backend{},
backend: defaultTestBackend(false, nil),
}
},
expectedErr: ErrChainNotSynced,
Expand All @@ -139,9 +138,7 @@ func TestManagerVerifyTx(t *testing.T) {
},
managerF: func(*gomock.Controller) *manager {
return &manager{
backend: &executor.Backend{
Bootstrapped: true,
},
backend: defaultTestBackend(true, nil),
}
},
expectedErr: errTestSyntacticVerifyFail,
Expand All @@ -167,9 +164,7 @@ func TestManagerVerifyTx(t *testing.T) {
state.EXPECT().GetTimestamp().Return(time.Time{})

return &manager{
backend: &executor.Backend{
Bootstrapped: true,
},
backend: defaultTestBackend(true, nil),
state: state,
lastAccepted: lastAcceptedID,
}
Expand Down Expand Up @@ -199,9 +194,7 @@ func TestManagerVerifyTx(t *testing.T) {
state.EXPECT().GetTimestamp().Return(time.Time{})

return &manager{
backend: &executor.Backend{
Bootstrapped: true,
},
backend: defaultTestBackend(true, nil),
state: state,
lastAccepted: lastAcceptedID,
}
Expand Down Expand Up @@ -231,9 +224,7 @@ func TestManagerVerifyTx(t *testing.T) {
state.EXPECT().GetTimestamp().Return(time.Time{})

return &manager{
backend: &executor.Backend{
Bootstrapped: true,
},
backend: defaultTestBackend(true, nil),
state: state,
lastAccepted: lastAcceptedID,
}
Expand Down
Loading

0 comments on commit 6249bab

Please sign in to comment.