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)
|
||||
}
|
||||
|
||||
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 {
|
||||
if vt.address.Cmp(address) != 0 {
|
||||
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.
|
||||
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
|
||||
// can be used even if the trie doesn't have one.
|
||||
Hash() common.Hash
|
||||
|
||||
@@ -417,11 +417,14 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
||||
}
|
||||
dirtyStorage[key] = v
|
||||
}
|
||||
|
||||
//storages := make(map[string][]byte)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for key, value := range dirtyStorage {
|
||||
//TODO:: add version schema check
|
||||
if len(value) == 0 {
|
||||
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
|
||||
s.db.setError(err)
|
||||
@@ -433,6 +436,16 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
||||
}
|
||||
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
|
||||
usedStorage = append(usedStorage, common.CopyBytes(key[:]))
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"runtime"
|
||||
"sort"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"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 {
|
||||
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
|
||||
}
|
||||
|
||||
if obj.dirtyCode {
|
||||
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
|
||||
addr := obj.Address()
|
||||
|
||||
if err := s.trie.DeleteAccount(addr); err != nil {
|
||||
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
|
||||
// the contract storage and account updates sequentially, that short circuits
|
||||
// the account prefetcher. Instead, let's process all the storage updates
|
||||
@@ -1228,9 +1228,6 @@ func (s *StateDB) AccountsIntermediateRoot() {
|
||||
wg.Add(1)
|
||||
tasks <- func() {
|
||||
obj.updateRoot()
|
||||
if obj.trie != nil {
|
||||
calcStateObjectCount.Add(1)
|
||||
}
|
||||
// Cache the data until commit. Note, this update mechanism is not symmetric
|
||||
// to the deletion, because whereas it is enough to track account updates
|
||||
// at commit time, deletions need tracking at transaction boundary level to
|
||||
@@ -1244,7 +1241,6 @@ func (s *StateDB) AccountsIntermediateRoot() {
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
log.Info("versa calc root state object", "count", calcStateObjectCount.Load(), "version", s.db.GetVersion()+1)
|
||||
}
|
||||
|
||||
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 {
|
||||
if obj := s.stateObjects[addr]; !obj.deleted {
|
||||
tasks <- func() {
|
||||
@@ -1635,9 +1630,6 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
|
||||
taskResults <- taskResult{err, nil}
|
||||
return
|
||||
} else {
|
||||
if obj.trie != nil {
|
||||
committedStateObjectNum.Add(1)
|
||||
}
|
||||
taskResults <- taskResult{nil, set}
|
||||
}
|
||||
} else {
|
||||
@@ -1720,7 +1712,6 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
log.Info("versa commit state object", "count", committedStateObjectNum.Load(), "version", s.db.GetVersion()+1)
|
||||
return nil
|
||||
}()
|
||||
|
||||
|
||||
@@ -31,6 +31,11 @@ func NewEmptyTrie() *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 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -73,6 +73,11 @@ func NewStateTrie(id *ID, db database.Database) (*StateTrie, error) {
|
||||
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.
|
||||
// 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
|
||||
}
|
||||
|
||||
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
|
||||
// to store a value.
|
||||
func (t *VerkleTrie) GetKey(key []byte) []byte {
|
||||
|
||||
@@ -22,28 +22,22 @@ type VersionDB struct {
|
||||
|
||||
func New(config *Config) *VersionDB {
|
||||
var (
|
||||
cfg *versa.VersaDBConfig
|
||||
//cfg *versa.VersaDBConfig
|
||||
path = "./node/version_db" // TODO:: debug code
|
||||
)
|
||||
|
||||
if config != nil {
|
||||
path = config.Path
|
||||
cfg = &versa.VersaDBConfig{
|
||||
FlushInterval: 2000,
|
||||
MaxStatesInMem: 128,
|
||||
MemLowWaterMark: 40,
|
||||
MemHighWaterMark: 60,
|
||||
MemEvictInternal: 200,
|
||||
}
|
||||
_ = cfg
|
||||
}
|
||||
db, err := versa.NewVersaDB(path, &versa.VersaDBConfig{
|
||||
FlushInterval: 2000,
|
||||
MaxStatesInMem: 128,
|
||||
MemLowWaterMark: 40,
|
||||
MemHighWaterMark: 60,
|
||||
MemEvictInternal: 200,
|
||||
})
|
||||
//if config != nil {
|
||||
// path = config.Path
|
||||
// cfg = &versa.VersaDBConfig{
|
||||
// FlushInterval: 2000,
|
||||
// MaxStatesInMem: 128,
|
||||
// MemLowWaterMark: 10,
|
||||
// MemHighWaterMark: 20,
|
||||
// MemEvictInternal: 200,
|
||||
// }
|
||||
// _ = cfg
|
||||
//}
|
||||
db, err := versa.NewVersaDB(path, &versa.VersaDBConfig{})
|
||||
if err != nil {
|
||||
log.Crit("failed to new version db", "error", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user