aboutsummaryrefslogtreecommitdiffstats
path: root/light/nodeset.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-02-11 20:57:46 +0800
committerGitHub <noreply@github.com>2018-02-11 20:57:46 +0800
commit7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa (patch)
tree98bc8333d5672cd4faa6a13c9a59f902c277955f /light/nodeset.go
parent5cf75a30c1ceb0ab35cd6b0532520d556996b21c (diff)
downloadgo-tangerine-7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa.tar
go-tangerine-7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa.tar.gz
go-tangerine-7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa.tar.bz2
go-tangerine-7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa.tar.lz
go-tangerine-7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa.tar.xz
go-tangerine-7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa.tar.zst
go-tangerine-7a0019c63b1297cb5c9a6fdfc4cb00fdae9b05aa.zip
les, light: fix CHT trie retrievals (#16039)
* les, light: fix CHT trie retrievals * les, light: minor polishes, test remote CHT retrievals * les, light: deterministic nodeset rlp, bloombits test skeleton * les: add an event emission to the les bloombits test * les: drop dead tester code
Diffstat (limited to 'light/nodeset.go')
-rw-r--r--light/nodeset.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/light/nodeset.go b/light/nodeset.go
index ffdb71bb7..245b5eb76 100644
--- a/light/nodeset.go
+++ b/light/nodeset.go
@@ -29,7 +29,9 @@ import (
// NodeSet stores a set of trie nodes. It implements trie.Database and can also
// act as a cache for another trie.Database.
type NodeSet struct {
- db map[string][]byte
+ nodes map[string][]byte
+ order []string
+
dataSize int
lock sync.RWMutex
}
@@ -37,7 +39,7 @@ type NodeSet struct {
// NewNodeSet creates an empty node set
func NewNodeSet() *NodeSet {
return &NodeSet{
- db: make(map[string][]byte),
+ nodes: make(map[string][]byte),
}
}
@@ -46,10 +48,15 @@ func (db *NodeSet) Put(key []byte, value []byte) error {
db.lock.Lock()
defer db.lock.Unlock()
- if _, ok := db.db[string(key)]; !ok {
- db.db[string(key)] = common.CopyBytes(value)
- db.dataSize += len(value)
+ if _, ok := db.nodes[string(key)]; ok {
+ return nil
}
+ keystr := string(key)
+
+ db.nodes[keystr] = common.CopyBytes(value)
+ db.order = append(db.order, keystr)
+ db.dataSize += len(value)
+
return nil
}
@@ -58,7 +65,7 @@ func (db *NodeSet) Get(key []byte) ([]byte, error) {
db.lock.RLock()
defer db.lock.RUnlock()
- if entry, ok := db.db[string(key)]; ok {
+ if entry, ok := db.nodes[string(key)]; ok {
return entry, nil
}
return nil, errors.New("not found")
@@ -75,7 +82,7 @@ func (db *NodeSet) KeyCount() int {
db.lock.RLock()
defer db.lock.RUnlock()
- return len(db.db)
+ return len(db.nodes)
}
// DataSize returns the aggregated data size of nodes in the set
@@ -92,8 +99,8 @@ func (db *NodeSet) NodeList() NodeList {
defer db.lock.RUnlock()
var values NodeList
- for _, value := range db.db {
- values = append(values, value)
+ for _, key := range db.order {
+ values = append(values, db.nodes[key])
}
return values
}
@@ -103,7 +110,7 @@ func (db *NodeSet) Store(target ethdb.Putter) {
db.lock.RLock()
defer db.lock.RUnlock()
- for key, value := range db.db {
+ for key, value := range db.nodes {
target.Put([]byte(key), value)
}
}