Predict next bound offset (#691)
* predictLowerBound with offset * remove method predictLowerBound without offset * bump emerald submodule
This commit is contained in:
@@ -168,7 +168,7 @@ abstract class DefaultUpstream(
|
||||
// NOOP
|
||||
}
|
||||
|
||||
override fun predictLowerBound(type: LowerBoundType): Long {
|
||||
override fun predictLowerBound(type: LowerBoundType, timeOffsetSeconds: Long): Long {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ abstract class Multistream(
|
||||
return getAll().any { it.isAvailable() }
|
||||
}
|
||||
|
||||
override fun predictLowerBound(type: LowerBoundType): Long {
|
||||
override fun predictLowerBound(type: LowerBoundType, timeOffsetSeconds: Long): Long {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ class Selector {
|
||||
LowerHeightMatcher(
|
||||
it.lowerHeightSelector.height,
|
||||
it.lowerHeightSelector.lowerBoundType.fromProtoType(),
|
||||
it.lowerHeightSelector.timeOffset,
|
||||
)
|
||||
} else {
|
||||
empty
|
||||
@@ -569,9 +570,10 @@ class Selector {
|
||||
data class LowerHeightMatcher(
|
||||
private val lowerHeight: Long,
|
||||
private val boundType: LowerBoundType,
|
||||
private val timeOffsetSeconds: Long = 0,
|
||||
) : Matcher() {
|
||||
override fun matchesWithCause(up: Upstream): MatchesResponse {
|
||||
val predictedLowerBound = up.predictLowerBound(boundType)
|
||||
val predictedLowerBound = up.predictLowerBound(boundType, timeOffsetSeconds)
|
||||
return if (lowerHeight >= predictedLowerBound && predictedLowerBound != 0L) {
|
||||
Success
|
||||
} else {
|
||||
|
||||
@@ -55,7 +55,7 @@ interface Upstream : Lifecycle {
|
||||
fun addFinalization(finalization: FinalizationData, upstreamId: String)
|
||||
fun getUpstreamSettingsData(): UpstreamSettingsData?
|
||||
fun updateLowerBound(lowerBound: Long, type: LowerBoundType)
|
||||
fun predictLowerBound(type: LowerBoundType): Long
|
||||
fun predictLowerBound(type: LowerBoundType, timeOffsetSeconds: Long): Long
|
||||
|
||||
fun getChain(): Chain
|
||||
|
||||
|
||||
@@ -437,8 +437,8 @@ open class GenericUpstream(
|
||||
lowerBoundService.updateLowerBound(lowerBound, type)
|
||||
}
|
||||
|
||||
override fun predictLowerBound(type: LowerBoundType): Long {
|
||||
return lowerBoundService.predictLowerBound(type)
|
||||
override fun predictLowerBound(type: LowerBoundType, timeOffsetSeconds: Long): Long {
|
||||
return lowerBoundService.predictLowerBound(type, timeOffsetSeconds)
|
||||
}
|
||||
|
||||
fun isValid(): Boolean = isUpstreamValid.get()
|
||||
|
||||
@@ -64,7 +64,7 @@ abstract class LowerBoundDetector(
|
||||
lowerBoundSink.emitNext(LowerBoundData(lowerBound, type)) { _, res -> res == Sinks.EmitResult.FAIL_NON_SERIALIZED }
|
||||
}
|
||||
|
||||
fun predictLowerBound(type: LowerBoundType): Long {
|
||||
return lowerBounds.predictNextBound(type)
|
||||
fun predictLowerBound(type: LowerBoundType, timeOffsetSeconds: Long): Long {
|
||||
return lowerBounds.predictNextBound(type, timeOffsetSeconds)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ abstract class LowerBoundService(
|
||||
.forEach { it.updateLowerBound(lowerBound, type) }
|
||||
}
|
||||
|
||||
fun predictLowerBound(type: LowerBoundType): Long {
|
||||
fun predictLowerBound(type: LowerBoundType, timeOffsetSeconds: Long): Long {
|
||||
return detectors
|
||||
.firstOrNull { it.types().contains(type) }
|
||||
?.predictLowerBound(type)
|
||||
?.predictLowerBound(type, timeOffsetSeconds)
|
||||
?: 0
|
||||
}
|
||||
|
||||
|
||||
@@ -67,16 +67,10 @@ class LowerBounds(
|
||||
}
|
||||
}
|
||||
|
||||
fun predictNextBound(type: LowerBoundType): Long {
|
||||
val offset = if (chain == Chain.BSC__MAINNET && type == LowerBoundType.STATE) {
|
||||
30
|
||||
} else {
|
||||
0
|
||||
}.toLong()
|
||||
|
||||
fun predictNextBound(type: LowerBoundType, timeOffsetSeconds: Long): Long {
|
||||
val lowerBoundCoeffs = lowerBounds[type] ?: return 0
|
||||
|
||||
val xTime = Instant.now().plus(offset, ChronoUnit.SECONDS).epochSecond
|
||||
val xTime = Instant.now().plus(timeOffsetSeconds, ChronoUnit.SECONDS).epochSecond
|
||||
|
||||
return (lowerBoundCoeffs.k.get() * xTime + lowerBoundCoeffs.b.get()).roundToLong()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user