Skip to content

Commit

Permalink
Merge pull request ethereum#214 from XinFinOrg/devnet-update-query
Browse files Browse the repository at this point in the history
Devnet Update Query
  • Loading branch information
span14 authored Feb 4, 2023
2 parents 49fc016 + eac0e42 commit bd46a94
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
37 changes: 35 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ import (

// EthApiBackend implements ethapi.Backend for full nodes
type EthApiBackend struct {
eth *Ethereum
gpo *gasprice.Oracle
eth *Ethereum
gpo *gasprice.Oracle
XDPoS *XDPoS.XDPoS
}

func (b *EthApiBackend) ChainConfig() *params.ChainConfig {
Expand All @@ -81,6 +82,22 @@ func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNum
// Otherwise resolve and return the block
if blockNr == rpc.LatestBlockNumber {
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 lookup")
}
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 lookup")
}
}
return b.eth.blockchain.GetHeaderByNumber(uint64(blockNr)), nil
}
Expand All @@ -93,6 +110,22 @@ func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb
// Otherwise resolve and return the block
if blockNr == rpc.LatestBlockNumber {
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 lookup")
}
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 lookup")
}
}
return b.eth.blockchain.GetBlockByNumber(uint64(blockNr)), nil
}
Expand Down
6 changes: 5 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
if gpoParams.Default == nil {
gpoParams.Default = config.GasPrice
Expand Down
2 changes: 1 addition & 1 deletion light/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (pool *TxPool) checkMinedTxs(ctx context.Context, hash common.Hash, number
}
// If some transactions have been mined, write the needed data to disk and update
if list != nil {
// Retrieve all the receipts belonging to this block and write the loopup table
// Retrieve all the receipts belonging to this block and write the lookup table
if _, err := GetBlockReceipts(ctx, pool.odr, hash, number); err != nil { // ODR caches, ignore results
return err
}
Expand Down
14 changes: 9 additions & 5 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ type BlockNumber int64
type EpochNumber int64

const (
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
LatestEpochNumber = EpochNumber(-1)
ConfirmedBlockNumber = BlockNumber(-3)
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
LatestEpochNumber = EpochNumber(-1)
)

// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
// - "latest", "earliest" or "pending" as string arguments
// - "latest", "earliest", "pending" and "confirmed" as string arguments
// - the block number
// Returned errors:
// - an invalid block number error when the given argument isn't a known strings
Expand All @@ -144,6 +145,9 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
case "pending":
*bn = PendingBlockNumber
return nil
case "confirmed":
*bn = ConfirmedBlockNumber
return nil
}

blckNum, err := hexutil.DecodeUint64(input)
Expand Down

0 comments on commit bd46a94

Please sign in to comment.