aboutsummaryrefslogtreecommitdiffstats
path: root/light/trie.go
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-10-14 11:47:09 +0800
committerFelix Lange <fjl@twurst.com>2016-11-09 09:12:53 +0800
commit760fd65487614b7a61443cd9371015925795f40f (patch)
treea2b122f03b7782e729be85b136f4c5304a164c9e /light/trie.go
parent8b1df1a259fe6dc4c15e391e9c0762c9621d9d72 (diff)
downloadgo-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar
go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.gz
go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.bz2
go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.lz
go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.xz
go-tangerine-760fd65487614b7a61443cd9371015925795f40f.tar.zst
go-tangerine-760fd65487614b7a61443cd9371015925795f40f.zip
light: light chain, VM env and tx pool
Diffstat (limited to 'light/trie.go')
-rw-r--r--light/trie.go25
1 files changed, 12 insertions, 13 deletions
diff --git a/light/trie.go b/light/trie.go
index 42a943d50..c5525358a 100644
--- a/light/trie.go
+++ b/light/trie.go
@@ -17,7 +17,6 @@
package light
import (
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
"golang.org/x/net/context"
@@ -25,28 +24,28 @@ import (
// LightTrie is an ODR-capable wrapper around trie.SecureTrie
type LightTrie struct {
- trie *trie.SecureTrie
- originalRoot common.Hash
- odr OdrBackend
- db ethdb.Database
+ trie *trie.SecureTrie
+ id *TrieID
+ odr OdrBackend
+ db ethdb.Database
}
// NewLightTrie creates a new LightTrie instance. It doesn't instantly try to
// access the db or network and retrieve the root node, it only initializes its
// encapsulated SecureTrie at the first actual operation.
-func NewLightTrie(root common.Hash, odr OdrBackend, useFakeMap bool) *LightTrie {
+func NewLightTrie(id *TrieID, odr OdrBackend, useFakeMap bool) *LightTrie {
return &LightTrie{
// SecureTrie is initialized before first request
- originalRoot: root,
- odr: odr,
- db: odr.Database(),
+ id: id,
+ odr: odr,
+ db: odr.Database(),
}
}
// retrieveKey retrieves a single key, returns true and stores nodes in local
// database if successful
func (t *LightTrie) retrieveKey(ctx context.Context, key []byte) bool {
- r := &TrieRequest{root: t.originalRoot, key: key}
+ r := &TrieRequest{Id: t.id, Key: key}
return t.odr.Retrieve(ctx, r) == nil
}
@@ -79,7 +78,7 @@ func (t *LightTrie) do(ctx context.Context, fallbackKey []byte, fn func() error)
func (t *LightTrie) Get(ctx context.Context, key []byte) (res []byte, err error) {
err = t.do(ctx, key, func() (err error) {
if t.trie == nil {
- t.trie, err = trie.NewSecure(t.originalRoot, t.db, 0)
+ t.trie, err = trie.NewSecure(t.id.Root, t.db, 0)
}
if err == nil {
res, err = t.trie.TryGet(key)
@@ -98,7 +97,7 @@ func (t *LightTrie) Get(ctx context.Context, key []byte) (res []byte, err error)
func (t *LightTrie) Update(ctx context.Context, key, value []byte) (err error) {
err = t.do(ctx, key, func() (err error) {
if t.trie == nil {
- t.trie, err = trie.NewSecure(t.originalRoot, t.db, 0)
+ t.trie, err = trie.NewSecure(t.id.Root, t.db, 0)
}
if err == nil {
err = t.trie.TryUpdate(key, value)
@@ -112,7 +111,7 @@ func (t *LightTrie) Update(ctx context.Context, key, value []byte) (err error) {
func (t *LightTrie) Delete(ctx context.Context, key []byte) (err error) {
err = t.do(ctx, key, func() (err error) {
if t.trie == nil {
- t.trie, err = trie.NewSecure(t.originalRoot, t.db, 0)
+ t.trie, err = trie.NewSecure(t.id.Root, t.db, 0)
}
if err == nil {
err = t.trie.TryDelete(key)