mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
Drop Ethereum.chainConfig and consistently read chain configuration from blockchain.Config() to avoid dual sources of truth. Changes include API/backend call sites and DebugAPI constructor cleanup. No functional behavior change is intended.
This commit is contained in:
parent
6f02401575
commit
bfe9a3e714
4 changed files with 15 additions and 19 deletions
|
|
@ -57,7 +57,7 @@ func (api *EthereumAPI) Mining() bool {
|
||||||
|
|
||||||
func (api *EthereumAPI) ChainId() hexutil.Uint64 {
|
func (api *EthereumAPI) ChainId() hexutil.Uint64 {
|
||||||
chainID := new(big.Int)
|
chainID := new(big.Int)
|
||||||
if config := api.e.chainConfig; config.IsEIP155(api.e.blockchain.CurrentBlock().Number) {
|
if config := api.e.blockchain.Config(); config.IsEIP155(api.e.blockchain.CurrentBlock().Number) {
|
||||||
chainID = config.ChainID
|
chainID = config.ChainID
|
||||||
}
|
}
|
||||||
return (hexutil.Uint64)(chainID.Uint64())
|
return (hexutil.Uint64)(chainID.Uint64())
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ type EthAPIBackend struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthAPIBackend) ChainConfig() *params.ChainConfig {
|
func (b *EthAPIBackend) ChainConfig() *params.ChainConfig {
|
||||||
return b.eth.chainConfig
|
return b.eth.blockchain.Config()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthAPIBackend) CurrentBlock() *types.Header {
|
func (b *EthAPIBackend) CurrentBlock() *types.Header {
|
||||||
|
|
@ -85,7 +85,7 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
|
||||||
return b.eth.blockchain.CurrentBlock(), nil
|
return b.eth.blockchain.CurrentBlock(), nil
|
||||||
}
|
}
|
||||||
if number == rpc.FinalizedBlockNumber {
|
if number == rpc.FinalizedBlockNumber {
|
||||||
if b.eth.chainConfig.XDPoS == nil {
|
if b.eth.blockchain.Config().XDPoS == nil {
|
||||||
return nil, errors.New("PoW does not support confirmed block lookup")
|
return nil, errors.New("PoW does not support confirmed block lookup")
|
||||||
}
|
}
|
||||||
current := b.eth.blockchain.CurrentBlock()
|
current := b.eth.blockchain.CurrentBlock()
|
||||||
|
|
@ -138,7 +138,7 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
|
||||||
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
|
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
|
||||||
}
|
}
|
||||||
if number == rpc.FinalizedBlockNumber {
|
if number == rpc.FinalizedBlockNumber {
|
||||||
if b.eth.chainConfig.XDPoS == nil {
|
if b.eth.blockchain.Config().XDPoS == nil {
|
||||||
return nil, errors.New("PoW does not support confirmed block lookup")
|
return nil, errors.New("PoW does not support confirmed block lookup")
|
||||||
}
|
}
|
||||||
current := b.eth.blockchain.CurrentBlock()
|
current := b.eth.blockchain.CurrentBlock()
|
||||||
|
|
@ -273,7 +273,7 @@ func (b *EthAPIBackend) GetEVM(ctx context.Context, state *state.StateDB, XDCxSt
|
||||||
} else {
|
} else {
|
||||||
context = core.NewEVMBlockContext(header, b.eth.BlockChain(), nil)
|
context = core.NewEVMBlockContext(header, b.eth.BlockChain(), nil)
|
||||||
}
|
}
|
||||||
return vm.NewEVM(context, state, XDCxState, b.eth.chainConfig, *vmConfig), vmError, nil
|
return vm.NewEVM(context, state, XDCxState, b.eth.blockchain.Config(), *vmConfig), vmError, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthAPIBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {
|
func (b *EthAPIBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/state"
|
"github.com/XinFinOrg/XDPoSChain/core/state"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/rlp"
|
"github.com/XinFinOrg/XDPoSChain/rlp"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rpc"
|
"github.com/XinFinOrg/XDPoSChain/rpc"
|
||||||
"github.com/XinFinOrg/XDPoSChain/trie"
|
"github.com/XinFinOrg/XDPoSChain/trie"
|
||||||
|
|
@ -36,14 +35,13 @@ import (
|
||||||
// DebugAPI is the collection of Ethereum full node APIs exposed over
|
// DebugAPI is the collection of Ethereum full node APIs exposed over
|
||||||
// the private debugging endpoint.
|
// the private debugging endpoint.
|
||||||
type DebugAPI struct {
|
type DebugAPI struct {
|
||||||
config *params.ChainConfig
|
eth *Ethereum
|
||||||
eth *Ethereum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDebugAPI creates a new API definition for the full node-related
|
// NewDebugAPI creates a new API definition for the full node-related
|
||||||
// private debug methods of the Ethereum service.
|
// private debug methods of the Ethereum service.
|
||||||
func NewDebugAPI(config *params.ChainConfig, eth *Ethereum) *DebugAPI {
|
func NewDebugAPI(eth *Ethereum) *DebugAPI {
|
||||||
return &DebugAPI{config: config, eth: eth}
|
return &DebugAPI{eth: eth}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpBlock retrieves the entire state of the database at a given block.
|
// DumpBlock retrieves the entire state of the database at a given block.
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,7 @@ import (
|
||||||
|
|
||||||
// Ethereum implements the Ethereum full node service.
|
// Ethereum implements the Ethereum full node service.
|
||||||
type Ethereum struct {
|
type Ethereum struct {
|
||||||
config *ethconfig.Config
|
config *ethconfig.Config
|
||||||
chainConfig *params.ChainConfig
|
|
||||||
|
|
||||||
// Channel for shutting down the service
|
// Channel for shutting down the service
|
||||||
shutdownChan chan bool // Channel for shutting down the ethereum
|
shutdownChan chan bool // Channel for shutting down the ethereum
|
||||||
|
|
@ -146,7 +145,6 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
||||||
eth := &Ethereum{
|
eth := &Ethereum{
|
||||||
config: config,
|
config: config,
|
||||||
chainDb: chainDb,
|
chainDb: chainDb,
|
||||||
chainConfig: chainConfig,
|
|
||||||
eventMux: stack.EventMux(),
|
eventMux: stack.EventMux(),
|
||||||
accountManager: stack.AccountManager(),
|
accountManager: stack.AccountManager(),
|
||||||
engine: CreateConsensusEngine(stack, chainConfig, chainDb),
|
engine: CreateConsensusEngine(stack, chainConfig, chainDb),
|
||||||
|
|
@ -221,7 +219,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
||||||
}
|
}
|
||||||
vmConfig.Tracer = t
|
vmConfig.Tracer = t
|
||||||
}
|
}
|
||||||
if eth.chainConfig.XDPoS != nil {
|
if chainConfig.XDPoS != nil {
|
||||||
c := eth.engine.(*XDPoS.XDPoS)
|
c := eth.engine.(*XDPoS.XDPoS)
|
||||||
c.GetXDCXService = func() utils.TradingService {
|
c.GetXDCXService = func() utils.TradingService {
|
||||||
return eth.XDCX
|
return eth.XDCX
|
||||||
|
|
@ -285,7 +283,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
||||||
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
|
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
|
||||||
|
|
||||||
var xdPoS *XDPoS.XDPoS = nil
|
var xdPoS *XDPoS.XDPoS = nil
|
||||||
if eth.chainConfig.XDPoS != nil {
|
if chainConfig.XDPoS != nil {
|
||||||
xdPoS = eth.engine.(*XDPoS.XDPoS)
|
xdPoS = eth.engine.(*XDPoS.XDPoS)
|
||||||
}
|
}
|
||||||
eth.APIBackend = &EthAPIBackend{
|
eth.APIBackend = &EthAPIBackend{
|
||||||
|
|
@ -303,7 +301,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
||||||
// Set global ipc endpoint.
|
// Set global ipc endpoint.
|
||||||
eth.blockchain.IPCEndpoint = stack.IPCEndpoint()
|
eth.blockchain.IPCEndpoint = stack.IPCEndpoint()
|
||||||
|
|
||||||
if eth.chainConfig.XDPoS != nil {
|
if chainConfig.XDPoS != nil {
|
||||||
c := eth.engine.(*XDPoS.XDPoS)
|
c := eth.engine.(*XDPoS.XDPoS)
|
||||||
signHook := func(block *types.Block) error {
|
signHook := func(block *types.Block) error {
|
||||||
eb, err := eth.Etherbase()
|
eb, err := eth.Etherbase()
|
||||||
|
|
@ -315,7 +313,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if block.NumberU64()%common.MergeSignRange == 0 || !eth.chainConfig.IsTIP2019(block.Number()) {
|
if block.NumberU64()%common.MergeSignRange == 0 || !chainConfig.IsTIP2019(block.Number()) {
|
||||||
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb, eb); err != nil {
|
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb, eb); err != nil {
|
||||||
return fmt.Errorf("fail to create tx sign for importing block: %v", err)
|
return fmt.Errorf("fail to create tx sign for importing block: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -433,7 +431,7 @@ func (e *Ethereum) APIs() []rpc.API {
|
||||||
Service: NewAdminAPI(e),
|
Service: NewAdminAPI(e),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "debug",
|
Namespace: "debug",
|
||||||
Service: NewDebugAPI(e.chainConfig, e),
|
Service: NewDebugAPI(e),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "net",
|
Namespace: "net",
|
||||||
Service: e.netRPCService,
|
Service: e.netRPCService,
|
||||||
|
|
@ -483,7 +481,7 @@ func (e *Ethereum) ValidateMasternode() (bool, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if e.chainConfig.XDPoS != nil {
|
if e.blockchain.Config().XDPoS != nil {
|
||||||
//check if miner's wallet is in set of validators
|
//check if miner's wallet is in set of validators
|
||||||
c := e.engine.(*XDPoS.XDPoS)
|
c := e.engine.(*XDPoS.XDPoS)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue