Merge pull request #71 from p2p-org/logging-for-emptiness
logging for empty results
This commit is contained in:
@@ -27,7 +27,6 @@ import io.emeraldpay.dshackle.quorum.CallQuorum
|
|||||||
import io.emeraldpay.dshackle.quorum.NotLaggingQuorum
|
import io.emeraldpay.dshackle.quorum.NotLaggingQuorum
|
||||||
import io.emeraldpay.dshackle.quorum.QuorumReaderFactory
|
import io.emeraldpay.dshackle.quorum.QuorumReaderFactory
|
||||||
import io.emeraldpay.dshackle.quorum.QuorumRpcReader
|
import io.emeraldpay.dshackle.quorum.QuorumRpcReader
|
||||||
import io.emeraldpay.dshackle.startup.ConfiguredUpstreams
|
|
||||||
import io.emeraldpay.dshackle.startup.UpstreamChangeEvent
|
import io.emeraldpay.dshackle.startup.UpstreamChangeEvent
|
||||||
import io.emeraldpay.dshackle.upstream.*
|
import io.emeraldpay.dshackle.upstream.*
|
||||||
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
|
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
|
||||||
@@ -56,7 +55,6 @@ import java.util.concurrent.atomic.AtomicInteger
|
|||||||
@Service
|
@Service
|
||||||
open class NativeCall(
|
open class NativeCall(
|
||||||
private val multistreamHolder: MultistreamHolder,
|
private val multistreamHolder: MultistreamHolder,
|
||||||
private val configuredUpstreams: ConfiguredUpstreams,
|
|
||||||
private val signer: ResponseSigner
|
private val signer: ResponseSigner
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -76,7 +74,7 @@ open class NativeCall(
|
|||||||
@EventListener
|
@EventListener
|
||||||
fun onUpstreamChangeEvent(event: UpstreamChangeEvent) {
|
fun onUpstreamChangeEvent(event: UpstreamChangeEvent) {
|
||||||
casting[BlockchainType.from(event.chain)]?.let { cast ->
|
casting[BlockchainType.from(event.chain)]?.let { cast ->
|
||||||
multistreamHolder.getUpstream(event.chain)?.let { up ->
|
multistreamHolder.getUpstream(event.chain).let { up ->
|
||||||
val reader = up.cast(cast).getReader()
|
val reader = up.cast(cast).getReader()
|
||||||
ethereumCallSelectors.putIfAbsent(event.chain, EthereumCallSelector(reader.heightByHash()))
|
ethereumCallSelectors.putIfAbsent(event.chain, EthereumCallSelector(reader.heightByHash()))
|
||||||
}
|
}
|
||||||
@@ -98,6 +96,7 @@ open class NativeCall(
|
|||||||
.doOnError { e -> log.warn("Error during native call: ${e.message}") }
|
.doOnError { e -> log.warn("Error during native call: ${e.message}") }
|
||||||
} else {
|
} else {
|
||||||
val error = it.getError()
|
val error = it.getError()
|
||||||
|
|
||||||
Mono.just(
|
Mono.just(
|
||||||
CallResult(error.id, 0, null, error, null, null)
|
CallResult(error.id, 0, null, error, null, null)
|
||||||
)
|
)
|
||||||
@@ -274,6 +273,7 @@ open class NativeCall(
|
|||||||
api.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params, ctx.nonce, ctx.forwardedSelector))
|
api.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params, ctx.nonce, ctx.forwardedSelector))
|
||||||
.flatMap(JsonRpcResponse::requireResult)
|
.flatMap(JsonRpcResponse::requireResult)
|
||||||
.map {
|
.map {
|
||||||
|
validateResult(it, "local", ctx)
|
||||||
if (ctx.nonce != null) {
|
if (ctx.nonce != null) {
|
||||||
CallResult.ok(ctx.id, ctx.nonce, it, signer.sign(ctx.nonce, it, ctx.upstream.getId()), ctx.upstream.getId())
|
CallResult.ok(ctx.id, ctx.nonce, it, signer.sign(ctx.nonce, it, ctx.upstream.getId()), ctx.upstream.getId())
|
||||||
} else {
|
} else {
|
||||||
@@ -299,11 +299,13 @@ open class NativeCall(
|
|||||||
} else {
|
} else {
|
||||||
AtomicInteger(-1)
|
AtomicInteger(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return reader
|
return reader
|
||||||
.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params, ctx.nonce, ctx.forwardedSelector))
|
.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params, ctx.nonce, ctx.forwardedSelector))
|
||||||
.map {
|
.map {
|
||||||
val bytes = ctx.resultDecorator.processResult(it)
|
val bytes = ctx.resultDecorator.processResult(it)
|
||||||
CallResult(ctx.id, ctx.nonce, bytes, null, it.signature, ctx.upstream.getId())
|
validateResult(bytes, "remote", ctx)
|
||||||
|
CallResult.ok(ctx.id, ctx.nonce, bytes, it.signature, ctx.upstream.getId())
|
||||||
}
|
}
|
||||||
.onErrorResume { t ->
|
.onErrorResume { t ->
|
||||||
Mono.just(CallResult.fail(ctx.id, ctx.nonce, t))
|
Mono.just(CallResult.fail(ctx.id, ctx.nonce, t))
|
||||||
@@ -322,6 +324,11 @@ open class NativeCall(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun validateResult(bytes: ByteArray, origin: String, ctx: ValidCallContext<ParsedCallDetails>) {
|
||||||
|
if (bytes.isEmpty())
|
||||||
|
log.warn("Empty result from origin $origin, method ${ctx.payload.method}, params ${ctx.payload.params}")
|
||||||
|
}
|
||||||
|
|
||||||
private fun errorMessage(attempts: Int, method: String): String =
|
private fun errorMessage(attempts: Int, method: String): String =
|
||||||
when (attempts) {
|
when (attempts) {
|
||||||
-1 -> "No response or no available upstream for $method"
|
-1 -> "No response or no available upstream for $method"
|
||||||
|
|||||||
@@ -54,17 +54,14 @@ class NativeCallSpec extends Specification {
|
|||||||
|
|
||||||
ObjectMapper objectMapper = Global.objectMapper
|
ObjectMapper objectMapper = Global.objectMapper
|
||||||
|
|
||||||
def nativeCall(MultistreamHolder upstreams = null, ResponseSigner signer = null, ConfiguredUpstreams configuredUpstreams = null) {
|
def nativeCall(MultistreamHolder upstreams = null, ResponseSigner signer = null) {
|
||||||
if (upstreams == null) {
|
if (upstreams == null) {
|
||||||
upstreams = Stub(MultistreamHolder)
|
upstreams = Stub(MultistreamHolder)
|
||||||
}
|
}
|
||||||
if (signer == null) {
|
if (signer == null) {
|
||||||
signer = Stub(ResponseSigner)
|
signer = Stub(ResponseSigner)
|
||||||
}
|
}
|
||||||
if (configuredUpstreams == null) {
|
new NativeCall(upstreams, signer)
|
||||||
configuredUpstreams = Stub(ConfiguredUpstreams)
|
|
||||||
}
|
|
||||||
new NativeCall(upstreams, configuredUpstreams, signer)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def "Tries router first"() {
|
def "Tries router first"() {
|
||||||
|
|||||||
Reference in New Issue
Block a user