Skip to content

Commit

Permalink
Merge branch 'master' into qdm12/libevm-master-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 28, 2025
2 parents 0097caa + ebc14ef commit 210fbee
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 176 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v5
with:
go-version: "~1.22.8"
go-version-file: "go.mod"
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v5
with:
go-version: "~1.22.8"
go-version-file: "go.mod"
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v5
with:
go-version: "~1.22.8"
go-version-file: "go.mod"
- name: Run e2e tests
run: E2E_SERIAL=1 ./scripts/tests.e2e.sh
shell: bash
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/sync-subnet-evm-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: "~1.22.8"
go-version-file: "go.mod"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.22.8-bullseye AS builder
FROM golang:1.23.6-bullseye AS builder

ARG AVALANCHE_VERSION

Expand All @@ -17,7 +17,7 @@ WORKDIR $GOPATH/src/github.com/ava-labs/avalanchego
RUN go mod download
# Replace the coreth dependency
RUN go mod edit -replace github.com/ava-labs/coreth=../coreth
RUN go mod download && go mod tidy -compat=1.22
RUN go mod download && go mod tidy -compat=1.23

# Build the AvalancheGo binary with local version of coreth.
RUN ./scripts/build_avalanche.sh
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ func golangBindings(t *testing.T, overload bool) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.22")
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.23")
tidier.Dir = pkg
if out, err := tidier.CombinedOutput(); err != nil {
t.Fatalf("failed to tidy Go module file: %v\n%s", err, out)
Expand Down
17 changes: 10 additions & 7 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
var (
allowedFutureBlockTime = 10 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks

ErrInsufficientBlockGas = errors.New("insufficient gas to cover the block cost")

errInvalidBlockTime = errors.New("timestamp less than parent's")
errUnclesUnsupported = errors.New("uncles unsupported")
errExtDataGasUsedNil = errors.New("extDataGasUsed is nil")
Expand Down Expand Up @@ -319,15 +321,16 @@ func (eng *DummyEngine) verifyBlockFee(
// set by the base fee of this block.
blockGas := new(big.Int).Div(totalBlockFee, baseFee)

// Require that the amount of gas purchased by the effective tips within the block, [blockGas],
// covers at least [requiredBlockGasCost].
// Require that the amount of gas purchased by the effective tips within the
// block covers at least `requiredBlockGasCost`.
//
// NOTE: To determine the [requiredBlockFee], multiply [requiredBlockGasCost]
// by [baseFee].
// NOTE: To determine the required block fee, multiply
// `requiredBlockGasCost` by `baseFee`.
if blockGas.Cmp(requiredBlockGasCost) < 0 {
return fmt.Errorf(
"insufficient gas (%d) to cover the block cost (%d) at base fee (%d) (total block fee: %d)",
blockGas, requiredBlockGasCost, baseFee, totalBlockFee,
return fmt.Errorf("%w: expected %d but got %d",
ErrInsufficientBlockGas,
requiredBlockGasCost,
blockGas,
)
}
return nil
Expand Down
74 changes: 24 additions & 50 deletions core/test_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package core
import (
"fmt"
"math/big"
"strings"
"testing"
"time"

Expand All @@ -15,6 +14,7 @@ import (
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/plugin/evm/upgrade/ap4"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/crypto"
"github.com/ava-labs/libevm/ethdb"
Expand Down Expand Up @@ -1284,6 +1284,7 @@ func TestReprocessAcceptBlockIdenticalStateRoot(t *testing.T, create func(db eth

func TestGenerateChainInvalidBlockFee(t *testing.T, create func(db ethdb.Database, gspec *Genesis, lastAcceptedHash common.Hash) (*BlockChain, error)) {
var (
require = require.New(t)
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
Expand All @@ -1299,14 +1300,12 @@ func TestGenerateChainInvalidBlockFee(t *testing.T, create func(db ethdb.Databas
}

blockchain, err := create(chainDB, gspec, common.Hash{})
if err != nil {
t.Fatal(err)
}
defer blockchain.Stop()
require.NoError(err)
t.Cleanup(blockchain.Stop)

// This call generates a chain of 3 blocks.
signer := types.LatestSigner(params.TestChainConfig)
_, _, _, err = GenerateChainWithGenesis(gspec, blockchain.engine, 3, 0, func(i int, gen *BlockGen) {
_, _, _, err = GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainID,
Nonce: gen.TxNonce(addr1),
Expand All @@ -1318,21 +1317,15 @@ func TestGenerateChainInvalidBlockFee(t *testing.T, create func(db ethdb.Databas
})

signedTx, err := types.SignTx(tx, signer, key1)
if err != nil {
t.Fatal(err)
}
require.NoError(err)
gen.AddTx(signedTx)
})
if err == nil {
t.Fatal("should not have been able to build a block because of insufficient block fee")
}
if !strings.Contains(err.Error(), "insufficient gas (0) to cover the block cost (400000)") {
t.Fatalf("should have gotten insufficient block fee error but got %v instead", err)
}
require.ErrorIs(err, dummy.ErrInsufficientBlockGas)
}

func TestInsertChainInvalidBlockFee(t *testing.T, create func(db ethdb.Database, gspec *Genesis, lastAcceptedHash common.Hash) (*BlockChain, error)) {
var (
require = require.New(t)
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
Expand All @@ -1348,15 +1341,13 @@ func TestInsertChainInvalidBlockFee(t *testing.T, create func(db ethdb.Database,
}

blockchain, err := create(chainDB, gspec, common.Hash{})
if err != nil {
t.Fatal(err)
}
defer blockchain.Stop()
require.NoError(err)
t.Cleanup(blockchain.Stop)

// This call generates a chain of 3 blocks.
signer := types.LatestSigner(params.TestChainConfig)
eng := dummy.NewFakerWithMode(TestCallbacks, dummy.Mode{ModeSkipBlockFee: true, ModeSkipCoinbase: true})
_, chain, _, err := GenerateChainWithGenesis(gspec, eng, 3, 0, func(i int, gen *BlockGen) {
_, chain, _, err := GenerateChainWithGenesis(gspec, eng, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainID,
Nonce: gen.TxNonce(addr1),
Expand All @@ -1368,25 +1359,17 @@ func TestInsertChainInvalidBlockFee(t *testing.T, create func(db ethdb.Database,
})

signedTx, err := types.SignTx(tx, signer, key1)
if err != nil {
t.Fatal(err)
}
require.NoError(err)
gen.AddTx(signedTx)
})
if err != nil {
t.Fatal(err)
}
require.NoError(err)
_, err = blockchain.InsertChain(chain)
if err == nil {
t.Fatal("should not have been able to build a block because of insufficient block fee")
}
if !strings.Contains(err.Error(), "insufficient gas (0) to cover the block cost (400000)") {
t.Fatalf("should have gotten insufficient block fee error but got %v instead", err)
}
require.ErrorIs(err, dummy.ErrInsufficientBlockGas)
}

func TestInsertChainValidBlockFee(t *testing.T, create func(db ethdb.Database, gspec *Genesis, lastAcceptedHash common.Hash) (*BlockChain, error)) {
var (
require = require.New(t)
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
Expand All @@ -1404,16 +1387,14 @@ func TestInsertChainValidBlockFee(t *testing.T, create func(db ethdb.Database, g
}

blockchain, err := create(chainDB, gspec, common.Hash{})
if err != nil {
t.Fatal(err)
}
defer blockchain.Stop()
require.NoError(err)
t.Cleanup(blockchain.Stop)

// This call generates a chain of 3 blocks.
signer := types.LatestSigner(params.TestChainConfig)
tip := big.NewInt(50000 * params.GWei)
transfer := big.NewInt(10000)
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 0, func(i int, gen *BlockGen) {
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
feeCap := new(big.Int).Add(gen.BaseFee(), tip)
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainID,
Expand All @@ -1427,22 +1408,15 @@ func TestInsertChainValidBlockFee(t *testing.T, create func(db ethdb.Database, g
})

signedTx, err := types.SignTx(tx, signer, key1)
if err != nil {
t.Fatal(err)
}
require.NoError(err)
gen.AddTx(signedTx)
})
if err != nil {
t.Fatal(err)
}
require.NoError(err)

// Insert three blocks into the chain and accept only the first block.
if _, err := blockchain.InsertChain(chain); err != nil {
t.Fatal(err)
}
if err := blockchain.Accept(chain[0]); err != nil {
t.Fatal(err)
}
_, err = blockchain.InsertChain(chain)
require.NoError(err)
require.NoError(blockchain.Accept(chain[0]))
blockchain.DrainAcceptorQueue()

// check the state of the last accepted block
Expand All @@ -1455,7 +1429,7 @@ func TestInsertChainValidBlockFee(t *testing.T, create func(db ethdb.Database, g
transfer := uint256.MustFromBig(transfer)
genesisBalance := uint256.MustFromBig(genesisBalance)
expectedBalance1 := new(uint256.Int).Sub(genesisBalance, transfer)
baseFee := big.NewInt(225 * params.GWei)
baseFee := chain[0].BaseFee()
feeSpend := new(big.Int).Mul(new(big.Int).Add(baseFee, tip), new(big.Int).SetUint64(params.TxGas))
expectedBalance1.Sub(expectedBalance1, uint256.MustFromBig(feeSpend))
if balance1.Cmp(expectedBalance1) != 0 {
Expand Down
9 changes: 8 additions & 1 deletion eth/gasprice/fee_info_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ func (f *feeInfoProvider) addHeader(ctx context.Context, header *types.Header) (
timestamp: header.Time,
baseFee: header.BaseFee,
}

totalGasUsed := new(big.Int).SetUint64(header.GasUsed)
if used := types.GetHeaderExtra(header).ExtDataGasUsed; used != nil {
totalGasUsed.Add(totalGasUsed, used)
}
minGasUsed := new(big.Int).SetUint64(f.minGasUsed)

// Don't bias the estimate with blocks containing a limited number of transactions paying to
// expedite block production.
var err error
if f.minGasUsed <= header.GasUsed {
if minGasUsed.Cmp(totalGasUsed) <= 0 {
// Compute minimum required tip to be included in previous block
//
// NOTE: Using this approach, we will never recommend that the caller
Expand Down
25 changes: 19 additions & 6 deletions eth/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestSuggestTipCapEmptyExtDataGasUsage(t *testing.T) {
numBlocks: 3,
extDataGasUsage: nil,
genBlock: testGenBlock(t, 55, 370),
expectedTip: big.NewInt(5_713_963_963),
expectedTip: big.NewInt(5_713_963_964),
}, defaultOracleConfig())
}

Expand All @@ -261,7 +261,7 @@ func TestSuggestTipCapSimple(t *testing.T) {
numBlocks: 3,
extDataGasUsage: common.Big0,
genBlock: testGenBlock(t, 55, 370),
expectedTip: big.NewInt(5_713_963_963),
expectedTip: big.NewInt(5_713_963_964),
}, defaultOracleConfig())
}

Expand Down Expand Up @@ -317,7 +317,7 @@ func TestSuggestTipCapSmallTips(t *testing.T) {
}
},
// NOTE: small tips do not bias estimate
expectedTip: big.NewInt(5_713_963_963),
expectedTip: big.NewInt(5_713_963_964),
}, defaultOracleConfig())
}

Expand All @@ -327,7 +327,7 @@ func TestSuggestTipCapExtDataUsage(t *testing.T) {
numBlocks: 3,
extDataGasUsage: big.NewInt(10_000),
genBlock: testGenBlock(t, 55, 370),
expectedTip: big.NewInt(5_706_726_649),
expectedTip: big.NewInt(5_706_726_650),
}, defaultOracleConfig())
}

Expand Down Expand Up @@ -383,7 +383,7 @@ func TestSuggestTipCapMaxBlocksLookback(t *testing.T) {
numBlocks: 20,
extDataGasUsage: common.Big0,
genBlock: testGenBlock(t, 550, 370),
expectedTip: big.NewInt(51_565_264_256),
expectedTip: big.NewInt(51_565_264_257),
}, defaultOracleConfig())
}

Expand All @@ -393,6 +393,19 @@ func TestSuggestTipCapMaxBlocksSecondsLookback(t *testing.T) {
numBlocks: 20,
extDataGasUsage: big.NewInt(1),
genBlock: testGenBlock(t, 550, 370),
expectedTip: big.NewInt(92_212_529_423),
expectedTip: big.NewInt(92_212_529_424),
}, timeCrunchOracleConfig())
}

func TestSuggestTipCapIncludesExtraDataGas(t *testing.T) {
applyGasPriceTest(t, suggestTipCapTest{
chainConfig: params.TestChainConfig,
numBlocks: 20,
extDataGasUsage: DefaultMinGasUsed,
// The tip on the transaction is very large to pay the block gas cost.
genBlock: testGenBlock(t, 100_000, 1),
// The actual tip doesn't matter, we just want to ensure that the tip is
// non-zero when almost all the gas is coming from the extDataGasUsage.
expectedTip: big.NewInt(83_603_561_239),
}, timeCrunchOracleConfig())
}
13 changes: 7 additions & 6 deletions plugin/evm/atomic/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,16 @@ func CalculateDynamicFee(cost uint64, baseFee *big.Int) (uint64, error) {
if baseFee == nil {
return 0, errNilBaseFee
}
bigCost := new(big.Int).SetUint64(cost)
fee := new(big.Int).Mul(bigCost, baseFee)
feeToRoundUp := new(big.Int).Add(fee, x2cRateMinus1.ToBig())
feeInNAVAX := new(big.Int).Div(feeToRoundUp, X2CRate.ToBig())
if !feeInNAVAX.IsUint64() {
// fee = (cost * baseFee + [X2CRate] - 1) / [X2CRate]
fee := new(big.Int).SetUint64(cost)
fee.Mul(fee, baseFee)
fee.Add(fee, x2cRateMinus1.ToBig())
fee.Div(fee, X2CRate.ToBig())
if !fee.IsUint64() {
// the fee is more than can fit in a uint64
return 0, errFeeOverflow
}
return feeInNAVAX.Uint64(), nil
return fee.Uint64(), nil
}

func calcBytesCost(len int) uint64 {
Expand Down
Loading

0 comments on commit 210fbee

Please sign in to comment.