Skip to content

Commit

Permalink
reintroduce ap3 check in tip
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur committed Feb 24, 2025
1 parent e82419f commit 950e83a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
10 changes: 6 additions & 4 deletions plugin/evm/atomic/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,12 @@ func (vm *VM) verifyTxAtTip(tx *atomic.Tx) error {
parentHeader := preferredBlock
var nextBaseFee *big.Int
timestamp := uint64(vm.clock.Time().Unix())
nextBaseFee, err = header.EstimateNextBaseFee(chainConfig, parentHeader, timestamp)
if err != nil {
// Return extremely detailed error since CalcBaseFee should never encounter an issue here
return fmt.Errorf("failed to calculate base fee with parent timestamp (%d), parent ExtraData: (0x%x), and current timestamp (%d): %w", parentHeader.Time, parentHeader.Extra, timestamp, err)
if chainConfig.IsApricotPhase3(timestamp) {
nextBaseFee, err = header.EstimateNextBaseFee(chainConfig, parentHeader, timestamp)
if err != nil {
// Return extremely detailed error since CalcBaseFee should never encounter an issue here
return fmt.Errorf("failed to calculate base fee with parent timestamp (%d), parent ExtraData: (0x%x), and current timestamp (%d): %w", parentHeader.Time, parentHeader.Extra, timestamp, err)
}
}

// We don’t need to revert the state here in case verifyTx errors, because
Expand Down
3 changes: 1 addition & 2 deletions plugin/evm/atomic/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/ava-labs/avalanchego/vms/components/chain"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
accountKeystore "github.com/ava-labs/coreth/accounts/keystore"
"github.com/ava-labs/coreth/consensus/dummy"
"github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
Expand Down Expand Up @@ -1580,7 +1579,7 @@ func TestBuildApricotPhase4Block(t *testing.T) {
if ethBlk.ExtDataGasUsed() == nil || ethBlk.ExtDataGasUsed().Cmp(common.Big0) != 0 {
t.Fatalf("expected extDataGasUsed to be 0 but got %d", ethBlk.ExtDataGasUsed())
}
minRequiredTip, err = dummy.MinRequiredTip(vm.Ethereum().BlockChain().Config(), ethBlk.Header())
minRequiredTip, err = header.EstimateRequiredTip(vm.Ethereum().BlockChain().Config(), ethBlk.Header())
if err != nil {
t.Fatal(err)
}
Expand Down
16 changes: 9 additions & 7 deletions plugin/evm/testutils/test_syncervm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/api/metrics"
avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic"
avalanchedatabase "github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/prefixdb"
Expand Down Expand Up @@ -42,7 +43,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
)

Expand Down Expand Up @@ -116,12 +116,6 @@ func StateSyncFromScratchExceedParentTest(t *testing.T, testSetup *SyncTestSetup

func StateSyncToggleEnabledToDisabledTest(t *testing.T, testSetup *SyncTestSetup) {
rand.Seed(1)
// Hack: registering metrics uses global variables, so we need to disable metrics here so that we can initialize the VM twice.
metrics.Enabled = false
defer func() {
metrics.Enabled = true
}()

var lock sync.Mutex
reqCount := 0
test := SyncTestParams{
Expand Down Expand Up @@ -167,6 +161,7 @@ func StateSyncToggleEnabledToDisabledTest(t *testing.T, testSetup *SyncTestSetup
go testSyncVMSetup.serverVM.VM.AppRequest(ctx, nodeID, requestID, time.Now().Add(1*time.Second), request)
return nil
}
resetMetrics(testSyncVMSetup.syncerVM.SnowCtx)
stateSyncDisabledConfigJSON := `{"state-sync-enabled":false}`
if err := syncDisabledVM.Initialize(
context.Background(),
Expand Down Expand Up @@ -231,6 +226,7 @@ func StateSyncToggleEnabledToDisabledTest(t *testing.T, testSetup *SyncTestSetup
`{"state-sync-enabled":true, "state-sync-min-blocks":%d}`,
test.StateSyncMinBlocks,
)
resetMetrics(testSyncVMSetup.syncerVM.SnowCtx)
if err := syncReEnabledVM.Initialize(
context.Background(),
testSyncVMSetup.syncerVM.SnowCtx,
Expand Down Expand Up @@ -681,3 +677,9 @@ func assertSyncPerformedHeights(t *testing.T, db ethdb.Iteratee, expected map[ui
require.NoError(t, it.Error())
require.Equal(t, expected, found)
}

// resetMetrics resets the vm avalanchego metrics, and allows
// for the VM to be re-initialized in tests.
func resetMetrics(snowCtx *snow.Context) {
snowCtx.Metrics = metrics.NewPrefixGatherer()
}
1 change: 1 addition & 0 deletions warp/handlers/signature_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/coreth/plugin/evm/message"
messagetest "github.com/ava-labs/coreth/plugin/evm/message/testutils"
"github.com/ava-labs/coreth/plugin/evm/testutils"
"github.com/ava-labs/coreth/utils"
"github.com/ava-labs/coreth/warp"
"github.com/ava-labs/coreth/warp/warptest"
Expand Down

0 comments on commit 950e83a

Please sign in to comment.