BSC offset bound (#689)
This commit is contained in:
@@ -4,12 +4,13 @@ import com.google.common.util.concurrent.AtomicDouble
|
|||||||
import io.emeraldpay.dshackle.Chain
|
import io.emeraldpay.dshackle.Chain
|
||||||
import org.apache.commons.math3.stat.regression.SimpleRegression
|
import org.apache.commons.math3.stat.regression.SimpleRegression
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import java.time.temporal.ChronoUnit
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque
|
import java.util.concurrent.ConcurrentLinkedDeque
|
||||||
import kotlin.math.roundToLong
|
import kotlin.math.roundToLong
|
||||||
|
|
||||||
class LowerBounds(
|
class LowerBounds(
|
||||||
chain: Chain,
|
val chain: Chain,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val MAX_BOUNDS = 3
|
private const val MAX_BOUNDS = 3
|
||||||
@@ -67,9 +68,15 @@ class LowerBounds(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun predictNextBound(type: LowerBoundType): Long {
|
fun predictNextBound(type: LowerBoundType): Long {
|
||||||
|
val offset = if (chain == Chain.BSC__MAINNET && type == LowerBoundType.STATE) {
|
||||||
|
30
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}.toLong()
|
||||||
|
|
||||||
val lowerBoundCoeffs = lowerBounds[type] ?: return 0
|
val lowerBoundCoeffs = lowerBounds[type] ?: return 0
|
||||||
|
|
||||||
val xTime = Instant.now().epochSecond
|
val xTime = Instant.now().plus(offset, ChronoUnit.SECONDS).epochSecond
|
||||||
|
|
||||||
return (lowerBoundCoeffs.k.get() * xTime + lowerBoundCoeffs.b.get()).roundToLong()
|
return (lowerBoundCoeffs.k.get() * xTime + lowerBoundCoeffs.b.get()).roundToLong()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user