Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into more_chainSimulator_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu authored Feb 21, 2024
2 parents be242d2 + 62305a2 commit 954cedb
Showing 13 changed files with 119 additions and 93 deletions.
1 change: 1 addition & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
@@ -660,6 +660,7 @@
PeerStatePruningEnabled = true
MaxStateTrieLevelInMemory = 5
MaxPeerTrieLevelInMemory = 5
StateStatisticsEnabled = false

[BlockSizeThrottleConfig]
MinSizeInBytes = 104857 # 104857 is 10% from 1MB
10 changes: 5 additions & 5 deletions common/interface.go
Original file line number Diff line number Diff line change
@@ -223,17 +223,17 @@ type StateStatisticsHandler interface {
Reset()
ResetSnapshot()

IncrCache()
IncrementCache()
Cache() uint64
IncrSnapshotCache()
IncrementSnapshotCache()
SnapshotCache() uint64

IncrPersister(epoch uint32)
IncrementPersister(epoch uint32)
Persister(epoch uint32) uint64
IncrSnapshotPersister(epoch uint32)
IncrementSnapshotPersister(epoch uint32)
SnapshotPersister(epoch uint32) uint64

IncrTrie()
IncrementTrie()
Trie() uint64

ProcessingStats() []string
20 changes: 10 additions & 10 deletions common/statistics/disabled/stateStatistics.go
Original file line number Diff line number Diff line change
@@ -19,44 +19,44 @@ func (s *stateStatistics) Reset() {
func (s *stateStatistics) ResetSnapshot() {
}

// IncrCache does nothing
func (s *stateStatistics) IncrCache() {
// IncrementCache does nothing
func (s *stateStatistics) IncrementCache() {
}

// Cache returns zero
func (s *stateStatistics) Cache() uint64 {
return 0
}

// IncrSnapshotCache does nothing
func (ss *stateStatistics) IncrSnapshotCache() {
// IncrementSnapshotCache does nothing
func (ss *stateStatistics) IncrementSnapshotCache() {
}

// SnapshotCache returns the number of cached operations
func (ss *stateStatistics) SnapshotCache() uint64 {
return 0
}

// IncrPersister does nothing
func (s *stateStatistics) IncrPersister(epoch uint32) {
// IncrementPersister does nothing
func (s *stateStatistics) IncrementPersister(epoch uint32) {
}

// Persister returns zero
func (s *stateStatistics) Persister(epoch uint32) uint64 {
return 0
}

// IncrSnapshotPersister does nothing
func (ss *stateStatistics) IncrSnapshotPersister(epoch uint32) {
// IncrementSnapshotPersister does nothing
func (ss *stateStatistics) IncrementSnapshotPersister(epoch uint32) {
}

// SnapshotPersister returns the number of persister operations
func (ss *stateStatistics) SnapshotPersister(epoch uint32) uint64 {
return 0
}

// IncrTrie does nothing
func (s *stateStatistics) IncrTrie() {
// IncrementTrie does nothing
func (s *stateStatistics) IncrementTrie() {
}

// Trie returns zero
12 changes: 6 additions & 6 deletions common/statistics/disabled/stateStatistics_test.go
Original file line number Diff line number Diff line change
@@ -31,12 +31,12 @@ func TestStateStatistics_MethodsShouldNotPanic(t *testing.T) {
stats.ResetSnapshot()
stats.ResetAll()

stats.IncrCache()
stats.IncrSnapshotCache()
stats.IncrSnapshotCache()
stats.IncrPersister(1)
stats.IncrSnapshotPersister(1)
stats.IncrTrie()
stats.IncrementCache()
stats.IncrementSnapshotCache()
stats.IncrementSnapshotCache()
stats.IncrementPersister(1)
stats.IncrementSnapshotPersister(1)
stats.IncrementTrie()

require.Equal(t, uint64(0), stats.Cache())
require.Equal(t, uint64(0), stats.SnapshotCache())
20 changes: 10 additions & 10 deletions common/statistics/stateStatistics.go
Original file line number Diff line number Diff line change
@@ -51,8 +51,8 @@ func (ss *stateStatistics) ResetSnapshot() {
ss.mutPersisters.Unlock()
}

// IncrCache will increment cache counter
func (ss *stateStatistics) IncrCache() {
// IncrementCache will increment cache counter
func (ss *stateStatistics) IncrementCache() {
atomic.AddUint64(&ss.numCache, 1)
}

@@ -61,8 +61,8 @@ func (ss *stateStatistics) Cache() uint64 {
return atomic.LoadUint64(&ss.numCache)
}

// IncrSnapshotCache will increment snapshot cache counter
func (ss *stateStatistics) IncrSnapshotCache() {
// IncrementSnapshotCache will increment snapshot cache counter
func (ss *stateStatistics) IncrementSnapshotCache() {
atomic.AddUint64(&ss.numSnapshotCache, 1)
}

@@ -71,8 +71,8 @@ func (ss *stateStatistics) SnapshotCache() uint64 {
return atomic.LoadUint64(&ss.numSnapshotCache)
}

// IncrPersister will increment persister counter
func (ss *stateStatistics) IncrPersister(epoch uint32) {
// IncrementPersister will increment persister counter
func (ss *stateStatistics) IncrementPersister(epoch uint32) {
ss.mutPersisters.Lock()
defer ss.mutPersisters.Unlock()

@@ -87,8 +87,8 @@ func (ss *stateStatistics) Persister(epoch uint32) uint64 {
return ss.numPersister[epoch]
}

// IncrSnapshotPersister will increment snapshot persister counter
func (ss *stateStatistics) IncrSnapshotPersister(epoch uint32) {
// IncrementSnapshotPersister will increment snapshot persister counter
func (ss *stateStatistics) IncrementSnapshotPersister(epoch uint32) {
ss.mutPersisters.Lock()
defer ss.mutPersisters.Unlock()

@@ -103,8 +103,8 @@ func (ss *stateStatistics) SnapshotPersister(epoch uint32) uint64 {
return ss.numSnapshotPersister[epoch]
}

// IncrTrie will increment trie counter
func (ss *stateStatistics) IncrTrie() {
// IncrementTrie will increment trie counter
func (ss *stateStatistics) IncrementTrie() {
atomic.AddUint64(&ss.numTrie, 1)
}

36 changes: 18 additions & 18 deletions common/statistics/stateStatistics_test.go
Original file line number Diff line number Diff line change
@@ -27,11 +27,11 @@ func TestStateStatistics_Processing(t *testing.T) {

assert.Equal(t, uint64(0), ss.Trie())

ss.IncrTrie()
ss.IncrTrie()
ss.IncrementTrie()
ss.IncrementTrie()
assert.Equal(t, uint64(2), ss.Trie())

ss.IncrTrie()
ss.IncrementTrie()
assert.Equal(t, uint64(3), ss.Trie())

ss.Reset()
@@ -47,11 +47,11 @@ func TestStateStatistics_Processing(t *testing.T) {

assert.Equal(t, uint64(0), ss.Persister(epoch))

ss.IncrPersister(epoch)
ss.IncrPersister(epoch)
ss.IncrementPersister(epoch)
ss.IncrementPersister(epoch)
assert.Equal(t, uint64(2), ss.Persister(epoch))

ss.IncrPersister(epoch)
ss.IncrementPersister(epoch)
assert.Equal(t, uint64(3), ss.Persister(epoch))

ss.Reset()
@@ -65,11 +65,11 @@ func TestStateStatistics_Processing(t *testing.T) {

assert.Equal(t, uint64(0), ss.Cache())

ss.IncrCache()
ss.IncrCache()
ss.IncrementCache()
ss.IncrementCache()
assert.Equal(t, uint64(2), ss.Cache())

ss.IncrCache()
ss.IncrementCache()
assert.Equal(t, uint64(3), ss.Cache())

ss.Reset()
@@ -89,11 +89,11 @@ func TestStateStatistics_Snapshot(t *testing.T) {

assert.Equal(t, uint64(0), ss.SnapshotPersister(epoch))

ss.IncrSnapshotPersister(epoch)
ss.IncrSnapshotPersister(epoch)
ss.IncrementSnapshotPersister(epoch)
ss.IncrementSnapshotPersister(epoch)
assert.Equal(t, uint64(2), ss.SnapshotPersister(epoch))

ss.IncrSnapshotPersister(epoch)
ss.IncrementSnapshotPersister(epoch)
assert.Equal(t, uint64(3), ss.SnapshotPersister(epoch))

ss.ResetSnapshot()
@@ -107,11 +107,11 @@ func TestStateStatistics_Snapshot(t *testing.T) {

assert.Equal(t, uint64(0), ss.Cache())

ss.IncrSnapshotCache()
ss.IncrSnapshotCache()
ss.IncrementSnapshotCache()
ss.IncrementSnapshotCache()
assert.Equal(t, uint64(2), ss.SnapshotCache())

ss.IncrSnapshotCache()
ss.IncrementSnapshotCache()
assert.Equal(t, uint64(3), ss.SnapshotCache())

ss.ResetSnapshot()
@@ -144,11 +144,11 @@ func TestStateStatistics_ConcurrenyOperations(t *testing.T) {
case 0:
ss.Reset()
case 1:
ss.IncrCache()
ss.IncrementCache()
case 2:
ss.IncrPersister(epoch)
ss.IncrementPersister(epoch)
case 3:
ss.IncrTrie()
ss.IncrementTrie()
case 7:
_ = ss.Cache()
case 8:
1 change: 1 addition & 0 deletions state/accountsDB.go
Original file line number Diff line number Diff line change
@@ -785,6 +785,7 @@ func (adb *AccountsDB) CommitInEpoch(currentEpoch uint32, epochToCommit uint32)
adb.mutOp.Lock()
defer func() {
adb.mainTrie.GetStorageManager().SetEpochForPutOperation(currentEpoch)
adb.mainTrie.GetStorageManager().GetStateStatsHandler().Reset()
adb.mutOp.Unlock()
adb.loadCodeMeasurements.resetAndPrint()
}()
8 changes: 4 additions & 4 deletions storage/interface.go
Original file line number Diff line number Diff line change
@@ -216,8 +216,8 @@ type PersisterFactoryHandler interface {

// StateStatsHandler defines the behaviour needed to handler storage statistics
type StateStatsHandler interface {
IncrCache()
IncrSnapshotCache()
IncrPersister(epoch uint32)
IncrSnapshotPersister(epoch uint32)
IncrementCache()
IncrementSnapshotCache()
IncrementPersister(epoch uint32)
IncrementSnapshotPersister(epoch uint32)
}
4 changes: 2 additions & 2 deletions storage/pruning/pruningStorer.go
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ func (ps *PruningStorer) createAndInitPersister(pd *persisterData) (storage.Pers
func (ps *PruningStorer) Get(key []byte) ([]byte, error) {
v, ok := ps.cacher.Get(key)
if ok {
ps.stateStatsHandler.IncrCache()
ps.stateStatsHandler.IncrementCache()
return v.([]byte), nil
}

@@ -457,7 +457,7 @@ func (ps *PruningStorer) Get(key []byte) ([]byte, error) {
// if found in persistence unit, add it to cache and return
_ = ps.cacher.Put(key, val, len(val))

ps.stateStatsHandler.IncrPersister(ps.activePersisters[idx].epoch)
ps.stateStatsHandler.IncrementPersister(ps.activePersisters[idx].epoch)

return val, nil
}
4 changes: 2 additions & 2 deletions storage/pruning/triePruningStorer.go
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ func (ps *triePruningStorer) PutInEpochWithoutCache(key []byte, data []byte, epo
func (ps *triePruningStorer) GetFromOldEpochsWithoutAddingToCache(key []byte) ([]byte, core.OptionalUint32, error) {
v, ok := ps.cacher.Get(key)
if ok && !bytes.Equal([]byte(common.ActiveDBKey), key) {
ps.stateStatsHandler.IncrSnapshotCache()
ps.stateStatsHandler.IncrementSnapshotCache()
return v.([]byte), core.OptionalUint32{}, nil
}

@@ -118,7 +118,7 @@ func (ps *triePruningStorer) GetFromOldEpochsWithoutAddingToCache(key []byte) ([
HasValue: true,
}

ps.stateStatsHandler.IncrSnapshotPersister(epoch.Value)
ps.stateStatsHandler.IncrementSnapshotPersister(epoch.Value)

return val, epoch, nil
}
25 changes: 25 additions & 0 deletions storage/pruning/triePruningStorer_test.go
Original file line number Diff line number Diff line change
@@ -76,6 +76,31 @@ func TestTriePruningStorer_GetFromOldEpochsWithoutCacheSearchesOnlyOldEpochsAndR
assert.True(t, strings.Contains(err.Error(), "not found"))
}

func TestTriePruningStorer_GetFromOldEpochsWithCache(t *testing.T) {
t.Parallel()

args := getDefaultArgs()
ps, _ := pruning.NewTriePruningStorer(args)
cacher := testscommon.NewCacherMock()
ps.SetCacher(cacher)

testKey1 := []byte("key1")
testVal1 := []byte("value1")

err := ps.PutInEpoch(testKey1, testVal1, 0)
assert.Nil(t, err)

err = ps.ChangeEpochSimple(1)
assert.Nil(t, err)
ps.SetEpochForPutOperation(1)

res, epoch, err := ps.GetFromOldEpochsWithoutAddingToCache(testKey1)
assert.Equal(t, testVal1, res)
assert.Nil(t, err)
assert.False(t, epoch.HasValue)
assert.Equal(t, uint32(0), epoch.Value)
}

func TestTriePruningStorer_GetFromOldEpochsWithoutCacheLessActivePersisters(t *testing.T) {
t.Parallel()

Loading

0 comments on commit 954cedb

Please sign in to comment.