@@ -18,6 +18,7 @@ import (
1818 "github.com/Fantom-foundation/go-opera/logger"
1919 "github.com/Fantom-foundation/go-opera/utils/adapters/snap2kvdb"
2020 "github.com/Fantom-foundation/go-opera/utils/eventid"
21+ "github.com/Fantom-foundation/go-opera/utils/randat"
2122 "github.com/Fantom-foundation/go-opera/utils/rlpstore"
2223 "github.com/Fantom-foundation/go-opera/utils/switchable"
2324)
@@ -165,14 +166,16 @@ func (s *Store) Close() {
165166}
166167
167168func (s * Store ) IsCommitNeeded () bool {
168- return s .isCommitNeeded (100 , 100 )
169+ // randomize flushing criteria for each epoch so that nodes would desynchronize flushes
170+ ratio := 900 + randat .RandAt (uint64 (s .GetEpoch ()))% 100
171+ return s .isCommitNeeded (ratio , ratio )
169172}
170173
171- func (s * Store ) isCommitNeeded (sc , tc int ) bool {
172- period := s .cfg .MaxNonFlushedPeriod * time .Duration (sc ) / 100
173- size := (s .cfg .MaxNonFlushedSize / 2 ) * tc / 100
174+ func (s * Store ) isCommitNeeded (sc , tc uint64 ) bool {
175+ period := s .cfg .MaxNonFlushedPeriod * time .Duration (sc ) / 1000
176+ size := (uint64 ( s .cfg .MaxNonFlushedSize ) / 2 ) * tc / 1000
174177 return time .Since (s .prevFlushTime ) > period ||
175- s .dbs .NotFlushedSizeEst () > size
178+ uint64 ( s .dbs .NotFlushedSizeEst () ) > size
176179}
177180
178181// commitEVM commits EVM storage
0 commit comments