Compare commits
9 Commits
versa_perf
...
versa_perf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffa6c04478 | ||
|
|
7bf93179b9 | ||
|
|
37b942eb2c | ||
|
|
2fbd77d64c | ||
|
|
46f6c75cc0 | ||
|
|
7a0d393c0d | ||
|
|
ed573ee1a8 | ||
|
|
6252589246 | ||
|
|
5271bf9bdb |
@@ -415,6 +415,10 @@ func (vt *VersaTree) UpdateAccount(address common.Address, account *types.StateA
|
|||||||
return vt.db.Put(vt.handler, address.Bytes(), data)
|
return vt.db.Put(vt.handler, address.Bytes(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vt *VersaTree) WriteBatch(values map[string][]byte) error {
|
||||||
|
return vt.db.WriteBatch(vt.handler, values)
|
||||||
|
}
|
||||||
|
|
||||||
func (vt *VersaTree) UpdateStorage(address common.Address, key, value []byte) error {
|
func (vt *VersaTree) UpdateStorage(address common.Address, key, value []byte) error {
|
||||||
if vt.address.Cmp(address) != 0 {
|
if vt.address.Cmp(address) != 0 {
|
||||||
panic(fmt.Sprintf("address mismatch in get storage, expect: %s, actul: %s", vt.address.String(), address.String()))
|
panic(fmt.Sprintf("address mismatch in get storage, expect: %s, actul: %s", vt.address.String(), address.String()))
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ type Trie interface {
|
|||||||
// to be moved to the stateWriter interface when the latter is ready.
|
// to be moved to the stateWriter interface when the latter is ready.
|
||||||
UpdateContractCode(address common.Address, codeHash common.Hash, code []byte) error
|
UpdateContractCode(address common.Address, codeHash common.Hash, code []byte) error
|
||||||
|
|
||||||
|
WriteBatch(values map[string][]byte) error
|
||||||
|
|
||||||
// Hash returns the root hash of the trie. It does not write to the database and
|
// Hash returns the root hash of the trie. It does not write to the database and
|
||||||
// can be used even if the trie doesn't have one.
|
// can be used even if the trie doesn't have one.
|
||||||
Hash() common.Hash
|
Hash() common.Hash
|
||||||
|
|||||||
@@ -417,11 +417,14 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
|||||||
}
|
}
|
||||||
dirtyStorage[key] = v
|
dirtyStorage[key] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//storages := make(map[string][]byte)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for key, value := range dirtyStorage {
|
for key, value := range dirtyStorage {
|
||||||
|
//TODO:: add version schema check
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
||||||
s.db.setError(err)
|
s.db.setError(err)
|
||||||
@@ -433,6 +436,16 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
|||||||
}
|
}
|
||||||
s.db.StorageUpdated += 1
|
s.db.StorageUpdated += 1
|
||||||
}
|
}
|
||||||
|
//if len(value) == 0 {
|
||||||
|
// storages[string(key[:])] = nil
|
||||||
|
//} else {
|
||||||
|
// v, _ := rlp.EncodeToBytes(value)
|
||||||
|
// storages[string(key[:])] = v
|
||||||
|
//}
|
||||||
|
//if err := tr.WriteBatch(storages); err != nil {
|
||||||
|
// s.db.setError(err)
|
||||||
|
//}
|
||||||
|
|
||||||
// Cache the items for preloading
|
// Cache the items for preloading
|
||||||
usedStorage = append(usedStorage, common.CopyBytes(key[:]))
|
usedStorage = append(usedStorage, common.CopyBytes(key[:]))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
@@ -693,6 +692,7 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
|
|||||||
if err := s.trie.UpdateAccount(addr, &obj.data); err != nil {
|
if err := s.trie.UpdateAccount(addr, &obj.data); err != nil {
|
||||||
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
|
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.dirtyCode {
|
if obj.dirtyCode {
|
||||||
s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
|
s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
|
||||||
}
|
}
|
||||||
@@ -720,6 +720,7 @@ func (s *StateDB) deleteStateObject(obj *stateObject) {
|
|||||||
}
|
}
|
||||||
// Delete the account from the trie
|
// Delete the account from the trie
|
||||||
addr := obj.Address()
|
addr := obj.Address()
|
||||||
|
|
||||||
if err := s.trie.DeleteAccount(addr); err != nil {
|
if err := s.trie.DeleteAccount(addr); err != nil {
|
||||||
s.setError(fmt.Errorf("deleteStateObject (%x) error: %v", addr[:], err))
|
s.setError(fmt.Errorf("deleteStateObject (%x) error: %v", addr[:], err))
|
||||||
}
|
}
|
||||||
@@ -1217,7 +1218,6 @@ func (s *StateDB) AccountsIntermediateRoot() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
var calcStateObjectCount atomic.Int64
|
|
||||||
// Although naively it makes sense to retrieve the account trie and then do
|
// Although naively it makes sense to retrieve the account trie and then do
|
||||||
// the contract storage and account updates sequentially, that short circuits
|
// the contract storage and account updates sequentially, that short circuits
|
||||||
// the account prefetcher. Instead, let's process all the storage updates
|
// the account prefetcher. Instead, let's process all the storage updates
|
||||||
@@ -1228,9 +1228,6 @@ func (s *StateDB) AccountsIntermediateRoot() {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
tasks <- func() {
|
tasks <- func() {
|
||||||
obj.updateRoot()
|
obj.updateRoot()
|
||||||
if obj.trie != nil {
|
|
||||||
calcStateObjectCount.Add(1)
|
|
||||||
}
|
|
||||||
// Cache the data until commit. Note, this update mechanism is not symmetric
|
// Cache the data until commit. Note, this update mechanism is not symmetric
|
||||||
// to the deletion, because whereas it is enough to track account updates
|
// to the deletion, because whereas it is enough to track account updates
|
||||||
// at commit time, deletions need tracking at transaction boundary level to
|
// at commit time, deletions need tracking at transaction boundary level to
|
||||||
@@ -1244,7 +1241,6 @@ func (s *StateDB) AccountsIntermediateRoot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
log.Info("versa calc root state object", "count", calcStateObjectCount.Load(), "version", s.db.GetVersion()+1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateDB) StateIntermediateRoot() common.Hash {
|
func (s *StateDB) StateIntermediateRoot() common.Hash {
|
||||||
@@ -1625,7 +1621,6 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
var committedStateObjectNum atomic.Int64
|
|
||||||
for addr := range s.stateObjectsDirty {
|
for addr := range s.stateObjectsDirty {
|
||||||
if obj := s.stateObjects[addr]; !obj.deleted {
|
if obj := s.stateObjects[addr]; !obj.deleted {
|
||||||
tasks <- func() {
|
tasks <- func() {
|
||||||
@@ -1635,9 +1630,6 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
|
|||||||
taskResults <- taskResult{err, nil}
|
taskResults <- taskResult{err, nil}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if obj.trie != nil {
|
|
||||||
committedStateObjectNum.Add(1)
|
|
||||||
}
|
|
||||||
taskResults <- taskResult{nil, set}
|
taskResults <- taskResult{nil, set}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1720,7 +1712,6 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
log.Info("versa commit state object", "count", committedStateObjectNum.Load(), "version", s.db.GetVersion()+1)
|
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ func NewEmptyTrie() *EmptyTrie {
|
|||||||
return &EmptyTrie{}
|
return &EmptyTrie{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *EmptyTrie) WriteBatch(values map[string][]byte) error {
|
||||||
|
panic("EmptyTrie not support WriteBatch")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *EmptyTrie) GetKey(shaKey []byte) []byte {
|
func (t *EmptyTrie) GetKey(shaKey []byte) []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,11 @@ func NewStateTrie(id *ID, db database.Database) (*StateTrie, error) {
|
|||||||
return &StateTrie{trie: *trie, db: db}, nil
|
return &StateTrie{trie: *trie, db: db}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *StateTrie) WriteBatch(values map[string][]byte) error {
|
||||||
|
panic("StateTrie not support WriteBatch")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// MustGet returns the value for key stored in the trie.
|
// MustGet returns the value for key stored in the trie.
|
||||||
// The value bytes must not be modified by the caller.
|
// The value bytes must not be modified by the caller.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ func NewVerkleTrie(root common.Hash, db database.Database, cache *utils.PointCac
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *VerkleTrie) WriteBatch(values map[string][]byte) error {
|
||||||
|
panic("VerkleTrie not support WriteBatch")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetKey returns the sha3 preimage of a hashed key that was previously used
|
// GetKey returns the sha3 preimage of a hashed key that was previously used
|
||||||
// to store a value.
|
// to store a value.
|
||||||
func (t *VerkleTrie) GetKey(key []byte) []byte {
|
func (t *VerkleTrie) GetKey(key []byte) []byte {
|
||||||
|
|||||||
@@ -22,28 +22,22 @@ type VersionDB struct {
|
|||||||
|
|
||||||
func New(config *Config) *VersionDB {
|
func New(config *Config) *VersionDB {
|
||||||
var (
|
var (
|
||||||
cfg *versa.VersaDBConfig
|
//cfg *versa.VersaDBConfig
|
||||||
path = "./node/version_db" // TODO:: debug code
|
path = "./node/version_db" // TODO:: debug code
|
||||||
)
|
)
|
||||||
|
|
||||||
if config != nil {
|
//if config != nil {
|
||||||
path = config.Path
|
// path = config.Path
|
||||||
cfg = &versa.VersaDBConfig{
|
// cfg = &versa.VersaDBConfig{
|
||||||
FlushInterval: 2000,
|
// FlushInterval: 2000,
|
||||||
MaxStatesInMem: 128,
|
// MaxStatesInMem: 128,
|
||||||
MemLowWaterMark: 40,
|
// MemLowWaterMark: 10,
|
||||||
MemHighWaterMark: 60,
|
// MemHighWaterMark: 20,
|
||||||
MemEvictInternal: 200,
|
// MemEvictInternal: 200,
|
||||||
}
|
// }
|
||||||
_ = cfg
|
// _ = cfg
|
||||||
}
|
//}
|
||||||
db, err := versa.NewVersaDB(path, &versa.VersaDBConfig{
|
db, err := versa.NewVersaDB(path, &versa.VersaDBConfig{})
|
||||||
FlushInterval: 2000,
|
|
||||||
MaxStatesInMem: 128,
|
|
||||||
MemLowWaterMark: 40,
|
|
||||||
MemHighWaterMark: 60,
|
|
||||||
MemEvictInternal: 200,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("failed to new version db", "error", err)
|
log.Crit("failed to new version db", "error", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user