Skip to content

Commit

Permalink
state at block number
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera committed Jul 20, 2023
1 parent 90866dc commit 5dba0ba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ func (bc *BlockChain) StateAt(root common.Hash) (state.StateDBI, error) {
return state.New(root, bc.stateCache, bc.snaps)
}

// StateAtHeader returns a new mutable state based on a particular block header in time.
func (bc *BlockChain) StateAtHeader(header *types.Header) (state.StateDBI, error) {
return bc.StateAt(header.Root)
// StateAtBlockNumber returns a new mutable state based on a particular block number.
func (bc *BlockChain) StateAtBlockNumber(number uint64) (state.StateDBI, error) {
return bc.StateAt(bc.GetHeaderByNumber(number).Root)
}

// Config retrieves the chain's fork configuration.
Expand Down
5 changes: 2 additions & 3 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ type blockChain interface {
CurrentBlock() *types.Header
GetBlock(hash common.Hash, number uint64) *types.Block
StateAt(root common.Hash) (state.StateDBI, error)
StateAtHeader(header *types.Header) (state.StateDBI, error)

StateAtBlockNumber(uint64) (state.StateDBI, error)
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
}

Expand Down Expand Up @@ -1381,7 +1380,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
}
statedb, err := pool.chain.StateAt(newHead.Root)
if err != nil {
statedb, err = pool.chain.StateAtHeader(newHead)
statedb, err = pool.chain.StateAtBlockNumber(newHead.Number.Uint64())
if err != nil {
log.Error("Failed to reset txpool state", "err", err)
return
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (bc *testBlockChain) StateAt(common.Hash) (state.StateDBI, error) {
return bc.statedb, nil
}

func (bc *testBlockChain) StateAtHeader(*types.Header) (state.StateDBI, error) {
func (bc *testBlockChain) StateAtBlockNumber(uint64) (state.StateDBI, error) {
return bc.statedb, nil
}

Expand Down
2 changes: 1 addition & 1 deletion miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (bc *testBlockChain) StateAt(common.Hash) (state.StateDBI, error) {
return bc.statedb, nil
}

func (bc *testBlockChain) StateAtHeader(*types.Header) (state.StateDBI, error) {
func (bc *testBlockChain) StateAtBlockNumber(uint64) (state.StateDBI, error) {
return bc.statedb, nil
}

Expand Down

0 comments on commit 5dba0ba

Please sign in to comment.