Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ACP-176 #815

Merged
merged 65 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
f620f6c
Move predicate header parsing
StephenButtolph Feb 20, 2025
9291295
nit
StephenButtolph Feb 20, 2025
726a0a3
nit
StephenButtolph Feb 20, 2025
64f8593
add comment
StephenButtolph Feb 21, 2025
5bb3f1c
Merge branch 'master' into move-predicate-header-parsing
StephenButtolph Feb 21, 2025
1f39026
Merge branch 'master' into move-predicate-header-parsing
StephenButtolph Feb 24, 2025
0a53c10
Merge branch 'master' into move-predicate-header-parsing
StephenButtolph Feb 24, 2025
4125251
Implement ACP-176
StephenButtolph Feb 24, 2025
9155b20
round up
StephenButtolph Feb 24, 2025
32ccf84
merged
StephenButtolph Feb 25, 2025
c63446c
merged
StephenButtolph Feb 25, 2025
0fd6894
CI passes?
StephenButtolph Feb 25, 2025
cb412d4
update min fee
StephenButtolph Feb 25, 2025
be3b80d
try to improve error
StephenButtolph Feb 25, 2025
e2cdc4a
add min price
StephenButtolph Feb 25, 2025
60abba7
debugging...
StephenButtolph Feb 25, 2025
23d665c
debugging...
StephenButtolph Feb 25, 2025
c7b3f89
debugging...
StephenButtolph Feb 25, 2025
2e8621d
wip
StephenButtolph Feb 25, 2025
489306b
wip
StephenButtolph Feb 25, 2025
21d6169
reduce diff
StephenButtolph Feb 25, 2025
cc39094
finally fix CI
StephenButtolph Feb 25, 2025
ba095bc
reduce diff
StephenButtolph Feb 25, 2025
4a749c9
reduce diff
StephenButtolph Feb 26, 2025
e856e2b
nit
StephenButtolph Feb 26, 2025
c7d9bb2
Merge branch 'master' into acp-176-spike
StephenButtolph Feb 26, 2025
344b501
Update plugin/evm/header/extra.go
StephenButtolph Feb 26, 2025
3a46a15
claimed -> remote
StephenButtolph Feb 26, 2025
82ec2ac
Add comment
StephenButtolph Feb 26, 2025
b08ba54
Merge branch 'acp-176-spike' of github.com:ava-labs/coreth into acp-1…
StephenButtolph Feb 26, 2025
1214814
merged
StephenButtolph Feb 26, 2025
0e66ded
Merge branch 'master' into acp-176-spike
StephenButtolph Feb 26, 2025
fd276a5
reduce diff
StephenButtolph Feb 26, 2025
d687594
reduce diff
StephenButtolph Feb 26, 2025
c78f05f
add comments
StephenButtolph Feb 26, 2025
9b41a95
nit
StephenButtolph Feb 26, 2025
540719d
nit
StephenButtolph Feb 26, 2025
133e27e
nit
StephenButtolph Feb 26, 2025
6495465
nit
StephenButtolph Feb 26, 2025
2860ef5
nit
StephenButtolph Feb 26, 2025
6d7ca18
Add large tip test
StephenButtolph Feb 26, 2025
2636147
Filter by total gas rather than GasUsed
StephenButtolph Feb 26, 2025
ac50d8e
merged
StephenButtolph Feb 26, 2025
bc60ec3
nit fixup comment
StephenButtolph Feb 26, 2025
c95e6af
wrap errors
StephenButtolph Feb 26, 2025
d8e1a5e
wrap errors
StephenButtolph Feb 26, 2025
e3179e8
nit
StephenButtolph Feb 26, 2025
33d501f
nit
StephenButtolph Feb 26, 2025
941064b
Add release notes
StephenButtolph Feb 26, 2025
3f89a5f
merged
StephenButtolph Feb 27, 2025
cd2dd28
Refactor serialization
StephenButtolph Feb 28, 2025
c3b8c38
Implement header.ExtraPrefix serialization into upgrades package
StephenButtolph Feb 28, 2025
148bd15
nit
StephenButtolph Feb 28, 2025
ba3156b
nit
StephenButtolph Feb 28, 2025
474b48c
resolve TODO
StephenButtolph Feb 28, 2025
3f35e89
nit
StephenButtolph Feb 28, 2025
616c5ef
merged
StephenButtolph Feb 28, 2025
84b1db3
reduce diff
StephenButtolph Feb 28, 2025
0336573
address nits
StephenButtolph Feb 28, 2025
69f15e3
nit
StephenButtolph Feb 28, 2025
87e024c
Update plugin/evm/header/extra.go
StephenButtolph Feb 28, 2025
10ab8e1
merged
StephenButtolph Feb 28, 2025
2a6a64d
nit
StephenButtolph Feb 28, 2025
34ff07c
Rename AtomicGasCapacity
StephenButtolph Feb 28, 2025
0ee443f
Add comment
StephenButtolph Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Release Notes

## Pending Release

- Bump golang version to v1.23.6
- Bump golangci-lint to v1.63 and add linters
- Implement ACP-176
- Add `GasTarget` to the chain config to allow modifying the chain's `GasTarget` based on the ACP-176 rules

## [v0.14.1](https://github.com/ava-labs/coreth/releases/tag/v0.14.1)

Expand Down
70 changes: 49 additions & 21 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
package dummy

import (
"bytes"
"errors"
"fmt"
"math/big"
"time"

"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/vms/components/gas"
"github.com/ava-labs/coreth/consensus"
"github.com/ava-labs/coreth/consensus/misc/eip4844"
"github.com/ava-labs/coreth/core/state"
Expand Down Expand Up @@ -41,21 +41,55 @@ type Mode struct {
}

type (
OnFinalizeAndAssembleCallbackType = func(header *types.Header, state *state.StateDB, txs []*types.Transaction) (extraData []byte, blockFeeContribution *big.Int, extDataGasUsed *big.Int, err error)
OnExtraStateChangeType = func(block *types.Block, statedb *state.StateDB) (blockFeeContribution *big.Int, extDataGasUsed *big.Int, err error)
OnFinalizeAndAssembleCallbackType = func(
header *types.Header,
parent *types.Header,
state *state.StateDB,
txs []*types.Transaction,
) (
extraData []byte,
blockFeeContribution *big.Int,
extDataGasUsed *big.Int,
err error,
)

OnExtraStateChangeType = func(
block *types.Block,
parent *types.Header,
statedb *state.StateDB,
) (
blockFeeContribution *big.Int,
extDataGasUsed *big.Int,
err error,
)

ConsensusCallbacks struct {
OnFinalizeAndAssemble OnFinalizeAndAssembleCallbackType
OnExtraStateChange OnExtraStateChangeType
}

DummyEngine struct {
cb ConsensusCallbacks
clock *mockable.Clock
consensusMode Mode
cb ConsensusCallbacks
clock *mockable.Clock
consensusMode Mode
desiredTargetExcess *gas.Gas
}
)

func NewDummyEngine(
cb ConsensusCallbacks,
mode Mode,
clock *mockable.Clock,
desiredTargetExcess *gas.Gas,
) *DummyEngine {
return &DummyEngine{
cb: cb,
clock: clock,
consensusMode: mode,
desiredTargetExcess: desiredTargetExcess,
}
}

func NewETHFaker() *DummyEngine {
return &DummyEngine{
clock: &mockable.Clock{},
Expand Down Expand Up @@ -112,21 +146,15 @@ func NewFullFaker() *DummyEngine {
}
}

func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header *types.Header, parent *types.Header) error {
// Verify that the gasUsed is <= gasLimit
if header.GasUsed > header.GasLimit {
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit)
func verifyHeaderGasFields(config *params.ChainConfig, header *types.Header, parent *types.Header) error {
if err := customheader.VerifyGasUsed(config, parent, header); err != nil {
return err
}
if err := customheader.VerifyGasLimit(config, parent, header); err != nil {
return err
}
// Verify header.Extra matches the expected value.
expectedExtraPrefix, err := customheader.ExtraPrefix(config, parent, header.Time)
if err != nil {
return fmt.Errorf("failed to calculate extra prefix: %w", err)
}
if !bytes.HasPrefix(header.Extra, expectedExtraPrefix) {
return fmt.Errorf("expected header.Extra to have prefix: %x, found %x", expectedExtraPrefix, header.Extra)
if err := customheader.VerifyExtraPrefix(config, parent, header); err != nil {
return err
}

// Verify header.BaseFee matches the expected value.
Expand Down Expand Up @@ -185,7 +213,7 @@ func (eng *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *
}

// Ensure gas-related header fields are correct
if err := eng.verifyHeaderGasFields(config, header, parent); err != nil {
if err := verifyHeaderGasFields(config, header, parent); err != nil {
return err
}

Expand Down Expand Up @@ -341,7 +369,7 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
err error
)
if eng.cb.OnExtraStateChange != nil {
contribution, extDataGasUsed, err = eng.cb.OnExtraStateChange(block, state)
contribution, extDataGasUsed, err = eng.cb.OnExtraStateChange(block, parent, state)
if err != nil {
return err
}
Expand Down Expand Up @@ -396,7 +424,7 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
err error
)
if eng.cb.OnFinalizeAndAssemble != nil {
extraData, contribution, extDataGasUsed, err = eng.cb.OnFinalizeAndAssemble(header, state, txs)
extraData, contribution, extDataGasUsed, err = eng.cb.OnFinalizeAndAssemble(header, parent, state, txs)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -430,7 +458,7 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
}

// finalize the header.Extra
extraPrefix, err := customheader.ExtraPrefix(config, parent, header.Time)
extraPrefix, err := customheader.ExtraPrefix(config, parent, header, eng.desiredTargetExcess)
if err != nil {
return nil, fmt.Errorf("failed to calculate new header.Extra: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ func GenerateChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int,
func (cm *chainMaker) makeHeader(parent *types.Block, gap uint64, state *state.StateDB, engine consensus.Engine) *types.Header {
time := parent.Time() + gap // block time is fixed at [gap] seconds

gasLimit := header.GasLimit(cm.config, parent.Header(), time)
gasLimit, err := header.GasLimit(cm.config, parent.Header(), time)
if err != nil {
panic(err)
}
baseFee, err := header.BaseFee(cm.config, parent.Header(), time)
if err != nil {
panic(err)
Expand Down
20 changes: 12 additions & 8 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
customheader "github.com/ava-labs/coreth/plugin/evm/header"
"github.com/ava-labs/coreth/plugin/evm/upgrade/acp176"
"github.com/ava-labs/coreth/plugin/evm/upgrade/ap1"
"github.com/ava-labs/coreth/plugin/evm/upgrade/ap3"
"github.com/ava-labs/coreth/plugin/evm/upgrade/cortina"
Expand Down Expand Up @@ -152,9 +153,10 @@ func TestStateProcessorErrors(t *testing.T) {
},
{ // ErrGasLimitReached
txs: []*types.Transaction{
makeTx(key1, 0, common.Address{}, big.NewInt(0), 15000001, big.NewInt(225000000000), nil),
// This test was modified to account for ACP-176 gas limits
makeTx(key1, 0, common.Address{}, big.NewInt(0), acp176.MinMaxCapacity+1, big.NewInt(acp176.MinGasPrice), nil),
},
want: "could not apply tx 0 [0x1354370681d2ab68247073d889736f8be4a8d87e35956f0c02658d3670803a66]: gas limit reached",
want: "could not apply tx 0 [0x6c95e59678246e8b44a1d9382a9cc6589684298b32b7aaf640e8b6fc75ce3dfc]: gas limit reached",
},
{ // ErrInsufficientFundsForTransfer
txs: []*types.Transaction{
Expand All @@ -180,15 +182,16 @@ func TestStateProcessorErrors(t *testing.T) {
},
{ // ErrGasLimitReached
txs: []*types.Transaction{
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas*762, big.NewInt(225000000000), nil),
// This test was modified to account for ACP-176 gas limits
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas*953, big.NewInt(acp176.MinGasPrice), nil),
},
want: "could not apply tx 0 [0x76c07cc2b32007eb1a9c3fa066d579a3d77ec4ecb79bbc266624a601d7b08e46]: gas limit reached",
want: "could not apply tx 0 [0xcd46718c1af6fd074deb6b036d34c1cb499517bf90d93df74dcfaba25fdf34af]: gas limit reached",
},
{ // ErrFeeCapTooLow
txs: []*types.Transaction{
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)),
},
want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0, baseFee: 225000000000",
want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0, baseFee: 1",
},
{ // ErrTipVeryHigh
txs: []*types.Transaction{
Expand Down Expand Up @@ -241,7 +244,7 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{
mkBlobTx(0, common.Address{}, params.TxGas, big.NewInt(1), big.NewInt(1), big.NewInt(0), []common.Hash{(common.Hash{1})}),
},
want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1, baseFee: 225000000000",
want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per blob gas less than block blob gas fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7 blobGasFeeCap: 0, blobBaseFee: 1",
},
} {
// FullFaker used to skip header verification that enforces no blobs.
Expand Down Expand Up @@ -358,6 +361,7 @@ func TestStateProcessorErrors(t *testing.T) {
func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Transactions, config *params.ChainConfig) *types.Block {
fakeChainReader := newChainMaker(nil, config, engine)
time := parent.Time() + 10
gasLimit, _ := customheader.GasLimit(config, parent.Header(), time)
baseFee, _ := customheader.BaseFee(config, parent.Header(), time)
header := &types.Header{
ParentHash: parent.Hash(),
Expand All @@ -368,7 +372,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
Difficulty: parent.Difficulty(),
UncleHash: parent.UncleHash(),
}),
GasLimit: parent.GasLimit(),
GasLimit: gasLimit,
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: time,
UncleHash: types.EmptyUncleHash,
Expand All @@ -395,7 +399,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
cumulativeGas += tx.Gas()
nBlobs += len(tx.BlobHashes())
}
header.Extra, _ = customheader.ExtraPrefix(config, parent.Header(), time)
header.Extra, _ = customheader.ExtraPrefix(config, parent.Header(), header, nil)
header.Root = common.BytesToHash(hasher.Sum(nil))
if config.IsCancun(header.Number, header.Time) {
var pExcess, pUsed = uint64(0), uint64(0)
Expand Down
9 changes: 7 additions & 2 deletions core/test_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ import (
)

var TestCallbacks = dummy.ConsensusCallbacks{
OnExtraStateChange: func(block *types.Block, sdb *state.StateDB) (*big.Int, *big.Int, error) {
OnExtraStateChange: func(block *types.Block, _ *types.Header, sdb *state.StateDB) (*big.Int, *big.Int, error) {
sdb.SetBalanceMultiCoin(common.HexToAddress("0xdeadbeef"), common.HexToHash("0xdeadbeef"), big.NewInt(block.Number().Int64()))
return nil, nil, nil
},
OnFinalizeAndAssemble: func(header *types.Header, sdb *state.StateDB, txs []*types.Transaction) ([]byte, *big.Int, *big.Int, error) {
OnFinalizeAndAssemble: func(
header *types.Header,
_ *types.Header,
sdb *state.StateDB,
_ []*types.Transaction,
) ([]byte, *big.Int, *big.Int, error) {
sdb.SetBalanceMultiCoin(common.HexToAddress("0xdeadbeef"), common.HexToHash("0xdeadbeef"), big.NewInt(header.Number.Int64()))
return nil, nil, nil, nil
},
Expand Down
9 changes: 0 additions & 9 deletions core/txpool/blobpool/blobpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ func init() {
*testChainConfig.CancunTime = uint64(time.Now().Unix())
}

// overrideMinFee sets the minimum base fee to 1 wei for the duration of the test.
func overrideMinFee(t *testing.T) {
orig := header.EtnaMinBaseFee
header.EtnaMinBaseFee = big.NewInt(1)
t.Cleanup(func() { header.EtnaMinBaseFee = orig })
}

// testBlockChain is a mock of the live chain for testing the pool.
type testBlockChain struct {
config *params.ChainConfig
Expand Down Expand Up @@ -755,7 +748,6 @@ func TestOpenIndex(t *testing.T) {
// Tests that after indexing all the loaded transactions from disk, a price heap
// is correctly constructed based on the head basefee and blobfee.
func TestOpenHeap(t *testing.T) {
overrideMinFee(t)
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))

// Create a temporary folder for the persistent backend
Expand Down Expand Up @@ -843,7 +835,6 @@ func TestOpenHeap(t *testing.T) {
// Tests that after the pool's previous state is loaded back, any transactions
// over the new storage cap will get dropped.
func TestOpenCap(t *testing.T) {
overrideMinFee(t)
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))

// Create a temporary folder for the persistent backend
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/fee_info_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestFeeInfoProvider(t *testing.T) {
backend := newTestBackend(t, params.TestChainConfig, 2, common.Big0, testGenBlock(t, 55, 370))
backend := newTestBackend(t, params.TestChainConfig, 2, common.Big0, testGenBlock(t, 55, 80))
f, err := newFeeInfoProvider(backend, 1, 2)
require.NoError(t, err)

Expand Down
5 changes: 3 additions & 2 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
customheader "github.com/ava-labs/coreth/plugin/evm/header"
"github.com/ava-labs/coreth/plugin/evm/upgrade/acp176"
"github.com/ava-labs/coreth/plugin/evm/upgrade/ap3"
"github.com/ava-labs/coreth/rpc"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -64,9 +65,9 @@ const (

var (
DefaultMaxPrice = big.NewInt(150 * params.GWei)
DefaultMinPrice = big.NewInt(0 * params.GWei)
DefaultMinPrice = big.NewInt(acp176.MinGasPrice)
DefaultMinBaseFee = big.NewInt(ap3.InitialBaseFee)
DefaultMinGasUsed = big.NewInt(6_000_000) // block gas limit is 8,000,000
DefaultMinGasUsed = big.NewInt(acp176.MinTargetPerSecond)
DefaultMaxLookbackSeconds = uint64(80)
)

Expand Down
Loading
Loading