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.
Reference in New Issue
Block a user