mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
expose GetWitness endpoint on Trie objects
This commit is contained in:
parent
e8f7ecb857
commit
2530c4a3e6
6 changed files with 26 additions and 2 deletions
|
|
@ -75,6 +75,8 @@ type Trie interface {
|
||||||
// a trie.MissingNodeError is returned.
|
// a trie.MissingNodeError is returned.
|
||||||
GetStorage(addr common.Address, key []byte) ([]byte, error)
|
GetStorage(addr common.Address, key []byte) ([]byte, error)
|
||||||
|
|
||||||
|
GetWitness() *trienode.Witness
|
||||||
|
|
||||||
// GetAccount abstracts an account read from the trie. It retrieves the
|
// GetAccount abstracts an account read from the trie. It retrieves the
|
||||||
// account blob from the trie with provided account address and decodes it
|
// account blob from the trie with provided account address and decodes it
|
||||||
// with associated decoding algorithm. If the specified account is not in
|
// with associated decoding algorithm. If the specified account is not in
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,14 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
|
||||||
return sdb, nil
|
return sdb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
|
||||||
|
// state trie concurrently while the state is mutated so that when we reach the
|
||||||
|
// commit phase, most of the needed data is already hot.
|
||||||
|
func (s *StateDB) GetWitness() *trienode.Witness {
|
||||||
|
return s.trie.GetWitness()
|
||||||
|
}
|
||||||
|
|
||||||
// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
|
// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
|
||||||
// state trie concurrently while the state is mutated so that when we reach the
|
// state trie concurrently while the state is mutated so that when we reach the
|
||||||
// commit phase, most of the needed data is already hot.
|
// commit phase, most of the needed data is already hot.
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
|
"github.com/ethereum/go-ethereum/trie/trienode"
|
||||||
"github.com/tyler-smith/go-bip39"
|
"github.com/tyler-smith/go-bip39"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -961,7 +962,7 @@ type RecentBlockHash struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRequiredBlockState returns all state required to execute a single historical block.
|
// GetRequiredBlockState returns all state required to execute a single historical block.
|
||||||
func (s *BlockChainAPI) GetRequiredBlockState(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*txTraceResult, error) {
|
func (s *BlockChainAPI) GetRequiredBlockState(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*trienode.Witness, error) {
|
||||||
block, err := s.b.BlockByNumberOrHash(ctx, blockNrOrHash)
|
block, err := s.b.BlockByNumberOrHash(ctx, blockNrOrHash)
|
||||||
if block == nil || err != nil {
|
if block == nil || err != nil {
|
||||||
// When the block doesn't exist, the RPC method should return JSON null
|
// When the block doesn't exist, the RPC method should return JSON null
|
||||||
|
|
@ -972,7 +973,8 @@ func (s *BlockChainAPI) GetRequiredBlockState(ctx context.Context, blockNrOrHash
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
s.ProcessBlock(ctx, block, state, vm.Config{})
|
s.ProcessBlock(ctx, block, state, vm.Config{})
|
||||||
return s.traceBlock(ctx, block)
|
return state.GetWitness(), nil
|
||||||
|
// return s.traceBlock(ctx, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
// txTraceResult is the result of a single transaction trace.
|
// txTraceResult is the result of a single transaction trace.
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,10 @@ type odrTrie struct {
|
||||||
trie *trie.Trie
|
trie *trie.Trie
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *odrTrie) GetWitness() *trienode.Witness {
|
||||||
|
return t.trie.GetWitness()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *odrTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
func (t *odrTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||||
key = crypto.Keccak256(key)
|
key = crypto.Keccak256(key)
|
||||||
var enc []byte
|
var enc []byte
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,10 @@ func (t *StateTrie) MustGet(key []byte) []byte {
|
||||||
return t.trie.MustGet(t.hashKey(key))
|
return t.trie.MustGet(t.hashKey(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *StateTrie) GetWitness() *trienode.Witness {
|
||||||
|
return t.trie.GetWitness()
|
||||||
|
}
|
||||||
|
|
||||||
// GetStorage attempts to retrieve a storage slot with provided account address
|
// GetStorage attempts to retrieve a storage slot with provided account address
|
||||||
// and slot key. The value bytes must not be modified by the caller.
|
// and slot key. The value bytes must not be modified by the caller.
|
||||||
// If the specified storage slot is not in the trie, nil will be returned.
|
// If the specified storage slot is not in the trie, nil will be returned.
|
||||||
|
|
|
||||||
|
|
@ -688,3 +688,7 @@ func (t *Trie) Reset() {
|
||||||
t.witness = trienode.NewWitness(common.Hash{})
|
t.witness = trienode.NewWitness(common.Hash{})
|
||||||
t.committed = false
|
t.committed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Trie) GetWitness() *trienode.Witness {
|
||||||
|
return t.witness
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue