diff --git a/emerald-grpc b/emerald-grpc index 464bab50..e6153279 160000 --- a/emerald-grpc +++ b/emerald-grpc @@ -1 +1 @@ -Subproject commit 464bab5057fa3b7baf91f11840ff627bc72a112b +Subproject commit e6153279a531807157639db258d7590ef83faace diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/ErrorProcessing.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/ErrorProcessing.kt deleted file mode 100644 index fbf5db56..00000000 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/ErrorProcessing.kt +++ /dev/null @@ -1,43 +0,0 @@ -package io.emeraldpay.dshackle.rpc - -import org.springframework.stereotype.Component - -interface ErrorProcessor { - - fun matches(result: NativeCall.CallResult): Boolean - - fun errorProcess(error: NativeCall.CallError): NativeCall.CallError -} - -@Component -open class ErrorCorrector( - private val processors: List, -) { - - fun correctError(result: NativeCall.CallResult): NativeCall.CallError { - if (!result.isError()) { - throw IllegalStateException("No error to correct") - } - return processors - .firstOrNull { it.matches(result) } - ?.errorProcess(result.error!!) - ?: result.error!! - } -} - -@Component -class NethermindEthCallRevertedErrorProcessor : ErrorProcessor { - override fun matches(result: NativeCall.CallResult): Boolean { - return result.ctx?.payload?.method == "eth_call" && (result.error?.data?.startsWith("Reverted") ?: false) - } - - override fun errorProcess(error: NativeCall.CallError): NativeCall.CallError { - return NativeCall.CallError( - 3, - error.message, - error.upstreamError, - error.data?.removePrefix("Reverted "), - error.upstreamId, - ) - } -} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 6641addb..3a889170 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -65,7 +65,6 @@ open class NativeCall( private val signer: ResponseSigner, config: MainConfig, private val tracer: Tracer, - private val errorCorrector: ErrorCorrector, ) { private val log = LoggerFactory.getLogger(NativeCall::class.java) @@ -174,12 +173,11 @@ open class NativeCall( .setSucceed(!it.isError()) .setId(it.id) if (it.isError()) { - it.error?.let { _ -> - val fixedError = errorCorrector.correctError(it) - result.setErrorMessage(fixedError.message) - .setErrorCode(fixedError.id) + it.error?.let { error -> + result.setErrorMessage(error.message) + .setItemErrorCode(error.id) - fixedError.data?.let { data -> + error.data?.let { data -> result.setErrorData(data) } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy index 57653451..06fb63bb 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy @@ -70,7 +70,7 @@ class NativeCallSpec extends Specification { config.cache = cacheConfig config.passthrough = passthrough - new NativeCall(upstreams, signer, config, Stub(Tracer), Stub(ErrorCorrector)) + new NativeCall(upstreams, signer, config, Stub(Tracer)) } def "Tries router first"() { diff --git a/src/test/kotlin/io/emeraldpay/dshackle/rpc/ErrorProcessingTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/rpc/ErrorProcessingTest.kt deleted file mode 100644 index e2a4fa3a..00000000 --- a/src/test/kotlin/io/emeraldpay/dshackle/rpc/ErrorProcessingTest.kt +++ /dev/null @@ -1,93 +0,0 @@ -package io.emeraldpay.dshackle.rpc - -import io.emeraldpay.dshackle.quorum.CallQuorum -import io.emeraldpay.dshackle.upstream.Multistream -import io.emeraldpay.dshackle.upstream.Selector -import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcError -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import org.mockito.kotlin.mock - -class ErrorProcessingTest { - - @Test - fun `fix nethermind eth_call reverted error`() { - val result = result("eth_call", "Reverted 0x0111") - val error = result.error!! - val corrector = ErrorCorrector(listOf(NethermindEthCallRevertedErrorProcessor())) - - val fixedError = corrector.correctError(result) - - assertEquals( - NativeCall.CallError(3, error.message, error.upstreamError, "0x0111", error.upstreamId), - fixedError, - ) - } - - @Test - fun `return the same error if there is no suitable processor`() { - val result = result("eth_getBlockByNumber", "Reverted 0x0111") - val error = result.error!! - val corrector = ErrorCorrector(listOf(NethermindEthCallRevertedErrorProcessor())) - - val fixedError = corrector.correctError(result) - - assertEquals( - NativeCall.CallError(55, error.message, error.upstreamError, "Reverted 0x0111", error.upstreamId), - fixedError, - ) - } - - @Test - fun `throw an exception if there is no error in result`() { - val result = NativeCall.CallResult( - 1, - 2, - null, - null, - null, - null, - ) - assertThrows("No error to correct") { - val corrector = ErrorCorrector(listOf(NethermindEthCallRevertedErrorProcessor())) - corrector.correctError(result) - } - } - - @Test - fun `NethermindEthCallRevertedErrorProcessor returns false if result is with null data`() { - val processor = NethermindEthCallRevertedErrorProcessor() - val result = result("eth_call", null) - - val matched = processor.matches(result) - - assertFalse(matched) - } - - private fun result(method: String, errorData: String?): NativeCall.CallResult = - NativeCall.CallResult( - 1, - 2, - null, - NativeCall.CallError( - 55, - "reverted", - JsonRpcError(1, "errMessage", null), - errorData, - "upId", - ), - null, - NativeCall.ValidCallContext( - 1, - 2, - mock(), - Selector.empty, - mock(), - NativeCall.ParsedCallDetails(method, emptyList()), - "req", - 1, - ), - ) -}