core/types: port to config2

This commit is contained in:
Felix Lange 2025-07-16 02:35:32 +02:00
parent e3725af2b1
commit fcf3b4329c
5 changed files with 45 additions and 36 deletions

View file

@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/blocktest" "github.com/ethereum/go-ethereum/internal/blocktest"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params/presets"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256" "github.com/holiman/uint256"
) )
@ -278,7 +279,7 @@ func makeBenchBlock() *Block {
key, _ = crypto.GenerateKey() key, _ = crypto.GenerateKey()
txs = make([]*Transaction, 70) txs = make([]*Transaction, 70)
receipts = make([]*Receipt, len(txs)) receipts = make([]*Receipt, len(txs))
signer = LatestSigner(params.TestChainConfig) signer = LatestSigner(presets.TestChainConfig)
uncles = make([]*Header, 3) uncles = make([]*Header, 3)
) )
header := &Header{ header := &Header{

View file

@ -379,7 +379,7 @@ func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer) {
// DeriveFields fills the receipts with their computed fields based on consensus // DeriveFields fills the receipts with their computed fields based on consensus
// data and contextual infos like containing block and transactions. // 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) signer := MakeSigner(config, new(big.Int).SetUint64(blockNumber), blockTime)
logIndex := uint(0) logIndex := uint(0)

View file

@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params/presets"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"github.com/kylelemons/godebug/diff" "github.com/kylelemons/godebug/diff"
@ -330,7 +331,8 @@ func TestDeriveFields(t *testing.T) {
blobGasPrice := big.NewInt(920) blobGasPrice := big.NewInt(920)
receipts := getTestReceipts() receipts := getTestReceipts()
derivedReceipts := clearComputedFieldsOnReceipts(receipts) 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 { if err != nil {
t.Fatalf("DeriveFields(...) = %v, want <nil>", err) t.Fatalf("DeriveFields(...) = %v, want <nil>", err)
} }

View file

@ -39,20 +39,23 @@ type sigCache struct {
} }
// MakeSigner returns a Signer based on the given chain config and block number. // 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 var signer Signer
switch { switch {
case config.IsPrague(blockNumber, blockTime): case config.Active(forks.Prague, number, blockTime):
signer = NewPragueSigner(config.ChainID) signer = NewPragueSigner(chainID)
case config.IsCancun(blockNumber, blockTime): case config.Active(forks.Cancun, number, blockTime):
signer = NewCancunSigner(config.ChainID) signer = NewCancunSigner(chainID)
case config.IsLondon(blockNumber): case config.Active(forks.London, number, blockTime):
signer = NewLondonSigner(config.ChainID) signer = NewLondonSigner(chainID)
case config.IsBerlin(blockNumber): case config.Active(forks.Berlin, number, blockTime):
signer = NewEIP2930Signer(config.ChainID) signer = NewEIP2930Signer(chainID)
case config.IsEIP155(blockNumber): case config.Active(forks.SpuriousDragon, number, blockTime):
signer = NewEIP155Signer(config.ChainID) signer = NewEIP155Signer(chainID)
case config.IsHomestead(blockNumber): case config.Active(forks.Homestead, number, blockTime):
signer = HomesteadSigner{} signer = HomesteadSigner{}
default: default:
signer = FrontierSigner{} 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 // Use this in transaction-handling code where the current block number is unknown. If you
// have the current block number available, use MakeSigner instead. // 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 var signer Signer
if config.ChainID != nil { if chainID != nil {
switch { switch {
case config.PragueTime != nil: case config.Scheduled(forks.Prague):
signer = NewPragueSigner(config.ChainID) signer = NewPragueSigner(chainID)
case config.CancunTime != nil: case config.Scheduled(forks.Cancun):
signer = NewCancunSigner(config.ChainID) signer = NewCancunSigner(chainID)
case config.LondonBlock != nil: case config.Scheduled(forks.London):
signer = NewLondonSigner(config.ChainID) signer = NewLondonSigner(chainID)
case config.BerlinBlock != nil: case config.Scheduled(forks.Berlin):
signer = NewEIP2930Signer(config.ChainID) signer = NewEIP2930Signer(chainID)
case config.EIP155Block != nil: case config.Scheduled(forks.SpuriousDragon):
signer = NewEIP155Signer(config.ChainID) signer = NewEIP155Signer(chainID)
default: default:
signer = HomesteadSigner{} signer = HomesteadSigner{}
} }
@ -198,25 +203,26 @@ func newModernSigner(chainID *big.Int, fork forks.Fork) Signer {
} }
// configure legacy signer // configure legacy signer
switch { switch {
case fork >= forks.SpuriousDragon: case fork.After(forks.SpuriousDragon):
s.legacy = NewEIP155Signer(chainID) s.legacy = NewEIP155Signer(chainID)
case fork >= forks.Homestead: case fork.After(forks.Homestead):
s.legacy = HomesteadSigner{} s.legacy = HomesteadSigner{}
default: default:
s.legacy = FrontierSigner{} s.legacy = FrontierSigner{}
} }
s.txtypes[LegacyTxType] = struct{}{} s.txtypes[LegacyTxType] = struct{}{}
// configure tx types // configure tx types
if fork >= forks.Berlin { // TODO: fix this
if fork.After(forks.Berlin) {
s.txtypes[AccessListTxType] = struct{}{} s.txtypes[AccessListTxType] = struct{}{}
} }
if fork >= forks.London { if fork.After(forks.London) {
s.txtypes[DynamicFeeTxType] = struct{}{} s.txtypes[DynamicFeeTxType] = struct{}{}
} }
if fork >= forks.Cancun { if fork.After(forks.Cancun) {
s.txtypes[BlobTxType] = struct{}{} s.txtypes[BlobTxType] = struct{}{}
} }
if fork >= forks.Prague { if fork.After(forks.Prague) {
s.txtypes[SetCodeTxType] = struct{}{} s.txtypes[SetCodeTxType] = struct{}{}
} }
return s return s

View file

@ -29,7 +29,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "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" "github.com/ethereum/go-ethereum/rlp"
) )
@ -596,7 +596,7 @@ func BenchmarkHash(b *testing.B) {
} }
func BenchmarkEffectiveGasTip(b *testing.B) { func BenchmarkEffectiveGasTip(b *testing.B) {
signer := LatestSigner(params.TestChainConfig) signer := LatestSigner(presets.TestChainConfig)
key, _ := crypto.GenerateKey() key, _ := crypto.GenerateKey()
txdata := &DynamicFeeTx{ txdata := &DynamicFeeTx{
ChainID: big.NewInt(1), ChainID: big.NewInt(1),
@ -634,7 +634,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) {
} }
func TestEffectiveGasTipInto(t *testing.T) { func TestEffectiveGasTipInto(t *testing.T) {
signer := LatestSigner(params.TestChainConfig) signer := LatestSigner(presets.TestChainConfig)
key, _ := crypto.GenerateKey() key, _ := crypto.GenerateKey()
testCases := []struct { testCases := []struct {