Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs bound is block bound #572

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class EthereumLowerBoundBlockDetector(
}
}
}
}.flatMap {
Flux.just(it, lowerBoundFrom(it, LowerBoundType.LOGS))
}
}

Expand All @@ -65,6 +67,6 @@ class EthereumLowerBoundBlockDetector(
}

override fun types(): Set<LowerBoundType> {
return setOf(LowerBoundType.BLOCK)
return setOf(LowerBoundType.BLOCK, LowerBoundType.LOGS)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class EthereumLowerBoundService(
EthereumLowerBoundStateDetector(upstream),
EthereumLowerBoundBlockDetector(upstream),
EthereumLowerBoundTxDetector(upstream),
EthereumLowerBoundLogsDetector(upstream),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,10 @@ class EthereumLowerBoundStateDetector(
}
}
}.flatMap {
Flux.just(it, lowerBoundFromState(it, LowerBoundType.TRACE))
Flux.just(it, lowerBoundFrom(it, LowerBoundType.TRACE))
}
}

private fun lowerBoundFromState(stateLowerBoundData: LowerBoundData, newType: LowerBoundType): LowerBoundData {
val currentBound = lowerBounds.getLastBound(newType)
if (currentBound == null || stateLowerBoundData.lowerBound >= currentBound.lowerBound) {
return stateLowerBoundData.copy(type = newType)
}
return LowerBoundData(currentBound.lowerBound, newType)
}

override fun types(): Set<LowerBoundType> {
return setOf(LowerBoundType.STATE, LowerBoundType.TRACE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ abstract class LowerBoundDetector(

protected abstract fun internalDetectLowerBound(): Flux<LowerBoundData>

protected fun lowerBoundFrom(lowerBoundFrom: LowerBoundData, newType: LowerBoundType): LowerBoundData {
val currentBound = lowerBounds.getLastBound(newType)
if (currentBound == null || lowerBoundFrom.lowerBound >= currentBound.lowerBound) {
return lowerBoundFrom.copy(type = newType)
}
return LowerBoundData(currentBound.lowerBound, newType)
}

abstract fun types(): Set<LowerBoundType>

fun updateLowerBound(lowerBound: Long, type: LowerBoundType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ class RecursiveLowerBoundServiceTest {
on {
read(ChainRequest("eth_getTransactionByHash", ListParams("0x99e52a94cfdf83a5bdadcd2e25c71574a5a24fa4df56a33f9f8b5cb6fa0ac657")))
} doReturn Mono.just(ChainResponse(ByteArray(0), null))
on {
read(ChainRequest("eth_getLogs", ListParams(mapOf("fromBlock" to it.toHex(), "toBlock" to it.toHex()))))
} doReturn Mono.just(ChainResponse("[\"0x12\"]".toByteArray(), null))
} else {
on {
read(ChainRequest("eth_getBalance", ListParams(ZERO_ADDRESS, it.toHex())))
Expand All @@ -66,9 +63,6 @@ class RecursiveLowerBoundServiceTest {
on {
read(ChainRequest("eth_getBlockByNumber", ListParams(block.toHex(), false)))
} doReturn Mono.just(ChainResponse(Global.nullValue, null))
on {
read(ChainRequest("eth_getLogs", ListParams(mapOf("fromBlock" to block.toHex(), "toBlock" to block.toHex()))))
} doReturn Mono.error(RuntimeException("No logs data"))
}
}
}
Expand All @@ -88,8 +82,8 @@ class RecursiveLowerBoundServiceTest {
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.STATE }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.TRACE }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.BLOCK }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.TX }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.LOGS }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.TX }
.thenCancel()
.verify(Duration.ofSeconds(3))

Expand All @@ -100,8 +94,8 @@ class RecursiveLowerBoundServiceTest {
LowerBoundData(17964844L, LowerBoundType.STATE),
LowerBoundData(17964844L, LowerBoundType.TRACE),
LowerBoundData(17964844L, LowerBoundType.BLOCK),
LowerBoundData(17964844L, LowerBoundType.TX),
LowerBoundData(17964844L, LowerBoundType.LOGS),
LowerBoundData(17964844L, LowerBoundType.TX),
),
)
}
Expand Down
Loading