Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change option pending block #335

Open
wants to merge 2 commits into
base: archive/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions consensus/posv/posv.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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
Expand Down
7 changes: 7 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ func (bc *BlockChain) OrderStateAt(block *types.Block) (*tradingstate.TradingSta
} else {
return nil, err
}
} else {
tomoxState, err := tomoXService.GetEmptyTradingState()
if err == nil {
return tomoxState, nil
} else {
return nil, err
}
}
}
return nil, errors.New("Get tomox state fail")
Expand Down
6 changes: 1 addition & 5 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,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 {
Expand All @@ -87,8 +86,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 {
Expand All @@ -100,8 +98,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)
Expand Down
8 changes: 4 additions & 4 deletions eth/api_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ 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:
from = api.eth.blockchain.GetBlockByNumber(uint64(start))
}
switch end {
case rpc.PendingBlockNumber:
to = api.eth.miner.PendingBlock()
to = api.eth.blockchain.CurrentBlock()
case rpc.LatestBlockNumber:
to = api.eth.blockchain.CurrentBlock()
default:
Expand Down Expand Up @@ -353,7 +353,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:
Expand Down Expand Up @@ -514,7 +514,7 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (*
break
}
if statedb, err = state.New(block.Root(), database); err == nil {
tomoxState, err = tradingstate.New(block.Root(), tradingstate.NewDatabase(api.eth.TomoX.GetLevelDB()))
tomoxState, err = api.eth.blockchain.OrderStateAt(block)
if err == nil {
break
}
Expand Down
5 changes: 5 additions & 0 deletions tomox/tomox.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ func (tomox *TomoX) GetTradingState(block *types.Block, author common.Address) (
return tradingstate.New(root, tomox.StateCache)
}


func (tomox *TomoX) GetEmptyTradingState() (*tradingstate.TradingStateDB, error) {
return tradingstate.New(tradingstate.EmptyRoot, tomox.StateCache)
}

func (tomox *TomoX) GetStateCache() tradingstate.Database {
return tomox.StateCache
}
Expand Down