From fc9f7e0fa60bfe21b5488f2c18ea689995057d48 Mon Sep 17 00:00:00 2001 From: Maksim Fomenkov Date: Fri, 18 Nov 2022 18:40:57 +0300 Subject: [PATCH] support network specific methods --- .../io/emeraldpay/dshackle/rpc/NativeCall.kt | 12 ++- .../upstream/calls/DefaultEthereumMethods.kt | 73 ++++++++++++++++++- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 956b187d..d8d02f95 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -255,7 +255,14 @@ open class NativeCall( } private fun getRequestDecorator(method: String): RequestDecorator = - if (method == "eth_getFilterChanges" || method == "eth_uninstallFilter") + if (method in listOf( + "eth_getFilterChanges", + "eth_uninstallFilter", + "shh_getFilterChanges", + "shh_uninstallFilter", + "shh_getMessages" + ) + ) GetFilterUpdatesDecorator() else NoneRequestDecorator() @@ -384,7 +391,8 @@ open class NativeCall( val createFilterMethods = listOf( "eth_newFilter", "eth_newBlockFilter", - "eth_newPendingTransactionFilter" + "eth_newPendingTransactionFilter", + "shh_newFilter", ) } override fun processResult(result: QuorumRpcReader.Result): ByteArray { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt index 6f78cfe0..10a8e4b4 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt @@ -78,8 +78,6 @@ class DefaultEthereumMethods( "eth_uninstallFilter" ) - private val allowedMethods = anyResponseMethods + firstValueMethods + specialMethods + headVerifiedMethods + filterMethods - private val hardcodedMethods = listOf( "net_version", "net_peerCount", @@ -94,9 +92,29 @@ class DefaultEthereumMethods( "eth_chainId" ) + private val bscFilterMethods = listOf( + "shh_newFilter", + "shh_uninstallFilter", + "shh_getFilterChanges", + "shh_getMessages", + ) + + private val allowedMethods: List + + init { + allowedMethods = anyResponseMethods + + firstValueMethods + + specialMethods + + headVerifiedMethods + + filterMethods - + chainUnsupportedMethods(chain) + + getChainSpecificMethods(chain) + } + + override fun getQuorumFor(method: String): CallQuorum { return when { - filterMethods.contains(method) -> AlwaysQuorum() + filterMethods.contains(method) -> NotLaggingQuorum(1) hardcodedMethods.contains(method) -> AlwaysQuorum() firstValueMethods.contains(method) -> AlwaysQuorum() anyResponseMethods.contains(method) -> NotLaggingQuorum(4) @@ -110,10 +128,59 @@ class DefaultEthereumMethods( else -> AlwaysQuorum() } } + + getChainSpecificMethods(chain).contains(method) -> { + if (bscFilterMethods.contains(method)) { + NotLaggingQuorum(1) + } else { + when (method) { + "eth_getBlockRange" -> NotLaggingQuorum(1) + "bor_getAuthor" -> NotLaggingQuorum(0) + "bor_getCurrentValidators" -> NotLaggingQuorum(0) + "bor_getCurrentProposer" -> NotLaggingQuorum(0) + "bor_getRootHash" -> NotLaggingQuorum(1) + "eth_getRootHash" -> NotLaggingQuorum(1) + "shh_hasIdentity" -> NotLaggingQuorum(1) + else -> AlwaysQuorum() + } + } + } else -> AlwaysQuorum() } } + private fun getChainSpecificMethods(chain: Chain): List { + return when (chain) { + Chain.OPTIMISM -> listOf( + "eth_getBlockRange", + "rollup_gasPrices" + ) + Chain.POLYGON -> listOf( + "bor_getAuthor", + "bor_getCurrentValidators", + "bor_getCurrentProposer", + "bor_getRootHash", + "bor_getSignersAtHash", + "eth_getRootHash" + ) + Chain.BSC -> bscFilterMethods + listOf( + "shh_post", + "shh_version", + "shh_newIdentity", + "shh_hasIdentity", + "shh_addToGroup", + ) + else -> emptyList() + } + } + + private fun chainUnsupportedMethods(chain: Chain): Set { + if (chain == Chain.OPTIMISM) { + return setOf("eth_getAccounts", "eth_sendTransaction") + } + return emptySet() + } + override fun isCallable(method: String): Boolean { return allowedMethods.contains(method) }