detect trace_callMany (#637)
fix success detection in case of error during other methods detection
This commit is contained in:
@@ -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>>
|
||||
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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>())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user