mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
add confirmed loopup
This commit is contained in:
parent
49fc016245
commit
abb0dcc48b
3 changed files with 47 additions and 7 deletions
|
|
@ -56,8 +56,9 @@ import (
|
||||||
|
|
||||||
// EthApiBackend implements ethapi.Backend for full nodes
|
// EthApiBackend implements ethapi.Backend for full nodes
|
||||||
type EthApiBackend struct {
|
type EthApiBackend struct {
|
||||||
eth *Ethereum
|
eth *Ethereum
|
||||||
gpo *gasprice.Oracle
|
gpo *gasprice.Oracle
|
||||||
|
XDPoS *XDPoS.XDPoS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthApiBackend) ChainConfig() *params.ChainConfig {
|
func (b *EthApiBackend) ChainConfig() *params.ChainConfig {
|
||||||
|
|
@ -81,6 +82,22 @@ func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNum
|
||||||
// Otherwise resolve and return the block
|
// Otherwise resolve and return the block
|
||||||
if blockNr == rpc.LatestBlockNumber {
|
if blockNr == rpc.LatestBlockNumber {
|
||||||
return b.eth.blockchain.CurrentBlock().Header(), nil
|
return b.eth.blockchain.CurrentBlock().Header(), nil
|
||||||
|
} else if blockNr == rpc.ConfirmedBlockNumber {
|
||||||
|
if b.eth.chainConfig.XDPoS == nil {
|
||||||
|
return nil, errors.New("PoW does not support confirmed block loopup")
|
||||||
|
}
|
||||||
|
current := b.eth.blockchain.CurrentBlock().Header()
|
||||||
|
if b.eth.blockchain.Config().XDPoS.BlockConsensusVersion(
|
||||||
|
current.Number,
|
||||||
|
current.Extra,
|
||||||
|
XDPoS.ExtraFieldCheck,
|
||||||
|
) == params.ConsensusEngineVersion2 {
|
||||||
|
// TO CHECK: why calling config in XDPoS is blocked (not field and method)
|
||||||
|
confirmedHash := b.XDPoS.EngineV2.GetLatestCommittedBlockInfo().Hash
|
||||||
|
return b.eth.blockchain.GetHeaderByHash(confirmedHash), nil
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("PoS V1 does not support confirmed block loopup")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return b.eth.blockchain.GetHeaderByNumber(uint64(blockNr)), nil
|
return b.eth.blockchain.GetHeaderByNumber(uint64(blockNr)), nil
|
||||||
}
|
}
|
||||||
|
|
@ -93,6 +110,22 @@ func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb
|
||||||
// Otherwise resolve and return the block
|
// Otherwise resolve and return the block
|
||||||
if blockNr == rpc.LatestBlockNumber {
|
if blockNr == rpc.LatestBlockNumber {
|
||||||
return b.eth.blockchain.CurrentBlock(), nil
|
return b.eth.blockchain.CurrentBlock(), nil
|
||||||
|
} else if blockNr == rpc.ConfirmedBlockNumber {
|
||||||
|
if b.eth.chainConfig.XDPoS == nil {
|
||||||
|
return nil, errors.New("PoW does not support confirmed block loopup")
|
||||||
|
}
|
||||||
|
current := b.eth.blockchain.CurrentBlock().Header()
|
||||||
|
if b.eth.blockchain.Config().XDPoS.BlockConsensusVersion(
|
||||||
|
current.Number,
|
||||||
|
current.Extra,
|
||||||
|
XDPoS.ExtraFieldCheck,
|
||||||
|
) == params.ConsensusEngineVersion2 {
|
||||||
|
// TO CHECK: why calling config in XDPoS is blocked (not field and method)
|
||||||
|
confirmedHash := b.XDPoS.EngineV2.GetLatestCommittedBlockInfo().Hash
|
||||||
|
return b.eth.blockchain.GetBlockByHash(confirmedHash), nil
|
||||||
|
} else {
|
||||||
|
return nil, errors.New("PoS V1 does not support confirmed block loopup")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return b.eth.blockchain.GetBlockByNumber(uint64(blockNr)), nil
|
return b.eth.blockchain.GetBlockByNumber(uint64(blockNr)), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,11 @@ func New(ctx *node.ServiceContext, config *Config, XDCXServ *XDCx.XDCX, lendingS
|
||||||
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, ctx.GetConfig().AnnounceTxs)
|
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, ctx.GetConfig().AnnounceTxs)
|
||||||
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
||||||
|
|
||||||
eth.ApiBackend = &EthApiBackend{eth, nil}
|
if eth.chainConfig.XDPoS != nil {
|
||||||
|
eth.ApiBackend = &EthApiBackend{eth, nil, eth.engine.(*XDPoS.XDPoS)}
|
||||||
|
} else {
|
||||||
|
eth.ApiBackend = &EthApiBackend{eth, nil, nil}
|
||||||
|
}
|
||||||
gpoParams := config.GPO
|
gpoParams := config.GPO
|
||||||
if gpoParams.Default == nil {
|
if gpoParams.Default == nil {
|
||||||
gpoParams.Default = config.GasPrice
|
gpoParams.Default = config.GasPrice
|
||||||
|
|
|
||||||
11
rpc/types.go
11
rpc/types.go
|
|
@ -120,10 +120,11 @@ type BlockNumber int64
|
||||||
type EpochNumber int64
|
type EpochNumber int64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PendingBlockNumber = BlockNumber(-2)
|
ConfirmedBlockNumber = BlockNumber(-3)
|
||||||
LatestBlockNumber = BlockNumber(-1)
|
PendingBlockNumber = BlockNumber(-2)
|
||||||
EarliestBlockNumber = BlockNumber(0)
|
LatestBlockNumber = BlockNumber(-1)
|
||||||
LatestEpochNumber = EpochNumber(-1)
|
EarliestBlockNumber = BlockNumber(0)
|
||||||
|
LatestEpochNumber = EpochNumber(-1)
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
|
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
|
||||||
|
|
@ -144,6 +145,8 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
||||||
case "pending":
|
case "pending":
|
||||||
*bn = PendingBlockNumber
|
*bn = PendingBlockNumber
|
||||||
return nil
|
return nil
|
||||||
|
case "confirmed":
|
||||||
|
*bn = ConfirmedBlockNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
blckNum, err := hexutil.DecodeUint64(input)
|
blckNum, err := hexutil.DecodeUint64(input)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue