mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
core/types: port to config2
This commit is contained in:
parent
e3725af2b1
commit
fcf3b4329c
5 changed files with 45 additions and 36 deletions
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 <nil>", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue