chore: store audit typo (#16840)

This commit is contained in:
cool-developer
2023-07-05 15:19:47 +00:00
committed by GitHub
parent 7017490830
commit cc1325c30c
6 changed files with 26 additions and 41 deletions
+8 -8
View File
@@ -21,7 +21,7 @@ type Manager struct {
opts types.PruningOptions
snapshotInterval uint64
// Snapshots are taken in a separate goroutine from the regular execution
// and can be delivered asynchrounously via HandleHeightSnapshot.
// and can be delivered asynchrounously via HandleSnapshotHeight.
// Therefore, we sync access to pruneSnapshotHeights with this mutex.
pruneSnapshotHeightsMx sync.RWMutex
// These are the heights that are multiples of snapshotInterval and kept for state sync snapshots.
@@ -65,11 +65,11 @@ func (m *Manager) GetOptions() types.PruningOptions {
return m.opts
}
// HandleHeightSnapshot persists the snapshot height to be pruned at the next appropriate
// height defined by the pruning strategy. Flushes the update to disk and panics if the flush fails.
// The input height must be greater than 0 and pruning strategy any but pruning nothing.
// If one of these conditions is not met, this function does nothing.
func (m *Manager) HandleHeightSnapshot(height int64) {
// HandleSnapshotHeight persists the snapshot height to be pruned at the next appropriate
// height defined by the pruning strategy. It flushes the update to disk and panics if the flush fails.
// The input height must be greater than 0, and the pruning strategy must not be set to pruning nothing.
// If either of these conditions is not met, this function does nothing.
func (m *Manager) HandleSnapshotHeight(height int64) {
if m.opts.GetPruningStrategy() == types.PruningNothing || height <= 0 {
return
}
@@ -77,7 +77,7 @@ func (m *Manager) HandleHeightSnapshot(height int64) {
m.pruneSnapshotHeightsMx.Lock()
defer m.pruneSnapshotHeightsMx.Unlock()
m.logger.Debug("HandleHeightSnapshot", "height", height)
m.logger.Debug("HandleSnapshotHeight", "height", height)
m.pruneSnapshotHeights = append(m.pruneSnapshotHeights, height)
sort.Slice(m.pruneSnapshotHeights, func(i, j int) bool { return m.pruneSnapshotHeights[i] < m.pruneSnapshotHeights[j] })
k := 1
@@ -118,7 +118,7 @@ func (m *Manager) GetPruningHeight(height int64) int64 {
m.pruneSnapshotHeightsMx.RLock()
defer m.pruneSnapshotHeightsMx.RUnlock()
// - snapshotInterval is zero as that means that all heights can be pruned.
// snapshotInterval is zero, indicating that all heights can be pruned
if m.snapshotInterval <= 0 {
return pruneHeight
}
+4 -25
View File
@@ -111,7 +111,7 @@ func TestStrategies(t *testing.T) {
for curHeight := int64(0); curHeight < 110000; curHeight++ {
if tc.snapshotInterval != 0 {
if curHeight > int64(tc.snapshotInterval) && curHeight%int64(tc.snapshotInterval) == int64(tc.snapshotInterval)-1 {
manager.HandleHeightSnapshot(curHeight - int64(tc.snapshotInterval) + 1)
manager.HandleSnapshotHeight(curHeight - int64(tc.snapshotInterval) + 1)
snHeight = curHeight
}
}
@@ -214,10 +214,10 @@ func TestHandleSnapshotHeight_DbErr_Panic(t *testing.T) {
}
}()
manager.HandleHeightSnapshot(10)
manager.HandleSnapshotHeight(10)
}
func TestHandleHeightSnapshot_LoadFromDisk(t *testing.T) {
func TestHandleSnapshotHeight_LoadFromDisk(t *testing.T) {
snapshotInterval := uint64(10)
// Setup
@@ -233,7 +233,7 @@ func TestHandleHeightSnapshot_LoadFromDisk(t *testing.T) {
snapshotHeightStr := fmt.Sprintf("snaphost height: %d", snapshotHeight)
if snapshotHeight > int64(snapshotInterval) && snapshotHeight%int64(snapshotInterval) == 1 {
// Test flush
manager.HandleHeightSnapshot(snapshotHeight - 1)
manager.HandleSnapshotHeight(snapshotHeight - 1)
expected = 1
}
@@ -251,27 +251,6 @@ func TestHandleHeightSnapshot_LoadFromDisk(t *testing.T) {
}
}
func TestHandleHeightSnapshot_DbErr_Panic(t *testing.T) {
ctrl := gomock.NewController(t)
// Setup
dbMock := mock.NewMockDB(ctrl)
dbMock.EXPECT().SetSync(gomock.Any(), gomock.Any()).Return(errors.New(dbErr)).Times(1)
manager := pruning.NewManager(dbMock, log.NewNopLogger())
manager.SetOptions(types.NewPruningOptions(types.PruningEverything))
require.NotNil(t, manager)
defer func() {
if r := recover(); r == nil {
t.Fail()
}
}()
manager.HandleHeightSnapshot(10)
}
func TestLoadPruningSnapshotHeights(t *testing.T) {
var (
manager = pruning.NewManager(db.NewMemDB(), log.NewNopLogger())