mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core/state, trie: Remove Commit() from PersistentMap interface
This commit is contained in:
parent
5b73f9aacd
commit
c4e5dc3bea
4 changed files with 4 additions and 21 deletions
|
|
@ -191,7 +191,7 @@ func (self *StateDB) SetTxContext(blockHash common.Hash, blockNum uint64, txHash
|
||||||
if validator == nil {
|
if validator == nil {
|
||||||
validator = &trie.NullCacheValidator{}
|
validator = &trie.NullCacheValidator{}
|
||||||
}
|
}
|
||||||
storage := trie.NewDirectCache(self.trie, self.db, CachePrefix, &trie.NullCacheValidator{}, true)
|
storage := trie.NewDirectCache(self.trie, self.db, CachePrefix, validator, true)
|
||||||
self.storage = trie.NewSecure(storage, self.db)
|
self.storage = trie.NewSecure(storage, self.db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,10 +159,6 @@ func (dc *DirectCache) TryDelete(key []byte) error {
|
||||||
return dc.data.TryDelete(key)
|
return dc.data.TryDelete(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DirectCache) Commit() (root common.Hash, err error) {
|
|
||||||
return dc.CommitTo(dc.db)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dc *DirectCache) CommitTo(dbw DatabaseWriter) (root common.Hash, err error) {
|
func (dc *DirectCache) CommitTo(dbw DatabaseWriter) (root common.Hash, err error) {
|
||||||
directCacheWrites.Inc(int64(len(dc.dirty)))
|
directCacheWrites.Inc(int64(len(dc.dirty)))
|
||||||
for k, _ := range dc.dirty {
|
for k, _ := range dc.dirty {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ type PersistentMap interface {
|
||||||
TryUpdate(key, value []byte) error
|
TryUpdate(key, value []byte) error
|
||||||
Delete(key []byte)
|
Delete(key []byte)
|
||||||
TryDelete(key []byte) error
|
TryDelete(key []byte) error
|
||||||
Commit() (root common.Hash, err error)
|
|
||||||
CommitTo(db DatabaseWriter) (root common.Hash, err error)
|
CommitTo(db DatabaseWriter) (root common.Hash, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,18 +139,6 @@ func (t *SecureTrie) GetKey(shaKey []byte) []byte {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit writes all nodes and the secure hash pre-images to the database.
|
|
||||||
// Nodes are stored with their sha3 hash as the key.
|
|
||||||
//
|
|
||||||
// Committing flushes nodes from memory. Subsequent Get calls will load nodes
|
|
||||||
// from the database.
|
|
||||||
func (t *SecureTrie) Commit() (root common.Hash, err error) {
|
|
||||||
if err := t.CommitPreimages(); err != nil {
|
|
||||||
return common.Hash{}, err
|
|
||||||
}
|
|
||||||
return t.data.Commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *SecureTrie) Iterator() *Iterator {
|
func (t *SecureTrie) Iterator() *Iterator {
|
||||||
return t.data.Iterator()
|
return t.data.Iterator()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func makeTestSecureTrie() (ethdb.Database, *SecureTrie, map[string][]byte) {
|
||||||
trie.Update(key, val)
|
trie.Update(key, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trie.Commit()
|
trie.CommitTo(db)
|
||||||
|
|
||||||
// Return the generated trie
|
// Return the generated trie
|
||||||
return db, trie, content
|
return db, trie, content
|
||||||
|
|
@ -110,7 +110,7 @@ func TestSecureGetKey(t *testing.T) {
|
||||||
|
|
||||||
func TestSecureTrieConcurrency(t *testing.T) {
|
func TestSecureTrieConcurrency(t *testing.T) {
|
||||||
// Create an initial trie and copy if for concurrent access
|
// Create an initial trie and copy if for concurrent access
|
||||||
_, trie, _ := makeTestSecureTrie()
|
db, trie, _ := makeTestSecureTrie()
|
||||||
|
|
||||||
threads := runtime.NumCPU()
|
threads := runtime.NumCPU()
|
||||||
tries := make([]*SecureTrie, threads)
|
tries := make([]*SecureTrie, threads)
|
||||||
|
|
@ -139,7 +139,7 @@ func TestSecureTrieConcurrency(t *testing.T) {
|
||||||
tries[index].Update(key, val)
|
tries[index].Update(key, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tries[index].Commit()
|
tries[index].CommitTo(db)
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
// Wait for all threads to finish
|
// Wait for all threads to finish
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue