listunspent only in case of balances is provided (#575)

This commit is contained in:
a10zn8
2024-09-25 17:03:40 +03:00
committed by GitHub
parent 2b141f7d08
commit 7c4d061fd0
8 changed files with 20 additions and 15 deletions

View File

@@ -63,7 +63,7 @@ class BitcoinUpstreamCreator(
MergedHead(listOf(rpcHead, zeroMqHead), MostWorkForkChoice(), headScheduler) MergedHead(listOf(rpcHead, zeroMqHead), MostWorkForkChoice(), headScheduler)
} ?: rpcHead } ?: rpcHead
val methods = buildMethods(config, chain) val methods = buildMethods(config, chain, options)
val upstream = BitcoinRpcUpstream( val upstream = BitcoinRpcUpstream(
config.id config.id
?: "bitcoin-${seq.getAndIncrement()}", ?: "bitcoin-${seq.getAndIncrement()}",

View File

@@ -72,7 +72,7 @@ open class GenericUpstreamCreator(
if (it.connectorMode == GenericConnectorFactory.ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD.name) it.rpc?.url ?: it.ws?.url else it.ws?.url ?: it.rpc?.url if (it.connectorMode == GenericConnectorFactory.ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD.name) it.rpc?.url ?: it.ws?.url else it.ws?.url ?: it.rpc?.url
} }
val hash = getHash(nodeId, hashUrl!!, hashes) val hash = getHash(nodeId, hashUrl!!, hashes)
val buildMethodsFun = { a: UpstreamsConfig.Upstream<*>, b: Chain -> this.buildMethods(a, b) } val buildMethodsFun = { a: UpstreamsConfig.Upstream<*>, b: Chain -> this.buildMethods(a, b, options) }
val upstream = GenericUpstream( val upstream = GenericUpstream(
config, config,

View File

@@ -6,6 +6,7 @@ import io.emeraldpay.dshackle.config.ChainsConfig
import io.emeraldpay.dshackle.config.IndexConfig import io.emeraldpay.dshackle.config.IndexConfig
import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.foundation.ChainOptions import io.emeraldpay.dshackle.foundation.ChainOptions
import io.emeraldpay.dshackle.foundation.ChainOptions.Options
import io.emeraldpay.dshackle.upstream.CallTargetsHolder import io.emeraldpay.dshackle.upstream.CallTargetsHolder
import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.CallMethods
import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods
@@ -70,7 +71,7 @@ abstract class UpstreamCreator(
chainConf: ChainsConfig.ChainConfig, chainConf: ChainsConfig.ChainConfig,
): UpstreamCreationData ): UpstreamCreationData
protected fun buildMethods(config: UpstreamsConfig.Upstream<*>, chain: Chain): CallMethods { protected fun buildMethods(config: UpstreamsConfig.Upstream<*>, chain: Chain, options: Options): CallMethods {
return if (config.methods != null || config.methodGroups != null) { return if (config.methods != null || config.methodGroups != null) {
if (config.methodGroups == null) { if (config.methodGroups == null) {
config.methodGroups = UpstreamsConfig.MethodGroups(setOf("filter"), setOf()) config.methodGroups = UpstreamsConfig.MethodGroups(setOf("filter"), setOf())
@@ -82,7 +83,7 @@ abstract class UpstreamCreator(
} }
ManagedCallMethods( ManagedCallMethods(
delegate = callTargets.getDefaultMethods(chain, indexConfig.isChainEnabled(chain)), delegate = callTargets.getDefaultMethods(chain, indexConfig.isChainEnabled(chain), options),
enabled = config.methods?.enabled?.map { it.name }?.toSet() ?: emptySet(), enabled = config.methods?.enabled?.map { it.name }?.toSet() ?: emptySet(),
disabled = config.methods?.disabled?.map { it.name }?.toSet() ?: emptySet(), disabled = config.methods?.disabled?.map { it.name }?.toSet() ?: emptySet(),
groupsEnabled = config.methodGroups?.enabled ?: emptySet(), groupsEnabled = config.methodGroups?.enabled ?: emptySet(),
@@ -98,7 +99,7 @@ abstract class UpstreamCreator(
} }
} }
} else { } else {
callTargets.getDefaultMethods(chain, indexConfig.isChainEnabled(chain)) callTargets.getDefaultMethods(chain, indexConfig.isChainEnabled(chain), options)
} }
} }
} }

View File

@@ -10,6 +10,7 @@ import io.emeraldpay.dshackle.BlockchainType.SOLANA
import io.emeraldpay.dshackle.BlockchainType.STARKNET import io.emeraldpay.dshackle.BlockchainType.STARKNET
import io.emeraldpay.dshackle.BlockchainType.UNKNOWN import io.emeraldpay.dshackle.BlockchainType.UNKNOWN
import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Chain
import io.emeraldpay.dshackle.foundation.ChainOptions
import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.CallMethods
import io.emeraldpay.dshackle.upstream.calls.DefaultBeaconChainMethods import io.emeraldpay.dshackle.upstream.calls.DefaultBeaconChainMethods
import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods
@@ -23,13 +24,13 @@ import org.springframework.stereotype.Component
class CallTargetsHolder { class CallTargetsHolder {
private val callTargets = HashMap<Chain, CallMethods>() private val callTargets = HashMap<Chain, CallMethods>()
fun getDefaultMethods(chain: Chain, hasLogsOracle: Boolean): CallMethods { fun getDefaultMethods(chain: Chain, hasLogsOracle: Boolean, options: ChainOptions.Options): CallMethods {
return callTargets[chain] ?: return setupDefaultMethods(chain, hasLogsOracle) return callTargets[chain] ?: return setupDefaultMethods(chain, hasLogsOracle, options)
} }
private fun setupDefaultMethods(chain: Chain, hasLogsOracle: Boolean): CallMethods { private fun setupDefaultMethods(chain: Chain, hasLogsOracle: Boolean, options: ChainOptions.Options): CallMethods {
val created = when (chain.type) { val created = when (chain.type) {
BITCOIN -> DefaultBitcoinMethods() BITCOIN -> DefaultBitcoinMethods(options.providesBalance == true)
ETHEREUM -> DefaultEthereumMethods(chain, hasLogsOracle) ETHEREUM -> DefaultEthereumMethods(chain, hasLogsOracle)
STARKNET -> DefaultStarknetMethods(chain) STARKNET -> DefaultStarknetMethods(chain)
POLKADOT -> DefaultPolkadotMethods(chain) POLKADOT -> DefaultPolkadotMethods(chain)

View File

@@ -51,7 +51,7 @@ open class BitcoinMultistream(
private var reader = BitcoinReader(this, head, esplora) private var reader = BitcoinReader(this, head, esplora)
private var addressActiveCheck: AddressActiveCheck? = null private var addressActiveCheck: AddressActiveCheck? = null
private var xpubAddresses: XpubAddresses? = null private var xpubAddresses: XpubAddresses? = null
private var callRouter: LocalCallRouter = LocalCallRouter(DefaultBitcoinMethods(), reader) private var callRouter: LocalCallRouter = LocalCallRouter(DefaultBitcoinMethods(sourceUpstreams.any { it.getOptions().providesBalance == true }), reader)
override fun getUpstreams(): MutableList<out Upstream> { override fun getUpstreams(): MutableList<out Upstream> {
return sourceUpstreams return sourceUpstreams
} }

View File

@@ -41,5 +41,5 @@ abstract class BitcoinUpstream(
options: ChainOptions.Options, options: ChainOptions.Options,
role: UpstreamsConfig.UpstreamRole, role: UpstreamsConfig.UpstreamRole,
chainConfig: ChainsConfig.ChainConfig, chainConfig: ChainsConfig.ChainConfig,
) : this(id, chain, options, role, DefaultBitcoinMethods(), QuorumForLabels.QuorumItem.empty(), null, chainConfig) ) : this(id, chain, options, role, DefaultBitcoinMethods(options.providesBalance == true), QuorumForLabels.QuorumItem.empty(), null, chainConfig)
} }

View File

@@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.quorum.NotNullQuorum
import io.emeraldpay.dshackle.upstream.ethereum.rpc.RpcException import io.emeraldpay.dshackle.upstream.ethereum.rpc.RpcException
import java.util.Collections import java.util.Collections
class DefaultBitcoinMethods : CallMethods { class DefaultBitcoinMethods(balances: Boolean) : CallMethods {
private val networkinfo = Global.objectMapper.writeValueAsBytes( private val networkinfo = Global.objectMapper.writeValueAsBytes(
mapOf( mapOf(
@@ -49,7 +49,6 @@ class DefaultBitcoinMethods : CallMethods {
"getbestblockhash", "getbestblockhash",
"getblocknumber", "getblocknumber",
"getblockcount", "getblockcount",
"listunspent",
"getreceivedbyaddress", "getreceivedbyaddress",
"getblockchaininfo", "getblockchaininfo",
).sorted() ).sorted()
@@ -63,8 +62,12 @@ class DefaultBitcoinMethods : CallMethods {
"sendrawtransaction", "sendrawtransaction",
).sorted() ).sorted()
private val withBalances = listOf(
"listunspent",
)
private val allowedMethods = private val allowedMethods =
(freshMethods + anyResponseMethods + headVerifiedMethods + broadcastMethods).sorted() (freshMethods + anyResponseMethods + headVerifiedMethods + broadcastMethods + if (balances) withBalances else listOf()).sorted()
override fun createQuorumFor(method: String): CallQuorum { override fun createQuorumFor(method: String): CallQuorum {
return when { return when {

View File

@@ -39,7 +39,7 @@ class GenericUpstreamMock extends GenericUpstream {
static CallMethods allMethods() { static CallMethods allMethods() {
new AggregatedCallMethods([ new AggregatedCallMethods([
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false), new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
new DefaultBitcoinMethods(), new DefaultBitcoinMethods(true),
new DirectCallMethods(["eth_test"]) new DirectCallMethods(["eth_test"])
]) ])
} }