From fcf3b4329c300e8b5270c10508966096dbe49045 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 16 Jul 2025 02:35:32 +0200 Subject: [PATCH] core/types: port to config2 --- core/types/block_test.go | 3 +- core/types/receipt.go | 2 +- core/types/receipt_test.go | 4 +- core/types/transaction_signing.go | 66 +++++++++++++++++-------------- core/types/transaction_test.go | 6 +-- 5 files changed, 45 insertions(+), 36 deletions(-) diff --git a/core/types/block_test.go b/core/types/block_test.go index 2130a2fcf3..3b11f1cade 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/internal/blocktest" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/params/presets" "github.com/ethereum/go-ethereum/rlp" "github.com/holiman/uint256" ) @@ -278,7 +279,7 @@ func makeBenchBlock() *Block { key, _ = crypto.GenerateKey() txs = make([]*Transaction, 70) receipts = make([]*Receipt, len(txs)) - signer = LatestSigner(params.TestChainConfig) + signer = LatestSigner(presets.TestChainConfig) uncles = make([]*Header, 3) ) header := &Header{ diff --git a/core/types/receipt.go b/core/types/receipt.go index 5b6669f274..2d02262bcd 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -379,7 +379,7 @@ func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer) { // DeriveFields fills the receipts with their computed fields based on consensus // data and contextual infos like containing block and transactions. -func (rs Receipts) DeriveFields(config *params.ChainConfig, blockHash common.Hash, blockNumber uint64, blockTime uint64, baseFee *big.Int, blobGasPrice *big.Int, txs []*Transaction) error { +func (rs Receipts) DeriveFields(config *params.Config2, blockHash common.Hash, blockNumber uint64, blockTime uint64, baseFee *big.Int, blobGasPrice *big.Int, txs []*Transaction) error { signer := MakeSigner(config, new(big.Int).SetUint64(blockNumber), blockTime) logIndex := uint(0) diff --git a/core/types/receipt_test.go b/core/types/receipt_test.go index 8f805ff096..53f892b7ad 100644 --- a/core/types/receipt_test.go +++ b/core/types/receipt_test.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/params/presets" "github.com/ethereum/go-ethereum/rlp" "github.com/holiman/uint256" "github.com/kylelemons/godebug/diff" @@ -330,7 +331,8 @@ func TestDeriveFields(t *testing.T) { blobGasPrice := big.NewInt(920) receipts := getTestReceipts() derivedReceipts := clearComputedFieldsOnReceipts(receipts) - err := Receipts(derivedReceipts).DeriveFields(params.TestChainConfig, blockHash, blockNumber.Uint64(), blockTime, basefee, blobGasPrice, txs) + config := presets.AllEthashProtocolChanges + err := Receipts(derivedReceipts).DeriveFields(config, blockHash, blockNumber.Uint64(), blockTime, basefee, blobGasPrice, txs) if err != nil { t.Fatalf("DeriveFields(...) = %v, want ", err) } diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 01aa67c6ba..c37a0f7e1f 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -39,20 +39,23 @@ type sigCache struct { } // MakeSigner returns a Signer based on the given chain config and block number. -func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64) Signer { +func MakeSigner(config *params.Config2, blockNumber *big.Int, blockTime uint64) Signer { + number := blockNumber.Uint64() + chainID := params.Get[*params.ChainID](config).BigInt() + var signer Signer switch { - case config.IsPrague(blockNumber, blockTime): - signer = NewPragueSigner(config.ChainID) - case config.IsCancun(blockNumber, blockTime): - signer = NewCancunSigner(config.ChainID) - case config.IsLondon(blockNumber): - signer = NewLondonSigner(config.ChainID) - case config.IsBerlin(blockNumber): - signer = NewEIP2930Signer(config.ChainID) - case config.IsEIP155(blockNumber): - signer = NewEIP155Signer(config.ChainID) - case config.IsHomestead(blockNumber): + case config.Active(forks.Prague, number, blockTime): + signer = NewPragueSigner(chainID) + case config.Active(forks.Cancun, number, blockTime): + signer = NewCancunSigner(chainID) + case config.Active(forks.London, number, blockTime): + signer = NewLondonSigner(chainID) + case config.Active(forks.Berlin, number, blockTime): + signer = NewEIP2930Signer(chainID) + case config.Active(forks.SpuriousDragon, number, blockTime): + signer = NewEIP155Signer(chainID) + case config.Active(forks.Homestead, number, blockTime): signer = HomesteadSigner{} default: signer = FrontierSigner{} @@ -67,20 +70,22 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint // // Use this in transaction-handling code where the current block number is unknown. If you // have the current block number available, use MakeSigner instead. -func LatestSigner(config *params.ChainConfig) Signer { +func LatestSigner(config *params.Config2) Signer { + chainID := params.Get[*params.ChainID](config).BigInt() + var signer Signer - if config.ChainID != nil { + if chainID != nil { switch { - case config.PragueTime != nil: - signer = NewPragueSigner(config.ChainID) - case config.CancunTime != nil: - signer = NewCancunSigner(config.ChainID) - case config.LondonBlock != nil: - signer = NewLondonSigner(config.ChainID) - case config.BerlinBlock != nil: - signer = NewEIP2930Signer(config.ChainID) - case config.EIP155Block != nil: - signer = NewEIP155Signer(config.ChainID) + case config.Scheduled(forks.Prague): + signer = NewPragueSigner(chainID) + case config.Scheduled(forks.Cancun): + signer = NewCancunSigner(chainID) + case config.Scheduled(forks.London): + signer = NewLondonSigner(chainID) + case config.Scheduled(forks.Berlin): + signer = NewEIP2930Signer(chainID) + case config.Scheduled(forks.SpuriousDragon): + signer = NewEIP155Signer(chainID) default: signer = HomesteadSigner{} } @@ -198,25 +203,26 @@ func newModernSigner(chainID *big.Int, fork forks.Fork) Signer { } // configure legacy signer switch { - case fork >= forks.SpuriousDragon: + case fork.After(forks.SpuriousDragon): s.legacy = NewEIP155Signer(chainID) - case fork >= forks.Homestead: + case fork.After(forks.Homestead): s.legacy = HomesteadSigner{} default: s.legacy = FrontierSigner{} } s.txtypes[LegacyTxType] = struct{}{} // configure tx types - if fork >= forks.Berlin { + // TODO: fix this + if fork.After(forks.Berlin) { s.txtypes[AccessListTxType] = struct{}{} } - if fork >= forks.London { + if fork.After(forks.London) { s.txtypes[DynamicFeeTxType] = struct{}{} } - if fork >= forks.Cancun { + if fork.After(forks.Cancun) { s.txtypes[BlobTxType] = struct{}{} } - if fork >= forks.Prague { + if fork.After(forks.Prague) { s.txtypes[SetCodeTxType] = struct{}{} } return s diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 7d5e2f058a..23636206a1 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -29,7 +29,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/params/presets" "github.com/ethereum/go-ethereum/rlp" ) @@ -596,7 +596,7 @@ func BenchmarkHash(b *testing.B) { } func BenchmarkEffectiveGasTip(b *testing.B) { - signer := LatestSigner(params.TestChainConfig) + signer := LatestSigner(presets.TestChainConfig) key, _ := crypto.GenerateKey() txdata := &DynamicFeeTx{ ChainID: big.NewInt(1), @@ -634,7 +634,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) { } func TestEffectiveGasTipInto(t *testing.T) { - signer := LatestSigner(params.TestChainConfig) + signer := LatestSigner(presets.TestChainConfig) key, _ := crypto.GenerateKey() testCases := []struct {