detect trace_callMany (#637)

fix success detection in case of error during other methods detection
This commit is contained in:
a10zn8
2025-03-11 13:12:55 +03:00
committed by GitHub
parent 98d29c064f
commit 21e6cb94ff
4 changed files with 37 additions and 4 deletions

View File

@@ -34,13 +34,17 @@ abstract class UpstreamRpcMethodsDetector(
.getIngressReader()
.read(ChainRequest(method, param))
.flatMap(ChainResponse::requireResult)
.map { method to true }
.map {
method to true
}
.onErrorResume { err ->
val notAvailableError =
notAvailableRegexps.any { s -> s.containsMatchIn(err.message ?: "") }
if (notAvailableError) {
log.error("$method failed with ${err.message}, detect as false")
Mono.just(method to false)
} else {
log.error("$method failed with ${err.message}, do not detect")
Mono.empty()
}
}
@@ -50,7 +54,7 @@ abstract class UpstreamRpcMethodsDetector(
it
.map { p -> p as Pair<String, Boolean> }
.associate { (method, enabled) -> method to enabled }
}
}.switchIfEmpty(Mono.just(emptyMap()))
protected abstract fun detectByMagicMethod(): Mono<Map<String, Boolean>>

View File

@@ -33,6 +33,7 @@ class BasicEthUpstreamRpcMethodsDetector(
override fun rpcMethods(): Set<Pair<String, CallParams>> =
setOf(
"eth_getBlockReceipts" to ListParams("latest"),
"trace_callMany" to ListParams(listOf(listOf<Any>())),
)
private fun parseRpcModules(data: ByteArray): Map<String, Boolean> {

View File

@@ -39,6 +39,15 @@ class BasicEthUpstreamRpcMethodsDetectorTest {
null,
),
)
on {
read(ChainRequest("trace_callMany", ListParams(listOf(listOf<Any>()))))
} doReturn
Mono.just(
ChainResponse(
"[]".toByteArray(),
null,
),
)
}
val upstream =
@@ -79,6 +88,15 @@ class BasicEthUpstreamRpcMethodsDetectorTest {
null,
),
)
on {
read(ChainRequest("trace_callMany", ListParams(listOf(listOf<Any>()))))
} doReturn
Mono.just(
ChainResponse(
"[]".toByteArray(),
null,
),
)
}
val upstream =
@@ -90,8 +108,9 @@ class BasicEthUpstreamRpcMethodsDetectorTest {
val detector = BasicEthUpstreamRpcMethodsDetector(upstream, config)
Assertions.assertThat(detector.detectRpcMethods().block()).apply {
isNotNull()
hasSize(1)
hasSize(2)
containsEntry("eth_getBlockReceipts", true)
containsEntry("trace_callMany", true)
}
}
@@ -119,6 +138,15 @@ class BasicEthUpstreamRpcMethodsDetectorTest {
null,
),
)
on {
read(ChainRequest("trace_callMany", ListParams(listOf(listOf<Any>()))))
} doReturn
Mono.just(
ChainResponse(
"[]".toByteArray(),
null,
),
)
}
val upstream =

View File

@@ -64,6 +64,6 @@ class BasicPolkadotUpstreamRpcMethodsDetectorTest {
on { getChain() } doReturn Chain.POLKADOT__MAINNET
}
val detector = BasicPolkadotUpstreamRpcMethodsDetector(upstream)
Assertions.assertThat(detector.detectRpcMethods().block()).isNull()
Assertions.assertThat(detector.detectRpcMethods().block()).isEqualTo(emptyMap<String, Boolean>())
}
}