Skip to content

Commit b17e4a8

Browse files
authored
Merge pull request #19344 from karalabe/eth-remove-redundant-chainconfig
eth: remove redundant chain config fields
2 parents dba336e + ac3e7c9 commit b17e4a8

4 files changed

Lines changed: 21 additions & 25 deletions

File tree

‎eth/api.go‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/ethereum/go-ethereum/core/state"
3636
"github.com/ethereum/go-ethereum/core/types"
3737
"github.com/ethereum/go-ethereum/internal/ethapi"
38-
"github.com/ethereum/go-ethereum/params"
3938
"github.com/ethereum/go-ethereum/rlp"
4039
"github.com/ethereum/go-ethereum/rpc"
4140
"github.com/ethereum/go-ethereum/trie"
@@ -70,7 +69,7 @@ func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64 {
7069
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
7170
func (api *PublicEthereumAPI) ChainId() hexutil.Uint64 {
7271
chainID := new(big.Int)
73-
if config := api.e.chainConfig; config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) {
72+
if config := api.e.blockchain.Config(); config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) {
7473
chainID = config.ChainID
7574
}
7675
return (hexutil.Uint64)(chainID.Uint64())
@@ -288,14 +287,13 @@ func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error
288287
// PrivateDebugAPI is the collection of Ethereum full node APIs exposed over
289288
// the private debugging endpoint.
290289
type PrivateDebugAPI struct {
291-
config *params.ChainConfig
292-
eth *Ethereum
290+
eth *Ethereum
293291
}
294292

295293
// NewPrivateDebugAPI creates a new API definition for the full node-related
296294
// private debug methods of the Ethereum service.
297-
func NewPrivateDebugAPI(config *params.ChainConfig, eth *Ethereum) *PrivateDebugAPI {
298-
return &PrivateDebugAPI{config: config, eth: eth}
295+
func NewPrivateDebugAPI(eth *Ethereum) *PrivateDebugAPI {
296+
return &PrivateDebugAPI{eth: eth}
299297
}
300298

301299
// Preimage is a debug API function that returns the preimage for a sha3 hash, if known.

‎eth/api_backend.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type EthAPIBackend struct {
4444

4545
// ChainConfig returns the active chain configuration.
4646
func (b *EthAPIBackend) ChainConfig() *params.ChainConfig {
47-
return b.eth.chainConfig
47+
return b.eth.blockchain.Config()
4848
}
4949

5050
func (b *EthAPIBackend) CurrentBlock() *types.Block {
@@ -130,7 +130,7 @@ func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *sta
130130
vmError := func() error { return nil }
131131

132132
context := core.NewEVMContext(msg, header, b.eth.BlockChain(), nil)
133-
return vm.NewEVM(context, state, b.eth.chainConfig, *b.eth.blockchain.GetVMConfig()), vmError, nil
133+
return vm.NewEVM(context, state, b.eth.blockchain.Config(), *b.eth.blockchain.GetVMConfig()), vmError, nil
134134
}
135135

136136
func (b *EthAPIBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {

‎eth/api_tracer.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl
201201

202202
// Fetch and execute the next block trace tasks
203203
for task := range tasks {
204-
signer := types.MakeSigner(api.config, task.block.Number())
204+
signer := types.MakeSigner(api.eth.blockchain.Config(), task.block.Number())
205205

206206
// Trace all the transactions contained within
207207
for i, tx := range task.block.Transactions() {
@@ -295,7 +295,7 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl
295295
break
296296
}
297297
// Finalize the state so any modifications are written to the trie
298-
root, err := statedb.Commit(api.eth.chainConfig.IsEIP158(block.Number()))
298+
root, err := statedb.Commit(api.eth.blockchain.Config().IsEIP158(block.Number()))
299299
if err != nil {
300300
failed = err
301301
break
@@ -460,7 +460,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
460460
}
461461
// Execute all the transaction contained within the block concurrently
462462
var (
463-
signer = types.MakeSigner(api.config, block.Number())
463+
signer = types.MakeSigner(api.eth.blockchain.Config(), block.Number())
464464

465465
txs = block.Transactions()
466466
results = make([]*txTraceResult, len(txs))
@@ -501,7 +501,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
501501
msg, _ := tx.AsMessage(signer)
502502
vmctx := core.NewEVMContext(msg, block.Header(), api.eth.blockchain, nil)
503503

504-
vmenv := vm.NewEVM(vmctx, statedb, api.config, vm.Config{})
504+
vmenv := vm.NewEVM(vmctx, statedb, api.eth.blockchain.Config(), vm.Config{})
505505
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil {
506506
failed = err
507507
break
@@ -561,7 +561,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
561561

562562
// Execute transaction, either tracing all or just the requested one
563563
var (
564-
signer = types.MakeSigner(api.config, block.Number())
564+
signer = types.MakeSigner(api.eth.blockchain.Config(), block.Number())
565565
dumps []string
566566
)
567567
for i, tx := range block.Transactions() {
@@ -595,7 +595,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
595595
}
596596
}
597597
// Execute the transaction and flush any traces to disk
598-
vmenv := vm.NewEVM(vmctx, statedb, api.config, vmConf)
598+
vmenv := vm.NewEVM(vmctx, statedb, api.eth.blockchain.Config(), vmConf)
599599
_, _, _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()))
600600
if writer != nil {
601601
writer.Flush()
@@ -756,7 +756,7 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
756756
tracer = vm.NewStructLogger(config.LogConfig)
757757
}
758758
// Run the transaction with tracing enabled.
759-
vmenv := vm.NewEVM(vmctx, statedb, api.config, vm.Config{Debug: true, Tracer: tracer})
759+
vmenv := vm.NewEVM(vmctx, statedb, api.eth.blockchain.Config(), vm.Config{Debug: true, Tracer: tracer})
760760

761761
ret, gas, failed, err := core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas()))
762762
if err != nil {
@@ -796,7 +796,7 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree
796796
return nil, vm.Context{}, nil, err
797797
}
798798
// Recompute transactions up to the target index.
799-
signer := types.MakeSigner(api.config, block.Number())
799+
signer := types.MakeSigner(api.eth.blockchain.Config(), block.Number())
800800

801801
for idx, tx := range block.Transactions() {
802802
// Assemble the transaction call message and return if the requested offset
@@ -806,7 +806,7 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree
806806
return msg, context, statedb, nil
807807
}
808808
// Not yet the searched for transaction, execute on top of the current state
809-
vmenv := vm.NewEVM(context, statedb, api.config, vm.Config{})
809+
vmenv := vm.NewEVM(context, statedb, api.eth.blockchain.Config(), vm.Config{})
810810
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
811811
return nil, vm.Context{}, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
812812
}

‎eth/backend.go‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ type LesServer interface {
6161

6262
// Ethereum implements the Ethereum full node service.
6363
type Ethereum struct {
64-
config *Config
65-
chainConfig *params.ChainConfig
64+
config *Config
6665

6766
// Channel for shutting down the service
6867
shutdownChan chan bool // Channel for shutting down the Ethereum
@@ -134,7 +133,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
134133
eth := &Ethereum{
135134
config: config,
136135
chainDb: chainDb,
137-
chainConfig: chainConfig,
138136
eventMux: ctx.EventMux,
139137
accountManager: ctx.AccountManager,
140138
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.MinerNotify, config.MinerNoverify, chainDb),
@@ -169,7 +167,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
169167
}
170168
cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieCleanLimit: config.TrieCleanCache, TrieDirtyLimit: config.TrieDirtyCache, TrieTimeLimit: config.TrieTimeout}
171169
)
172-
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig, eth.shouldPreserve)
170+
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve)
173171
if err != nil {
174172
return nil, err
175173
}
@@ -184,13 +182,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
184182
if config.TxPool.Journal != "" {
185183
config.TxPool.Journal = ctx.ResolvePath(config.TxPool.Journal)
186184
}
187-
eth.txPool = core.NewTxPool(config.TxPool, eth.chainConfig, eth.blockchain)
185+
eth.txPool = core.NewTxPool(config.TxPool, chainConfig, eth.blockchain)
188186

189-
if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb, config.Whitelist); err != nil {
187+
if eth.protocolManager, err = NewProtocolManager(chainConfig, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb, config.Whitelist); err != nil {
190188
return nil, err
191189
}
192190

193-
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock)
191+
eth.miner = miner.New(eth, chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock)
194192
eth.miner.SetExtra(makeExtraData(config.MinerExtraData))
195193

196194
eth.APIBackend = &EthAPIBackend{eth, nil}
@@ -302,7 +300,7 @@ func (s *Ethereum) APIs() []rpc.API {
302300
}, {
303301
Namespace: "debug",
304302
Version: "1.0",
305-
Service: NewPrivateDebugAPI(s.chainConfig, s),
303+
Service: NewPrivateDebugAPI(s),
306304
}, {
307305
Namespace: "net",
308306
Version: "1.0",

0 commit comments

Comments
 (0)