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

core/state: simplify proof methods #17965

Merged
merged 1 commit into from
Oct 23, 2018
Merged
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
20 changes: 13 additions & 7 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
Expand All @@ -46,6 +45,13 @@ var (
emptyCode = crypto.Keccak256Hash(nil)
)

type proofList [][]byte

func (n *proofList) Put(key []byte, value []byte) error {
*n = append(*n, value)
return nil
}

// StateDBs within the ethereum protocol are used to store anything
// within the merkle trie. StateDBs take care of caching and storing
// nested states. It's the general query interface to retrieve:
Expand Down Expand Up @@ -259,21 +265,21 @@ func (self *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash
}

// GetProof returns the MerkleProof for a given Account
func (self *StateDB) GetProof(a common.Address) (vm.ProofList, error) {
var proof vm.ProofList
func (self *StateDB) GetProof(a common.Address) ([][]byte, error) {
var proof proofList
err := self.trie.Prove(crypto.Keccak256(a.Bytes()), 0, &proof)
return proof, err
return [][]byte(proof), err
}

// GetProof returns the StorageProof for given key
func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) (vm.ProofList, error) {
var proof vm.ProofList
func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error) {
var proof proofList
trie := self.StorageTrie(a)
if trie == nil {
return proof, errors.New("storage trie for requested address does not exist")
}
err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
return proof, err
return [][]byte(proof), err
}

// GetCommittedState retrieves a value from the given account's committed storage trie.
Expand Down
10 changes: 0 additions & 10 deletions core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type StateDB interface {
SetNonce(common.Address, uint64)

GetCodeHash(common.Address) common.Hash
GetProof(common.Address) (ProofList, error)
GetStorageProof(common.Address, common.Hash) (ProofList, error)
GetCode(common.Address) []byte
SetCode(common.Address, []byte)
GetCodeSize(common.Address) int
Expand Down Expand Up @@ -80,11 +78,3 @@ type CallContext interface {
// Create a new contract
Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
}

// MerkleProof
type ProofList [][]byte

func (n *ProofList) Put(key []byte, value []byte) error {
*n = append(*n, value)
return nil
}