mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
eth, internal: Implement using trie diffs
This commit is contained in:
parent
0dbf55d478
commit
7df396d9ce
2 changed files with 42 additions and 0 deletions
30
eth/api.go
30
eth/api.go
|
|
@ -636,3 +636,33 @@ func storageRangeAt(st state.Trie, start []byte, maxResult int) StorageRangeResu
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *PrivateDebugAPI) GetDirtyAccountsByNumber(startNum, endNum uint64) ([]common.Address, error) {
|
||||||
|
return api.getDirtyAccounts(api.eth.blockchain.GetBlockByNumber(startNum), api.eth.blockchain.GetBlockByNumber(endNum))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *PrivateDebugAPI) GetDirtyAccountsByHash(startHash, endHash common.Hash) ([]common.Address, error) {
|
||||||
|
return api.getDirtyAccounts(
|
||||||
|
api.eth.blockchain.GetBlockByHash(startHash),
|
||||||
|
api.eth.blockchain.GetBlockByHash(endHash))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *PrivateDebugAPI) getDirtyAccounts(startBlock, endBlock *types.Block) ([]common.Address, error) {
|
||||||
|
oldTrie, err := trie.NewSecure(startBlock.Root(), api.eth.chainDb, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
newTrie, err := trie.NewSecure(endBlock.Root(), api.eth.chainDb, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
diff, _ := trie.NewDifferenceIterator(oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}))
|
||||||
|
iter := trie.NewIterator(diff)
|
||||||
|
var dirty []common.Address
|
||||||
|
for iter.Next() {
|
||||||
|
dirty = append(dirty, common.BytesToAddress(newTrie.GetKey(iter.Key)))
|
||||||
|
}
|
||||||
|
return dirty, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -354,6 +354,18 @@ web3._extend({
|
||||||
call: 'debug_storageRangeAt',
|
call: 'debug_storageRangeAt',
|
||||||
params: 5,
|
params: 5,
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'getDirtyAccountsByNumber',
|
||||||
|
call: 'debug_getDirtyAccountsByNumber',
|
||||||
|
params: 2,
|
||||||
|
inputFormatter: [null, null],
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'getDirtyAccountsByHash',
|
||||||
|
call: 'debug_getDirtyAccountsByHash',
|
||||||
|
params: 2,
|
||||||
|
inputFormatter:[web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputAddressFormatter],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
properties: []
|
properties: []
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue