mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
use header to avoid getting the whole block from db
This commit is contained in:
parent
fc2ba1fb2e
commit
255ee2aa9b
1 changed files with 25 additions and 25 deletions
|
|
@ -271,26 +271,26 @@ func storageRangeAt(statedb *state.StateDB, root common.Hash, address common.Add
|
||||||
//
|
//
|
||||||
// With one parameter, returns the list of accounts modified in the specified block.
|
// With one parameter, returns the list of accounts modified in the specified block.
|
||||||
func (api *DebugAPI) GetModifiedAccountsByNumber(startNum uint64, endNum *uint64) ([]common.Address, error) {
|
func (api *DebugAPI) GetModifiedAccountsByNumber(startNum uint64, endNum *uint64) ([]common.Address, error) {
|
||||||
var startBlock, endBlock *types.Block
|
var startHeader, endHeader *types.Header
|
||||||
|
|
||||||
startBlock = api.eth.blockchain.GetBlockByNumber(startNum)
|
startHeader = api.eth.blockchain.GetHeaderByNumber(startNum)
|
||||||
if startBlock == nil {
|
if startHeader == nil {
|
||||||
return nil, fmt.Errorf("start block %x not found", startNum)
|
return nil, fmt.Errorf("start block %x not found", startNum)
|
||||||
}
|
}
|
||||||
|
|
||||||
if endNum == nil {
|
if endNum == nil {
|
||||||
endBlock = startBlock
|
endHeader = startHeader
|
||||||
startBlock = api.eth.blockchain.GetBlockByHash(startBlock.ParentHash())
|
startHeader = api.eth.blockchain.GetHeaderByHash(startHeader.ParentHash)
|
||||||
if startBlock == nil {
|
if startHeader == nil {
|
||||||
return nil, fmt.Errorf("block %x has no parent", endBlock.Number())
|
return nil, fmt.Errorf("block %x has no parent", endHeader.Number)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
endBlock = api.eth.blockchain.GetBlockByNumber(*endNum)
|
endHeader = api.eth.blockchain.GetHeaderByNumber(*endNum)
|
||||||
if endBlock == nil {
|
if endHeader == nil {
|
||||||
return nil, fmt.Errorf("end block %d not found", *endNum)
|
return nil, fmt.Errorf("end block %d not found", *endNum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return api.getModifiedAccounts(startBlock, endBlock)
|
return api.getModifiedAccounts(startHeader, endHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetModifiedAccountsByHash returns all accounts that have changed between the
|
// GetModifiedAccountsByHash returns all accounts that have changed between the
|
||||||
|
|
@ -299,38 +299,38 @@ func (api *DebugAPI) GetModifiedAccountsByNumber(startNum uint64, endNum *uint64
|
||||||
//
|
//
|
||||||
// With one parameter, returns the list of accounts modified in the specified block.
|
// With one parameter, returns the list of accounts modified in the specified block.
|
||||||
func (api *DebugAPI) GetModifiedAccountsByHash(startHash common.Hash, endHash *common.Hash) ([]common.Address, error) {
|
func (api *DebugAPI) GetModifiedAccountsByHash(startHash common.Hash, endHash *common.Hash) ([]common.Address, error) {
|
||||||
var startBlock, endBlock *types.Block
|
var startHeader, endHeader *types.Header
|
||||||
startBlock = api.eth.blockchain.GetBlockByHash(startHash)
|
startHeader = api.eth.blockchain.GetHeaderByHash(startHash)
|
||||||
if startBlock == nil {
|
if startHeader == nil {
|
||||||
return nil, fmt.Errorf("start block %x not found", startHash)
|
return nil, fmt.Errorf("start block %x not found", startHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
if endHash == nil {
|
if endHash == nil {
|
||||||
endBlock = startBlock
|
endHeader = startHeader
|
||||||
startBlock = api.eth.blockchain.GetBlockByHash(startBlock.ParentHash())
|
startHeader = api.eth.blockchain.GetHeaderByHash(startHeader.ParentHash)
|
||||||
if startBlock == nil {
|
if startHeader == nil {
|
||||||
return nil, fmt.Errorf("block %x has no parent", endBlock.Number())
|
return nil, fmt.Errorf("block %x has no parent", endHeader.Number)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
endBlock = api.eth.blockchain.GetBlockByHash(*endHash)
|
endHeader = api.eth.blockchain.GetHeaderByHash(*endHash)
|
||||||
if endBlock == nil {
|
if endHeader == nil {
|
||||||
return nil, fmt.Errorf("end block %x not found", *endHash)
|
return nil, fmt.Errorf("end block %x not found", *endHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return api.getModifiedAccounts(startBlock, endBlock)
|
return api.getModifiedAccounts(startHeader, endHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *DebugAPI) getModifiedAccounts(startBlock, endBlock *types.Block) ([]common.Address, error) {
|
func (api *DebugAPI) getModifiedAccounts(startHeader, endHeader *types.Header) ([]common.Address, error) {
|
||||||
if startBlock.Number().Uint64() >= endBlock.Number().Uint64() {
|
if startHeader.Number.Uint64() >= endHeader.Number.Uint64() {
|
||||||
return nil, fmt.Errorf("start block height (%d) must be less than end block height (%d)", startBlock.Number().Uint64(), endBlock.Number().Uint64())
|
return nil, fmt.Errorf("start block height (%d) must be less than end block height (%d)", startHeader.Number.Uint64(), endHeader.Number.Uint64())
|
||||||
}
|
}
|
||||||
triedb := api.eth.BlockChain().TrieDB()
|
triedb := api.eth.BlockChain().TrieDB()
|
||||||
|
|
||||||
oldTrie, err := trie.NewStateTrie(trie.StateTrieID(startBlock.Root()), triedb)
|
oldTrie, err := trie.NewStateTrie(trie.StateTrieID(startHeader.Root), triedb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
newTrie, err := trie.NewStateTrie(trie.StateTrieID(endBlock.Root()), triedb)
|
newTrie, err := trie.NewStateTrie(trie.StateTrieID(endHeader.Root), triedb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue