Reset lower bounds if they're too different (#655)

This commit is contained in:
KirillPamPam
2025-04-17 18:09:38 +04:00
committed by GitHub
parent fa3f4411c3
commit d20f2d0c7f
2 changed files with 72 additions and 2 deletions

View File

@@ -22,14 +22,19 @@ class LowerBounds(
fun updateBound(newBound: LowerBoundData) {
if (lowerBounds.containsKey(newBound.type)) {
val lowerBoundCoeffs = lowerBounds[newBound.type]!!
val lastBound = lowerBoundCoeffs.getLastBound()
// we add only bounds with different timestamps
if (newBound.timestamp != lowerBoundCoeffs.getLastBound().timestamp) {
if (newBound.timestamp != lastBound.timestamp) {
if (newBound.lowerBound == 1L) {
// this is the fully archival node, so there is no need to accumulate bounds and calculate the coeffs
lowerBoundCoeffs.updateCoeffs(0.0, 1.0)
lowerBoundCoeffs.clearBounds()
lowerBoundCoeffs.addBound(newBound)
} else if (newBound.lowerBound < lastBound.lowerBound || (newBound.lowerBound - lastBound.lowerBound) >= 100000) {
lowerBoundCoeffs.updateCoeffs(averageSpeed, calculateB(newBound))
lowerBoundCoeffs.clearBounds()
lowerBoundCoeffs.addBound(newBound)
} else {
// accumulate up to MAX_BOUNDS and preserve this size
if (lowerBoundCoeffs.boundsSize() == MAX_BOUNDS) {