mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
fix api trace block & Change option pending block.
This commit is contained in:
parent
420a589599
commit
afe58d79fc
6 changed files with 21 additions and 16 deletions
|
|
@ -572,6 +572,9 @@ func (XDCx *XDCX) GetTradingState(block *types.Block, author common.Address) (*t
|
|||
}
|
||||
return tradingstate.New(root, XDCx.StateCache)
|
||||
}
|
||||
func (XDCX *XDCX) GetEmptyTradingState() (*tradingstate.TradingStateDB, error) {
|
||||
return tradingstate.New(tradingstate.EmptyRoot, XDCX.StateCache)
|
||||
}
|
||||
|
||||
func (XDCx *XDCX) GetStateCache() tradingstate.Database {
|
||||
return XDCx.StateCache
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ type Masternode struct {
|
|||
type TradingService interface {
|
||||
GetTradingStateRoot(block *types.Block, author common.Address) (common.Hash, error)
|
||||
GetTradingState(block *types.Block, author common.Address) (*tradingstate.TradingStateDB, error)
|
||||
GetEmptyTradingState() (*tradingstate.TradingStateDB, error)
|
||||
HasTradingState(block *types.Block, author common.Address) bool
|
||||
GetStateCache() tradingstate.Database
|
||||
GetTriegc() *prque.Prque
|
||||
|
|
|
|||
|
|
@ -519,6 +519,13 @@ func (bc *BlockChain) OrderStateAt(block *types.Block) (*tradingstate.TradingSta
|
|||
} else {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
XDCxState, err := XDCXService.GetEmptyTradingState()
|
||||
if err == nil {
|
||||
return XDCxState, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, errors.New("Get XDCx state fail")
|
||||
|
|
|
|||
|
|
@ -306,11 +306,7 @@ func NewPublicDebugAPI(eth *Ethereum) *PublicDebugAPI {
|
|||
// DumpBlock retrieves the entire state of the database at a given block.
|
||||
func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
|
||||
if blockNr == rpc.PendingBlockNumber {
|
||||
// If we're dumping the pending state, we need to request
|
||||
// both the pending block as well as the pending state from
|
||||
// the miner and operate on those
|
||||
_, stateDb := api.eth.miner.Pending()
|
||||
return stateDb.RawDump(), nil
|
||||
blockNr = rpc.LatestBlockNumber
|
||||
}
|
||||
var block *types.Block
|
||||
if blockNr == rpc.LatestBlockNumber {
|
||||
|
|
|
|||
|
|
@ -76,8 +76,7 @@ func (b *EthApiBackend) SetHead(number uint64) {
|
|||
func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) {
|
||||
// Pending block is only known by the miner
|
||||
if blockNr == rpc.PendingBlockNumber {
|
||||
block := b.eth.miner.PendingBlock()
|
||||
return block.Header(), nil
|
||||
blockNr = rpc.LatestBlockNumber
|
||||
}
|
||||
// Otherwise resolve and return the block
|
||||
if blockNr == rpc.LatestBlockNumber {
|
||||
|
|
@ -89,8 +88,7 @@ func (b *EthApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNum
|
|||
func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) {
|
||||
// Pending block is only known by the miner
|
||||
if blockNr == rpc.PendingBlockNumber {
|
||||
block := b.eth.miner.PendingBlock()
|
||||
return block, nil
|
||||
blockNr = rpc.LatestBlockNumber
|
||||
}
|
||||
// Otherwise resolve and return the block
|
||||
if blockNr == rpc.LatestBlockNumber {
|
||||
|
|
@ -102,8 +100,7 @@ func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb
|
|||
func (b *EthApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
|
||||
// Pending state is only known by the miner
|
||||
if blockNr == rpc.PendingBlockNumber {
|
||||
block, state := b.eth.miner.Pending()
|
||||
return state, block.Header(), nil
|
||||
blockNr = rpc.LatestBlockNumber
|
||||
}
|
||||
// Otherwise resolve the block number and return its state
|
||||
header, err := b.HeaderByNumber(ctx, blockNr)
|
||||
|
|
|
|||
|
|
@ -21,13 +21,14 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
||||
"github.com/XinFinOrg/XDPoSChain/core"
|
||||
|
|
@ -99,7 +100,7 @@ func (api *PrivateDebugAPI) TraceChain(ctx context.Context, start, end rpc.Block
|
|||
|
||||
switch start {
|
||||
case rpc.PendingBlockNumber:
|
||||
from = api.eth.miner.PendingBlock()
|
||||
from = api.eth.blockchain.CurrentBlock()
|
||||
case rpc.LatestBlockNumber:
|
||||
from = api.eth.blockchain.CurrentBlock()
|
||||
default:
|
||||
|
|
@ -107,7 +108,7 @@ func (api *PrivateDebugAPI) TraceChain(ctx context.Context, start, end rpc.Block
|
|||
}
|
||||
switch end {
|
||||
case rpc.PendingBlockNumber:
|
||||
to = api.eth.miner.PendingBlock()
|
||||
to = api.eth.blockchain.CurrentBlock()
|
||||
case rpc.LatestBlockNumber:
|
||||
to = api.eth.blockchain.CurrentBlock()
|
||||
default:
|
||||
|
|
@ -353,7 +354,7 @@ func (api *PrivateDebugAPI) TraceBlockByNumber(ctx context.Context, number rpc.B
|
|||
|
||||
switch number {
|
||||
case rpc.PendingBlockNumber:
|
||||
block = api.eth.miner.PendingBlock()
|
||||
block = api.eth.blockchain.CurrentBlock()
|
||||
case rpc.LatestBlockNumber:
|
||||
block = api.eth.blockchain.CurrentBlock()
|
||||
default:
|
||||
|
|
@ -514,7 +515,7 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (*
|
|||
break
|
||||
}
|
||||
if statedb, err = state.New(block.Root(), database); err == nil {
|
||||
XDCxState, err = tradingstate.New(block.Root(), tradingstate.NewDatabase(api.eth.XDCX.GetLevelDB()))
|
||||
XDCxState, err = api.eth.blockchain.OrderStateAt(block)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue