diff --git a/XDCx/XDCx.go b/XDCx/XDCx.go index 9762bf6b50..2a8d9b299a 100644 --- a/XDCx/XDCx.go +++ b/XDCx/XDCx.go @@ -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 diff --git a/consensus/XDPoS/utils/types.go b/consensus/XDPoS/utils/types.go index 754194c728..4f55973cfd 100644 --- a/consensus/XDPoS/utils/types.go +++ b/consensus/XDPoS/utils/types.go @@ -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 diff --git a/core/blockchain.go b/core/blockchain.go index 3088ea62d8..9e4c84f5ca 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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") diff --git a/eth/api.go b/eth/api.go index f6e4232356..9f12db9ec2 100644 --- a/eth/api.go +++ b/eth/api.go @@ -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 { diff --git a/eth/api_backend.go b/eth/api_backend.go index e7c102f67e..9285afbac5 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -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) diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 752a92bd3e..aa4d74b7b2 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -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 }