Remove oracle (#620)
This commit is contained in:
@@ -21,7 +21,6 @@ import io.emeraldpay.dshackle.config.CacheConfig
|
||||
import io.emeraldpay.dshackle.config.ChainsConfig
|
||||
import io.emeraldpay.dshackle.config.CompressionConfig
|
||||
import io.emeraldpay.dshackle.config.HealthConfig
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import io.emeraldpay.dshackle.config.MainConfig
|
||||
import io.emeraldpay.dshackle.config.MainConfigReader
|
||||
import io.emeraldpay.dshackle.config.MonitoringConfig
|
||||
@@ -131,11 +130,6 @@ open class Config(
|
||||
return mainConfig.cache ?: CacheConfig()
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun indexConfig(@Autowired mainConfig: MainConfig): IndexConfig {
|
||||
return mainConfig.index ?: IndexConfig()
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun signatureConfig(@Autowired mainConfig: MainConfig): SignatureConfig {
|
||||
return mainConfig.signature ?: SignatureConfig()
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package io.emeraldpay.dshackle.config
|
||||
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
|
||||
class IndexConfig {
|
||||
var items: HashMap<Chain, Index> = HashMap<Chain, Index>()
|
||||
|
||||
class Index(
|
||||
var rpc: String,
|
||||
var store: String,
|
||||
var ram_limit: Long?,
|
||||
)
|
||||
|
||||
fun isChainEnabled(chain: Chain): Boolean {
|
||||
return items.containsKey(chain)
|
||||
}
|
||||
|
||||
fun getByChain(chain: Chain): Index? {
|
||||
return items.get(chain)
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package io.emeraldpay.dshackle.config
|
||||
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import io.emeraldpay.dshackle.Global
|
||||
import io.emeraldpay.dshackle.foundation.YamlConfigReader
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.util.unit.DataSize
|
||||
import org.yaml.snakeyaml.nodes.MappingNode
|
||||
|
||||
class IndexConfigReader : YamlConfigReader<IndexConfig>() {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(IndexConfigReader::class.java)
|
||||
}
|
||||
|
||||
override fun read(input: MappingNode?): IndexConfig? {
|
||||
return getList<MappingNode>(input, "index")?.let { items ->
|
||||
val config = IndexConfig()
|
||||
|
||||
items.value.map {
|
||||
val blockchainRaw = getValueAsString(it, "chain")
|
||||
if (blockchainRaw == null || StringUtils.isEmpty(blockchainRaw) || Global.chainById(blockchainRaw) == Chain.UNSPECIFIED) {
|
||||
throw InvalidConfigYamlException(filename, it.startMark, "Invalid blockchain or not specified")
|
||||
}
|
||||
|
||||
val blockchain = Global.chainById(blockchainRaw)
|
||||
if (config.items.containsKey(blockchain)) {
|
||||
throw InvalidConfigYamlException(filename, it.startMark, "Duplicated indexes")
|
||||
}
|
||||
|
||||
val rpc = getValueAsString(it, "rpc")
|
||||
if (rpc == null || StringUtils.isEmpty(rpc)) {
|
||||
throw InvalidConfigYamlException(filename, it.startMark, "Invalid rpc specified")
|
||||
}
|
||||
|
||||
val store = getValueAsString(it, "store")
|
||||
if (store == null || StringUtils.isEmpty(store)) {
|
||||
throw InvalidConfigYamlException(filename, it.startMark, "Invalid store directory or not specified")
|
||||
}
|
||||
|
||||
val limit = getMapping(it, "limit")
|
||||
val ram_limit = limit?.let {
|
||||
val raw = getValueAsString(limit, "ram")
|
||||
if (raw == null || StringUtils.isEmpty(raw)) {
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
DataSize.parse(raw).toBytes()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
throw InvalidConfigYamlException(filename, it.startMark, "Invalid limit for index")
|
||||
}
|
||||
}
|
||||
|
||||
config.items.put(blockchain, IndexConfig.Index(rpc, store, ram_limit))
|
||||
}
|
||||
|
||||
config
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ class MainConfig {
|
||||
var tls: AuthConfig.ServerTlsAuth? = null
|
||||
var passthrough: Boolean = false
|
||||
var cache: CacheConfig? = null
|
||||
var index: IndexConfig? = null
|
||||
var proxy: ProxyConfig? = null
|
||||
var upstreams: UpstreamsConfig? = null
|
||||
set(value) {
|
||||
|
||||
@@ -29,7 +29,6 @@ class MainConfigReader(
|
||||
private val optionsReader = ChainOptionsReader()
|
||||
private val upstreamsConfigReader = UpstreamsConfigReader(fileResolver, optionsReader)
|
||||
private val cacheConfigReader = CacheConfigReader()
|
||||
private val indexConfigReader = IndexConfigReader()
|
||||
private val tokensConfigReader = TokensConfigReader()
|
||||
private val monitoringConfigReader = MonitoringConfigReader()
|
||||
private val accessLogReader = AccessLogReader()
|
||||
@@ -64,9 +63,6 @@ class MainConfigReader(
|
||||
cacheConfigReader.read(input)?.let {
|
||||
config.cache = it
|
||||
}
|
||||
indexConfigReader.read(input)?.let {
|
||||
config.index = it
|
||||
}
|
||||
tokensConfigReader.read(input)?.let {
|
||||
config.tokens = it
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.emeraldpay.dshackle.config.context
|
||||
import io.emeraldpay.dshackle.BlockchainType.BITCOIN
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import io.emeraldpay.dshackle.cache.CachesFactory
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import io.emeraldpay.dshackle.upstream.CallTargetsHolder
|
||||
import io.emeraldpay.dshackle.upstream.Multistream
|
||||
import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream
|
||||
@@ -29,9 +28,6 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory)
|
||||
subScheduler: Scheduler,
|
||||
tracer: Tracer,
|
||||
multistreamEventsScheduler: Scheduler,
|
||||
indexConfig: IndexConfig,
|
||||
@Qualifier("logsOracleScheduler")
|
||||
logsOracleScheduler: Scheduler,
|
||||
): List<Multistream> {
|
||||
return Chain.entries
|
||||
.filterNot { it == Chain.UNSPECIFIED }
|
||||
@@ -46,8 +42,6 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory)
|
||||
subScheduler,
|
||||
tracer,
|
||||
multistreamEventsScheduler,
|
||||
indexConfig.getByChain(chain),
|
||||
logsOracleScheduler,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -60,8 +54,6 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory)
|
||||
subScheduler: Scheduler,
|
||||
tracer: Tracer,
|
||||
multistreamEventsScheduler: Scheduler,
|
||||
logsOracleConfig: IndexConfig.Index?,
|
||||
logsOracleScheduler: Scheduler,
|
||||
): Multistream {
|
||||
val name = "multi-$chain"
|
||||
val cs = ChainSpecificRegistry.resolve(chain)
|
||||
@@ -76,9 +68,6 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory)
|
||||
cs.makeCachingReaderBuilder(tracer),
|
||||
cs::localReaderBuilder,
|
||||
cs.subscriptionBuilder(subScheduler),
|
||||
logsOracleConfig,
|
||||
logsOracleScheduler,
|
||||
tracer,
|
||||
).also { register(it, name) }
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,6 @@ open class SchedulersConfig {
|
||||
return makeScheduler("sub-scheduler", 4, monitoringConfig)
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun logsOracleScheduler(monitoringConfig: MonitoringConfig): Scheduler {
|
||||
return makeScheduler("logs-oracle", 4, monitoringConfig)
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun multistreamEventsScheduler(monitoringConfig: MonitoringConfig): Scheduler {
|
||||
return makeScheduler("events-scheduler", 4, monitoringConfig)
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.emeraldpay.dshackle.startup.configure
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import io.emeraldpay.dshackle.FileResolver
|
||||
import io.emeraldpay.dshackle.config.ChainsConfig
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||
import io.emeraldpay.dshackle.foundation.ChainOptions
|
||||
import io.emeraldpay.dshackle.startup.QuorumForLabels
|
||||
@@ -24,12 +23,11 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||
@Component
|
||||
class BitcoinUpstreamCreator(
|
||||
chainsConfig: ChainsConfig,
|
||||
indexConfig: IndexConfig,
|
||||
callTargets: CallTargetsHolder,
|
||||
private val genericConnectorFactoryCreator: ConnectorFactoryCreator,
|
||||
private val fileResolver: FileResolver,
|
||||
private val headScheduler: Scheduler,
|
||||
) : UpstreamCreator(chainsConfig, indexConfig, callTargets) {
|
||||
) : UpstreamCreator(chainsConfig, callTargets) {
|
||||
private var seq = AtomicInteger(0)
|
||||
|
||||
override fun createUpstream(
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.emeraldpay.dshackle.startup.configure
|
||||
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import io.emeraldpay.dshackle.config.ChainsConfig
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||
import io.emeraldpay.dshackle.config.hot.CompatibleVersionsRules
|
||||
import io.emeraldpay.dshackle.foundation.ChainOptions
|
||||
@@ -13,11 +12,10 @@ import java.util.function.Supplier
|
||||
@Component
|
||||
class EthereumUpstreamCreator(
|
||||
chainsConfig: ChainsConfig,
|
||||
indexConfig: IndexConfig,
|
||||
callTargets: CallTargetsHolder,
|
||||
connectorFactoryCreatorResolver: ConnectorFactoryCreatorResolver,
|
||||
versionRules: Supplier<CompatibleVersionsRules?>,
|
||||
) : GenericUpstreamCreator(chainsConfig, indexConfig, callTargets, connectorFactoryCreatorResolver, versionRules) {
|
||||
) : GenericUpstreamCreator(chainsConfig, callTargets, connectorFactoryCreatorResolver, versionRules) {
|
||||
|
||||
override fun createUpstream(
|
||||
upstreamsConfig: UpstreamsConfig.Upstream<*>,
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.emeraldpay.dshackle.startup.configure
|
||||
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import io.emeraldpay.dshackle.config.ChainsConfig
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||
import io.emeraldpay.dshackle.config.hot.CompatibleVersionsRules
|
||||
import io.emeraldpay.dshackle.foundation.ChainOptions
|
||||
@@ -19,11 +18,10 @@ import java.util.function.Supplier
|
||||
@Component
|
||||
open class GenericUpstreamCreator(
|
||||
chainsConfig: ChainsConfig,
|
||||
indexConfig: IndexConfig,
|
||||
callTargets: CallTargetsHolder,
|
||||
private val connectorFactoryCreatorResolver: ConnectorFactoryCreatorResolver,
|
||||
private val versionRules: Supplier<CompatibleVersionsRules?>,
|
||||
) : UpstreamCreator(chainsConfig, indexConfig, callTargets) {
|
||||
) : UpstreamCreator(chainsConfig, callTargets) {
|
||||
private val hashes = HashSet<Short>()
|
||||
|
||||
override fun createUpstream(
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.emeraldpay.dshackle.startup.configure
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import io.emeraldpay.dshackle.Global
|
||||
import io.emeraldpay.dshackle.config.ChainsConfig
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||
import io.emeraldpay.dshackle.foundation.ChainOptions
|
||||
import io.emeraldpay.dshackle.foundation.ChainOptions.Options
|
||||
@@ -17,7 +16,6 @@ import kotlin.math.abs
|
||||
|
||||
abstract class UpstreamCreator(
|
||||
private val chainsConfig: ChainsConfig,
|
||||
private val indexConfig: IndexConfig,
|
||||
private val callTargets: CallTargetsHolder,
|
||||
) {
|
||||
protected val log: Logger = LoggerFactory.getLogger(this::class.java)
|
||||
@@ -83,7 +81,7 @@ abstract class UpstreamCreator(
|
||||
}
|
||||
|
||||
ManagedCallMethods(
|
||||
delegate = callTargets.getDefaultMethods(chain, indexConfig.isChainEnabled(chain), options, config.connection),
|
||||
delegate = callTargets.getDefaultMethods(chain, options, config.connection),
|
||||
enabled = config.methods?.enabled?.map { it.name }?.toSet() ?: emptySet(),
|
||||
disabled = config.methods?.disabled?.map { it.name }?.toSet() ?: emptySet(),
|
||||
groupsEnabled = config.methodGroups?.enabled ?: emptySet(),
|
||||
@@ -99,7 +97,7 @@ abstract class UpstreamCreator(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callTargets.getDefaultMethods(chain, indexConfig.isChainEnabled(chain), options, config.connection)
|
||||
callTargets.getDefaultMethods(chain, options, config.connection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,22 +29,20 @@ class CallTargetsHolder {
|
||||
|
||||
fun getDefaultMethods(
|
||||
chain: Chain,
|
||||
hasLogsOracle: Boolean,
|
||||
options: ChainOptions.Options,
|
||||
connection: UpstreamsConfig.UpstreamConnection?,
|
||||
): CallMethods {
|
||||
return callTargets[chain] ?: return setupDefaultMethods(chain, hasLogsOracle, options, connection)
|
||||
return callTargets[chain] ?: return setupDefaultMethods(chain, options, connection)
|
||||
}
|
||||
|
||||
private fun setupDefaultMethods(
|
||||
chain: Chain,
|
||||
hasLogsOracle: Boolean,
|
||||
options: ChainOptions.Options,
|
||||
connection: UpstreamsConfig.UpstreamConnection?,
|
||||
): CallMethods {
|
||||
val created = when (chain.type) {
|
||||
BITCOIN -> DefaultBitcoinMethods(options.providesBalance == true)
|
||||
ETHEREUM -> DefaultEthereumMethods(chain, hasLogsOracle)
|
||||
ETHEREUM -> DefaultEthereumMethods(chain)
|
||||
STARKNET -> DefaultStarknetMethods(chain)
|
||||
POLKADOT -> DefaultPolkadotMethods(chain)
|
||||
SOLANA -> DefaultSolanaMethods()
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package io.emeraldpay.dshackle.upstream
|
||||
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.cloud.sleuth.Tracer
|
||||
import reactor.core.Disposable
|
||||
import reactor.core.publisher.Mono
|
||||
import reactor.core.scheduler.Scheduler
|
||||
|
||||
class LogsOracle(
|
||||
private val config: IndexConfig.Index,
|
||||
private val upstream: Multistream,
|
||||
private val scheduler: Scheduler,
|
||||
private val tracer: Tracer,
|
||||
) {
|
||||
|
||||
private val log = LoggerFactory.getLogger(LogsOracle::class.java)
|
||||
|
||||
private var subscription: Disposable? = null
|
||||
private var conn: org.drpc.logsoracle.LogsOracle? = null
|
||||
|
||||
fun start() {
|
||||
log.info("liboracle starting: store=${config.store}, ram=${config.ram_limit}")
|
||||
|
||||
conn = org.drpc.logsoracle.LogsOracle(config.store, config.ram_limit ?: 0L)
|
||||
subscription = upstream.getHead().getFlux()
|
||||
.publishOn(scheduler)
|
||||
.doOnError { t -> log.error("Failed to subscribe head for oracle", t) }
|
||||
.doFinally { log.info("unsubscribe head") }
|
||||
.subscribe { setHeight(it.height) }
|
||||
|
||||
setUpstream(config.rpc)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
log.info("liboracle closed")
|
||||
|
||||
subscription?.dispose()
|
||||
subscription = null
|
||||
|
||||
conn?.close()
|
||||
}
|
||||
|
||||
fun estimate(
|
||||
limit: Long?,
|
||||
fromBlock: Long,
|
||||
toBlock: Long,
|
||||
address: List<String>,
|
||||
topics: List<List<String>>,
|
||||
): Mono<String> {
|
||||
val requestSpan = tracer.currentSpan()
|
||||
|
||||
return Mono.fromCallable {
|
||||
val span = tracer.nextSpan(requestSpan).name("emerald.blockchain/logsoracle").start()
|
||||
log.info("query: from=$fromBlock, to=$toBlock, limit=$limit")
|
||||
|
||||
try {
|
||||
val estimate = conn?.Query(limit, fromBlock, toBlock, address, topics)
|
||||
"{\"total\":$estimate,\"overflow\":false}"
|
||||
} catch (e: org.drpc.logsoracle.LogsOracle.LogsOracleException) {
|
||||
if (e.isQueryOverflow()) {
|
||||
"{\"total\":-1,\"overflow\":true}"
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
} finally {
|
||||
span.end()
|
||||
}
|
||||
}
|
||||
.publishOn(scheduler)
|
||||
}
|
||||
|
||||
fun setHeight(height: Long) {
|
||||
try {
|
||||
log.info("update state: height=$height")
|
||||
conn?.UpdateHeight(height)
|
||||
} catch (e: Exception) {
|
||||
log.error("couldn't set height", e)
|
||||
}
|
||||
}
|
||||
|
||||
fun setUpstream(upstream: String) {
|
||||
try {
|
||||
log.info("update state: upstream=$upstream")
|
||||
conn?.SetUpstream(upstream)
|
||||
} catch (e: Exception) {
|
||||
log.error("couldn't set upstream", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import io.emeraldpay.dshackle.upstream.ethereum.rpc.RpcException
|
||||
*/
|
||||
class DefaultEthereumMethods(
|
||||
private val chain: Chain,
|
||||
private val hasLogsOracle: Boolean = false,
|
||||
) : CallMethods {
|
||||
|
||||
private val version = "\"EmeraldDshackle/${Global.version}\""
|
||||
@@ -613,7 +612,6 @@ class DefaultEthereumMethods(
|
||||
specialMethods +
|
||||
headVerifiedMethods -
|
||||
chainUnsupportedMethods(chain) +
|
||||
getDrpcVendorMethods(chain) +
|
||||
getChainSpecificMethods(chain)
|
||||
}
|
||||
|
||||
@@ -632,15 +630,6 @@ class DefaultEthereumMethods(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDrpcVendorMethods(chain: Chain): List<String> {
|
||||
val supported = mutableListOf<String>()
|
||||
|
||||
// Currently tested on eth mainnet only, should potentially work for all compatible ones.
|
||||
if (chain == Chain.ETHEREUM__MAINNET && hasLogsOracle) { supported.add("drpc_getLogsEstimate") }
|
||||
|
||||
return supported
|
||||
}
|
||||
|
||||
private fun getChainSpecificMethods(chain: Chain): List<String> {
|
||||
return when (chain) {
|
||||
Chain.OPTIMISM__MAINNET, Chain.OPTIMISM__SEPOLIA ->
|
||||
|
||||
@@ -14,7 +14,6 @@ import io.emeraldpay.dshackle.upstream.EgressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.GenericSingleCallValidator
|
||||
import io.emeraldpay.dshackle.upstream.Head
|
||||
import io.emeraldpay.dshackle.upstream.IngressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.LogsOracle
|
||||
import io.emeraldpay.dshackle.upstream.Multistream
|
||||
import io.emeraldpay.dshackle.upstream.SingleValidator
|
||||
import io.emeraldpay.dshackle.upstream.Upstream
|
||||
@@ -65,9 +64,8 @@ object EthereumChainSpecific : AbstractPollChainSpecific() {
|
||||
cachingReader: CachingReader,
|
||||
methods: CallMethods,
|
||||
head: Head,
|
||||
logsOracle: LogsOracle?,
|
||||
): Mono<ChainReader> {
|
||||
return Mono.just(EthereumLocalReader(cachingReader as EthereumCachingReader, methods, head, logsOracle))
|
||||
return Mono.just(EthereumLocalReader(cachingReader as EthereumCachingReader, methods, head))
|
||||
}
|
||||
|
||||
override fun subscriptionBuilder(headScheduler: Scheduler): (Multistream) -> EgressSubscription {
|
||||
|
||||
@@ -22,7 +22,6 @@ import io.emeraldpay.dshackle.reader.ChainReader
|
||||
import io.emeraldpay.dshackle.upstream.ChainRequest
|
||||
import io.emeraldpay.dshackle.upstream.ChainResponse
|
||||
import io.emeraldpay.dshackle.upstream.Head
|
||||
import io.emeraldpay.dshackle.upstream.LogsOracle
|
||||
import io.emeraldpay.dshackle.upstream.Selector
|
||||
import io.emeraldpay.dshackle.upstream.calls.CallMethods
|
||||
import io.emeraldpay.dshackle.upstream.ethereum.hex.HexQuantity
|
||||
@@ -46,7 +45,6 @@ class EthereumLocalReader(
|
||||
private val reader: EthereumCachingReader,
|
||||
private val methods: CallMethods,
|
||||
private val head: Head,
|
||||
private val logsOracle: LogsOracle?,
|
||||
) : ChainReader {
|
||||
|
||||
override fun read(key: ChainRequest): Mono<ChainResponse> {
|
||||
@@ -132,10 +130,6 @@ class EthereumLocalReader(
|
||||
.map { ChainResponse(it.data, null, it.resolvedUpstreamData) }
|
||||
}
|
||||
|
||||
method == "drpc_getLogsEstimate" -> {
|
||||
getLogsEstimate(params.list)
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -193,82 +187,4 @@ class EthereumLocalReader(
|
||||
return reader.blocksByHeightAsCont(upstreamFilter)
|
||||
.read(number).map { ChainResponse(it.data.json, null, it.resolvedUpstreamData) }
|
||||
}
|
||||
|
||||
fun getLogsEstimate(params: List<Any?>): Mono<ChainResponse>? {
|
||||
if (logsOracle == null) {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
if (params.size != 1 || params[0] == null) {
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Must provide 1 parameters")
|
||||
}
|
||||
|
||||
val req = params[0] as LinkedHashMap<String, Any?>
|
||||
|
||||
val limit = try { req.get("limit") as Int? } catch (_: IllegalArgumentException) {
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'limit' parameter")
|
||||
}
|
||||
|
||||
val fromBlock = try { parseBlockRef(req.get("fromBlock") as String?) } catch (_: IllegalArgumentException) {
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'fromBlock' parameter")
|
||||
}
|
||||
val toBlock = try { parseBlockRef(req.get("toBlock") as String?) } catch (_: IllegalArgumentException) {
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'toBlock' parameter")
|
||||
}
|
||||
val address: List<String> = try {
|
||||
val it = req.get("address") ?: listOf<String>()
|
||||
|
||||
if (it is String) {
|
||||
listOf<String>(it)
|
||||
} else {
|
||||
it as List<String>
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'address' parameter")
|
||||
}
|
||||
val topics: List<List<String>> = try {
|
||||
val tpcs = req.get("topics")?.let { it as List<Any?> } ?: listOf<Any?>()
|
||||
if (tpcs.size > 4) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
tpcs.map {
|
||||
if (it == null) {
|
||||
emptyList<String>()
|
||||
} else if (it is String) {
|
||||
listOf<String>(it)
|
||||
} else {
|
||||
it as List<String>
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
throw RpcException(RpcResponseError.CODE_INVALID_METHOD_PARAMS, "Invalid 'topics' parameter")
|
||||
}
|
||||
|
||||
return logsOracle.estimate(limit?.toLong(), fromBlock, toBlock, address, topics)
|
||||
.map { ChainResponse(it.toByteArray(), null, emptyList()) }
|
||||
}
|
||||
|
||||
private fun parseBlockRef(blockRef: String?): Long {
|
||||
when {
|
||||
blockRef == "earliest" -> {
|
||||
return 0
|
||||
}
|
||||
blockRef == null || blockRef == "finalized" || blockRef == "safe" || blockRef == "pending" || blockRef == "latest" -> {
|
||||
return head.getCurrentHeight() ?: throw Exception("couldn't get current head")
|
||||
}
|
||||
blockRef.startsWith("0x") -> {
|
||||
val quantity = HexQuantity.from(blockRef) ?: throw IllegalArgumentException()
|
||||
return quantity.value.let {
|
||||
if (it < BigInteger.valueOf(Long.MAX_VALUE) && it >= BigInteger.ZERO) {
|
||||
it.toLong()
|
||||
} else {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import io.emeraldpay.dshackle.upstream.EgressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.EmptyEgressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.Head
|
||||
import io.emeraldpay.dshackle.upstream.IngressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.LogsOracle
|
||||
import io.emeraldpay.dshackle.upstream.Multistream
|
||||
import io.emeraldpay.dshackle.upstream.NoIngressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.NoopCachingReader
|
||||
@@ -41,7 +40,6 @@ abstract class AbstractChainSpecific : ChainSpecific {
|
||||
cachingReader: CachingReader,
|
||||
methods: CallMethods,
|
||||
head: Head,
|
||||
logsOracle: LogsOracle?,
|
||||
): Mono<ChainReader> {
|
||||
return Mono.just(LocalReader(methods))
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import io.emeraldpay.dshackle.upstream.ChainRequest
|
||||
import io.emeraldpay.dshackle.upstream.EgressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.Head
|
||||
import io.emeraldpay.dshackle.upstream.IngressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.LogsOracle
|
||||
import io.emeraldpay.dshackle.upstream.Multistream
|
||||
import io.emeraldpay.dshackle.upstream.SingleValidator
|
||||
import io.emeraldpay.dshackle.upstream.Upstream
|
||||
@@ -51,7 +50,7 @@ import reactor.core.scheduler.Scheduler
|
||||
import java.util.function.Supplier
|
||||
|
||||
typealias SubscriptionBuilder = (Multistream) -> EgressSubscription
|
||||
typealias LocalReaderBuilder = (CachingReader, CallMethods, Head, LogsOracle?) -> Mono<ChainReader>
|
||||
typealias LocalReaderBuilder = (CachingReader, CallMethods, Head) -> Mono<ChainReader>
|
||||
typealias CachingReaderBuilder = (Multistream, Caches, Factory<CallMethods>) -> CachingReader
|
||||
typealias FinalizationDetectorBuilder = () -> FinalizationDetector
|
||||
|
||||
@@ -70,7 +69,6 @@ interface ChainSpecific {
|
||||
cachingReader: CachingReader,
|
||||
methods: CallMethods,
|
||||
head: Head,
|
||||
logsOracle: LogsOracle?,
|
||||
): Mono<ChainReader>
|
||||
|
||||
fun subscriptionBuilder(headScheduler: Scheduler): (Multistream) -> EgressSubscription
|
||||
|
||||
@@ -19,7 +19,6 @@ package io.emeraldpay.dshackle.upstream.generic
|
||||
import io.emeraldpay.api.proto.BlockchainOuterClass
|
||||
import io.emeraldpay.dshackle.Chain
|
||||
import io.emeraldpay.dshackle.cache.Caches
|
||||
import io.emeraldpay.dshackle.config.IndexConfig
|
||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||
import io.emeraldpay.dshackle.reader.ChainReader
|
||||
import io.emeraldpay.dshackle.upstream.CachingReader
|
||||
@@ -30,7 +29,6 @@ import io.emeraldpay.dshackle.upstream.EmptyHead
|
||||
import io.emeraldpay.dshackle.upstream.Head
|
||||
import io.emeraldpay.dshackle.upstream.HeadLagObserver
|
||||
import io.emeraldpay.dshackle.upstream.Lifecycle
|
||||
import io.emeraldpay.dshackle.upstream.LogsOracle
|
||||
import io.emeraldpay.dshackle.upstream.MergedHead
|
||||
import io.emeraldpay.dshackle.upstream.Multistream
|
||||
import io.emeraldpay.dshackle.upstream.Selector
|
||||
@@ -39,7 +37,6 @@ import io.emeraldpay.dshackle.upstream.Upstream
|
||||
import io.emeraldpay.dshackle.upstream.calls.CallSelector
|
||||
import io.emeraldpay.dshackle.upstream.forkchoice.PriorityForkChoice
|
||||
import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream
|
||||
import org.springframework.cloud.sleuth.Tracer
|
||||
import org.springframework.util.ConcurrentReferenceHashMap
|
||||
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType.WEAK
|
||||
import reactor.core.publisher.Flux
|
||||
@@ -56,9 +53,6 @@ open class GenericMultistream(
|
||||
cachingReaderBuilder: CachingReaderBuilder,
|
||||
private val localReaderBuilder: LocalReaderBuilder,
|
||||
private val subscriptionBuilder: SubscriptionBuilder,
|
||||
logsOracleConfig: IndexConfig.Index? = null,
|
||||
private val logsOracleScheduler: Scheduler,
|
||||
private val tracer: Tracer,
|
||||
) : Multistream(chain, caches, callSelector, multistreamEventsScheduler) {
|
||||
|
||||
private val cachingReader = cachingReaderBuilder(this, caches, getMethodsFactory())
|
||||
@@ -77,10 +71,6 @@ open class GenericMultistream(
|
||||
headScheduler,
|
||||
)
|
||||
|
||||
private val logsOracle: LogsOracle? = logsOracleConfig?.let {
|
||||
LogsOracle(logsOracleConfig, this, logsOracleScheduler, tracer)
|
||||
}
|
||||
|
||||
private var subscription: EgressSubscription = subscriptionBuilder(this)
|
||||
|
||||
private val filteredHeads: MutableMap<String, Head> =
|
||||
@@ -91,14 +81,12 @@ open class GenericMultistream(
|
||||
head.start()
|
||||
onHeadUpdated(head)
|
||||
cachingReader.start()
|
||||
logsOracle?.start()
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
super.stop()
|
||||
cachingReader.stop()
|
||||
filteredHeads.clear()
|
||||
logsOracle?.stop()
|
||||
}
|
||||
|
||||
override fun addHead(upstream: Upstream) {
|
||||
@@ -167,7 +155,7 @@ open class GenericMultistream(
|
||||
}
|
||||
|
||||
override fun getLocalReader(): Mono<ChainReader> {
|
||||
return localReaderBuilder(cachingReader, getMethods(), getHead(), logsOracle)
|
||||
return localReaderBuilder(cachingReader, getMethods(), getHead())
|
||||
}
|
||||
|
||||
override fun getEgressSubscription(): EgressSubscription {
|
||||
|
||||
@@ -16,7 +16,6 @@ import io.emeraldpay.dshackle.upstream.EgressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.GenericSingleCallValidator
|
||||
import io.emeraldpay.dshackle.upstream.Head
|
||||
import io.emeraldpay.dshackle.upstream.IngressSubscription
|
||||
import io.emeraldpay.dshackle.upstream.LogsOracle
|
||||
import io.emeraldpay.dshackle.upstream.Multistream
|
||||
import io.emeraldpay.dshackle.upstream.SingleValidator
|
||||
import io.emeraldpay.dshackle.upstream.Upstream
|
||||
@@ -80,7 +79,6 @@ object PolkadotChainSpecific : AbstractPollChainSpecific() {
|
||||
cachingReader: CachingReader,
|
||||
methods: CallMethods,
|
||||
head: Head,
|
||||
logsOracle: LogsOracle?,
|
||||
): Mono<ChainReader> {
|
||||
return Mono.just(LocalReader(methods))
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -392,7 +392,7 @@ class NativeCallSpec extends Specification {
|
||||
def "Prepare call adds height selector for not-lagging quorum"() {
|
||||
setup:
|
||||
def methods = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
["foo_bar"] as Set, [] as Set, [] as Set, [] as Set
|
||||
)
|
||||
methods.setQuorum("foo_bar", "not_lagging")
|
||||
@@ -434,7 +434,7 @@ class NativeCallSpec extends Specification {
|
||||
def "Prepare call adds decorator for eth_newFilter"() {
|
||||
setup:
|
||||
def methods = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
["eth_newFilter"] as Set, [] as Set, [] as Set, [] as Set
|
||||
)
|
||||
methods.setQuorum("eth_newFilter", "always")
|
||||
@@ -466,7 +466,7 @@ class NativeCallSpec extends Specification {
|
||||
def "Prepare call adds decorator for eth_getFilterChanges"() {
|
||||
setup:
|
||||
def methods = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
["eth_getFilterChanges"] as Set, [] as Set, [] as Set, [] as Set
|
||||
)
|
||||
def multistream = new MultistreamHolderMock.EthereumMultistreamMock(Chain.ETHEREUM__MAINNET, TestingCommons.upstream())
|
||||
@@ -497,7 +497,7 @@ class NativeCallSpec extends Specification {
|
||||
def "Prepare call adds decorator for eth_uninstallFilter"() {
|
||||
setup:
|
||||
def methods = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
["eth_uninstallFilter"] as Set, [] as Set, [] as Set, [] as Set
|
||||
)
|
||||
def multistream = new MultistreamHolderMock.EthereumMultistreamMock(Chain.ETHEREUM__MAINNET, TestingCommons.upstream())
|
||||
@@ -595,7 +595,7 @@ class NativeCallSpec extends Specification {
|
||||
setup:
|
||||
def quorum = new AlwaysQuorum()
|
||||
def methods = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
[] as Set, [] as Set, ["filter"] as Set, [] as Set
|
||||
)
|
||||
def multistream = new MultistreamHolderMock.EthereumMultistreamMock(Chain.ETHEREUM__MAINNET, new ArrayList<GenericUpstream>())
|
||||
@@ -628,7 +628,7 @@ class NativeCallSpec extends Specification {
|
||||
setup:
|
||||
def quorum = new AlwaysQuorum()
|
||||
def methods = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
[] as Set, [] as Set, ["filter"] as Set, [] as Set
|
||||
)
|
||||
def multistream = new MultistreamHolderMock.EthereumMultistreamMock(Chain.ETHEREUM__MAINNET, new ArrayList<GenericUpstream>())
|
||||
|
||||
@@ -38,7 +38,7 @@ class GenericUpstreamMock extends GenericUpstream {
|
||||
|
||||
static CallMethods allMethods() {
|
||||
new AggregatedCallMethods([
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
new DefaultBitcoinMethods(true),
|
||||
new DirectCallMethods(["eth_test"])
|
||||
])
|
||||
|
||||
@@ -52,8 +52,6 @@ class MultistreamHolderMock implements MultistreamHolder {
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(TestingCommons.tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
io.emeraldpay.dshackle.upstream.starknet.StarknetChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()),
|
||||
null, Schedulers.immediate(),
|
||||
TestingCommons.tracerMock()
|
||||
)
|
||||
upstreams[chain].addUpstream(up)
|
||||
} else {
|
||||
@@ -106,8 +104,8 @@ class MultistreamHolderMock implements MultistreamHolder {
|
||||
super(chain, Schedulers.immediate(), null, upstreams, caches, Schedulers.boundedElastic(),
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(new BraveTracer(null, null, null)),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()), null, Schedulers.immediate(),
|
||||
new BraveTracer(null, null, null))
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()),
|
||||
)
|
||||
}
|
||||
|
||||
EthereumMultistreamMock(@NotNull Chain chain, @NotNull List<GenericUpstream> upstreams) {
|
||||
|
||||
@@ -102,9 +102,6 @@ class TestingCommons {
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()),
|
||||
null,
|
||||
Schedulers.immediate(),
|
||||
tracerMock()
|
||||
).tap {
|
||||
it.processUpstreamsEvents(
|
||||
new UpstreamChangeEvent(Chain.ETHEREUM__MAINNET, up, UpstreamChangeEvent.ChangeType.ADDED)
|
||||
@@ -132,9 +129,7 @@ class TestingCommons {
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()),
|
||||
null,
|
||||
Schedulers.immediate(),
|
||||
tracerMock())
|
||||
)
|
||||
}
|
||||
|
||||
static Multistream multistreamClassicWithoutUpstreams(Chain chain) {
|
||||
@@ -142,9 +137,7 @@ class TestingCommons {
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()),
|
||||
null,
|
||||
Schedulers.immediate(),
|
||||
tracerMock())
|
||||
)
|
||||
}
|
||||
|
||||
static FileResolver fileResolver() {
|
||||
|
||||
@@ -37,7 +37,7 @@ import static java.util.List.of
|
||||
|
||||
class FilteredApisSpec extends Specification {
|
||||
|
||||
def ethereumTargets = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def ethereumTargets = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
|
||||
def "Verifies labels"() {
|
||||
setup:
|
||||
|
||||
@@ -57,7 +57,7 @@ class MultistreamSpec extends Specification {
|
||||
Schedulers.boundedElastic(),
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(TestingCommons.tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()), null, Schedulers.immediate(), TestingCommons.tracerMock())
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()))
|
||||
when:
|
||||
aggr.onUpstreamsUpdated()
|
||||
def act = aggr.getMethods()
|
||||
@@ -192,7 +192,7 @@ class MultistreamSpec extends Specification {
|
||||
Schedulers.boundedElastic(),
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(TestingCommons.tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()), null, Schedulers.immediate(), TestingCommons.tracerMock())
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()))
|
||||
|
||||
expect:
|
||||
multistream.getHead(new Selector.LabelMatcher("provider", ["internal"])).is(up1.ethereumHeadMock)
|
||||
@@ -265,7 +265,7 @@ class MultistreamSpec extends Specification {
|
||||
Schedulers.boundedElastic(),
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(TestingCommons.tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()), null, Schedulers.immediate(), TestingCommons.tracerMock())
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()))
|
||||
when:
|
||||
ms.processUpstreamsEvents(
|
||||
new UpstreamChangeEvent(Chain.ETHEREUM__MAINNET, up1, UpstreamChangeEvent.ChangeType.ADDED)
|
||||
@@ -296,7 +296,7 @@ class MultistreamSpec extends Specification {
|
||||
Schedulers.boundedElastic(),
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(TestingCommons.tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()), null, Schedulers.immediate(), TestingCommons.tracerMock())
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()))
|
||||
def head1 = createBlock(250, "0x0d050c785de17179f935b9b93aca09c442964cc59972c71ae68e74731448401b")
|
||||
def head2 = createBlock(270, "0x0d050c785de17179f935b9b93aca09c442964cc59972c71ae68e74731448402b")
|
||||
def head3 = createBlock(100, "0x0d050c785de17179f935b9b93aca09c442964cc59972c71ae68e74731448412b")
|
||||
@@ -331,7 +331,7 @@ class MultistreamSpec extends Specification {
|
||||
Schedulers.boundedElastic(),
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(TestingCommons.tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()), null, Schedulers.immediate(), TestingCommons.tracerMock())
|
||||
EthereumChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()))
|
||||
multistream.processUpstreamsEvents(
|
||||
new UpstreamChangeEvent(Chain.ETHEREUM__MAINNET, up1, UpstreamChangeEvent.ChangeType.ADDED)
|
||||
)
|
||||
@@ -369,7 +369,7 @@ class MultistreamSpec extends Specification {
|
||||
Schedulers.boundedElastic(),
|
||||
EthereumChainSpecific.INSTANCE.makeCachingReaderBuilder(TestingCommons.tracerMock()),
|
||||
EthereumChainSpecific.INSTANCE.&localReaderBuilder,
|
||||
StarknetChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()), null, Schedulers.immediate(), TestingCommons.tracerMock())
|
||||
StarknetChainSpecific.INSTANCE.subscriptionBuilder(Schedulers.boundedElastic()))
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -7,7 +7,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "eth_chainId is available"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
when:
|
||||
def act = methods.isAvailable("eth_chainId")
|
||||
then:
|
||||
@@ -16,7 +16,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "eth_chainId is hardcoded"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
when:
|
||||
def act = methods.isHardcoded("eth_chainId")
|
||||
then:
|
||||
@@ -25,7 +25,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "eth_chainId is not callable"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
when:
|
||||
def act = methods.isCallable("eth_chainId")
|
||||
then:
|
||||
@@ -34,7 +34,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "Provides hardcoded correct chainId"() {
|
||||
expect:
|
||||
new String(new DefaultEthereumMethods(chain, false).executeHardcoded("eth_chainId")) == id
|
||||
new String(new DefaultEthereumMethods(chain).executeHardcoded("eth_chainId")) == id
|
||||
where:
|
||||
chain | id
|
||||
Chain.ETHEREUM__MAINNET | '"0x1"'
|
||||
@@ -43,7 +43,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "Optimism chain unsupported methods"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.OPTIMISM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.OPTIMISM__MAINNET)
|
||||
when:
|
||||
def acc = methods.isAvailable("eth_getAccounts")
|
||||
def trans = methods.isAvailable("eth_sendTransaction")
|
||||
@@ -54,7 +54,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "Has supported specific methods"() {
|
||||
expect:
|
||||
new DefaultEthereumMethods(chain, false).getSupportedMethods().containsAll(methods)
|
||||
new DefaultEthereumMethods(chain).getSupportedMethods().containsAll(methods)
|
||||
where:
|
||||
chain | methods
|
||||
Chain.POLYGON__MAINNET | ["bor_getAuthor",
|
||||
@@ -68,7 +68,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "Has no filter methods by default"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
when:
|
||||
def act = methods.getSupportedMethods().findAll { it.containsIgnoreCase("filter") }
|
||||
then:
|
||||
@@ -77,7 +77,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "Has no trace methods by default"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
when:
|
||||
def act = methods.getSupportedMethods().findAll { it.containsIgnoreCase("trace") }
|
||||
then:
|
||||
@@ -86,7 +86,7 @@ class DefaultEthereumMethodsSpec extends Specification {
|
||||
|
||||
def "Default eth methods are available"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
expect:
|
||||
methods.isAvailable(method)
|
||||
where:
|
||||
|
||||
@@ -94,7 +94,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
def "Use custom quorum if provided"() {
|
||||
setup:
|
||||
def managed = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
["eth_test", "eth_foo", "eth_bar"] as Set,
|
||||
[] as Set,
|
||||
[] as Set,
|
||||
@@ -120,7 +120,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
|
||||
def "Doesn't reuse same instance"() {
|
||||
def managed = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
["eth_test"] as Set,
|
||||
[] as Set,
|
||||
[] as Set,
|
||||
@@ -145,7 +145,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
def "Test enable method group"() {
|
||||
setup:
|
||||
def managed = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
[] as Set,
|
||||
[] as Set,
|
||||
["filter"] as Set,
|
||||
@@ -169,7 +169,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
def "Test enable method group minus one"() {
|
||||
setup:
|
||||
def managed = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
[] as Set,
|
||||
["eth_newPendingTransactionFilter"] as Set,
|
||||
["filter"] as Set,
|
||||
@@ -193,7 +193,7 @@ class ManagedCallMethodsSpec extends Specification {
|
||||
def "Test disabled group not disable enabled method"() {
|
||||
setup:
|
||||
def managed = new ManagedCallMethods(
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false),
|
||||
new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET),
|
||||
["eth_newPendingTransactionFilter"] as Set,
|
||||
[] as Set,
|
||||
[] as Set,
|
||||
|
||||
@@ -45,7 +45,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
transactions = []
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -80,7 +80,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
transactions = []
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -107,7 +107,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
def "Produce empty result on non-existing block"() {
|
||||
setup:
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -140,7 +140,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
transactions = []
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -172,7 +172,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
blockHash = BlockHash.from(hash1)
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -205,7 +205,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
blockHash = BlockHash.from(hash1)
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -238,7 +238,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
blockHash = BlockHash.from(hash1)
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -268,7 +268,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
blockHash = BlockHash.from(hash1)
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
def caches = Mock(Caches) {
|
||||
// note that the Caches needs a Height value, otherwise it's not cached
|
||||
@@ -297,7 +297,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
def "Produce empty on non-existing tx"() {
|
||||
setup:
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
Stub(Multistream), Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -327,7 +327,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
}
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -358,7 +358,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
}
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
1 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
@@ -392,7 +392,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
transactions = []
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
3 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
3 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
def result = Mono.just(
|
||||
new RequestReader.Result(
|
||||
@@ -432,7 +432,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
transactions = []
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
3 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
3 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
def result = Mono.just(
|
||||
new RequestReader.Result(
|
||||
@@ -469,7 +469,7 @@ class EthereumDirectReaderSpec extends Specification {
|
||||
}
|
||||
}
|
||||
def calls = Mock(Factory) {
|
||||
4 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
4 * create() >> new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
}
|
||||
EthereumDirectReader reader = new EthereumDirectReader(
|
||||
up, Caches.default(), new CurrentBlockCache(), calls, TestingCommons.tracerMock()
|
||||
|
||||
@@ -25,17 +25,16 @@ class EthereumLocalReaderSpec extends Specification {
|
||||
|
||||
def "Calls hardcoded"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
def router = new EthereumLocalReader(
|
||||
new EthereumCachingReader(
|
||||
TestingCommons.multistream(TestingCommons.api()),
|
||||
Caches.default(),
|
||||
ConstantFactory.constantFactory(new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)),
|
||||
ConstantFactory.constantFactory(new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)),
|
||||
TestingCommons.tracerMock()
|
||||
),
|
||||
methods,
|
||||
new EmptyHead(),
|
||||
null
|
||||
)
|
||||
when:
|
||||
def act = router.read(new ChainRequest("eth_coinbase", new ListParams())).block(Duration.ofSeconds(1))
|
||||
@@ -45,17 +44,16 @@ class EthereumLocalReaderSpec extends Specification {
|
||||
|
||||
def "Returns empty if nonce set"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
def router = new EthereumLocalReader(
|
||||
new EthereumCachingReader(
|
||||
TestingCommons.multistream(TestingCommons.api()),
|
||||
Caches.default(),
|
||||
ConstantFactory.constantFactory(new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)),
|
||||
ConstantFactory.constantFactory(new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)),
|
||||
TestingCommons.tracerMock()
|
||||
),
|
||||
methods,
|
||||
new EmptyHead(),
|
||||
null
|
||||
)
|
||||
when:
|
||||
def act = router.read(new ChainRequest("eth_getTransactionByHash", new ListParams(["test"]), 10))
|
||||
@@ -78,8 +76,8 @@ class EthereumLocalReaderSpec extends Specification {
|
||||
)
|
||||
}
|
||||
}
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def router = new EthereumLocalReader(reader, methods, head, null)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
def router = new EthereumLocalReader(reader, methods, head)
|
||||
|
||||
when:
|
||||
def act = router.getBlockByNumber(["latest", false], Selector.UpstreamFilter.default)
|
||||
@@ -106,8 +104,8 @@ class EthereumLocalReaderSpec extends Specification {
|
||||
)
|
||||
}
|
||||
}
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def router = new EthereumLocalReader(reader, methods, head, null)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
def router = new EthereumLocalReader(reader, methods, head)
|
||||
|
||||
when:
|
||||
def act = router.getBlockByNumber(["earliest", false], Selector.UpstreamFilter.default)
|
||||
@@ -134,8 +132,8 @@ class EthereumLocalReaderSpec extends Specification {
|
||||
)
|
||||
}
|
||||
}
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def router = new EthereumLocalReader(reader, methods, head, null)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
def router = new EthereumLocalReader(reader, methods, head)
|
||||
|
||||
when:
|
||||
def act = router.getBlockByNumber(["0x123ef", false], Selector.UpstreamFilter.default)
|
||||
@@ -160,8 +158,8 @@ class EthereumLocalReaderSpec extends Specification {
|
||||
)
|
||||
}
|
||||
}
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def router = new EthereumLocalReader(reader, methods, head, null)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
def router = new EthereumLocalReader(reader, methods, head)
|
||||
|
||||
when:
|
||||
def act = router.read(
|
||||
@@ -188,8 +186,8 @@ class EthereumLocalReaderSpec extends Specification {
|
||||
_ * txByHashAsCont(Selector.UpstreamFilter.default) >> new EmptyReader<>()
|
||||
_ * blocksByHeightAsCont(Selector.UpstreamFilter.default) >> new EmptyReader<>()
|
||||
}
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET, false)
|
||||
def router = new EthereumLocalReader(reader, methods, head, null)
|
||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM__MAINNET)
|
||||
def router = new EthereumLocalReader(reader, methods, head)
|
||||
|
||||
when:
|
||||
def act = router.getBlockByNumber(["0x0", true], Selector.UpstreamFilter.default)
|
||||
|
||||
@@ -180,9 +180,6 @@ class ReloadConfigTest {
|
||||
cs.makeCachingReaderBuilder(mock<Tracer>()),
|
||||
cs::localReaderBuilder,
|
||||
cs.subscriptionBuilder(Schedulers.boundedElastic()),
|
||||
null,
|
||||
Schedulers.fromExecutor(Executors.newFixedThreadPool(6)),
|
||||
mock<Tracer>(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user