rename readers/routers according to their functions
This commit is contained in:
@@ -126,7 +126,7 @@ class QuorumRpcReader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun callApi(api: Upstream, key: JsonRpcRequest): Mono<Tuple3<ByteArray, Optional<ResponseSigner.Signature>, Upstream>> {
|
fun callApi(api: Upstream, key: JsonRpcRequest): Mono<Tuple3<ByteArray, Optional<ResponseSigner.Signature>, Upstream>> {
|
||||||
return api.getApi()
|
return api.getIngressReader()
|
||||||
.read(key)
|
.read(key)
|
||||||
.flatMap { response ->
|
.flatMap { response ->
|
||||||
response.requireResult()
|
response.requireResult()
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ open class NativeCall(
|
|||||||
if (method in DefaultEthereumMethods.newFilterMethods) CreateFilterDecorator() else NoneResultDecorator()
|
if (method in DefaultEthereumMethods.newFilterMethods) CreateFilterDecorator() else NoneResultDecorator()
|
||||||
|
|
||||||
fun fetch(ctx: ValidCallContext<ParsedCallDetails>): Mono<CallResult> {
|
fun fetch(ctx: ValidCallContext<ParsedCallDetails>): Mono<CallResult> {
|
||||||
return ctx.upstream.getRoutedApi(localRouterEnabled)
|
return ctx.upstream.getLocalReader(localRouterEnabled)
|
||||||
.flatMap { api ->
|
.flatMap { api ->
|
||||||
api.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params, ctx.nonce, ctx.forwardedSelector))
|
api.read(JsonRpcRequest(ctx.payload.method, ctx.payload.params, ctx.nonce, ctx.forwardedSelector))
|
||||||
.flatMap(JsonRpcResponse::requireResult)
|
.flatMap(JsonRpcResponse::requireResult)
|
||||||
|
|||||||
@@ -173,9 +173,9 @@ abstract class Multistream(
|
|||||||
/**
|
/**
|
||||||
* Finds an API that leverages caches and other optimizations/transformations of the request.
|
* Finds an API that leverages caches and other optimizations/transformations of the request.
|
||||||
*/
|
*/
|
||||||
abstract fun getRoutedApi(localEnabled: Boolean): Mono<JsonRpcReader>
|
abstract fun getLocalReader(localEnabled: Boolean): Mono<JsonRpcReader>
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
throw NotImplementedError("Immediate direct API is not implemented for Aggregated Upstream")
|
throw NotImplementedError("Immediate direct API is not implemented for Aggregated Upstream")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,12 @@ interface Upstream {
|
|||||||
fun getStatus(): UpstreamAvailability
|
fun getStatus(): UpstreamAvailability
|
||||||
fun observeStatus(): Flux<UpstreamAvailability>
|
fun observeStatus(): Flux<UpstreamAvailability>
|
||||||
fun getHead(): Head
|
fun getHead(): Head
|
||||||
fun getApi(): JsonRpcReader
|
|
||||||
|
/**
|
||||||
|
* Get an actual reader that access the current upstream
|
||||||
|
*/
|
||||||
|
fun getIngressReader(): JsonRpcReader
|
||||||
|
|
||||||
fun getOptions(): UpstreamsConfig.Options
|
fun getOptions(): UpstreamsConfig.Options
|
||||||
fun getRole(): UpstreamsConfig.UpstreamRole
|
fun getRole(): UpstreamsConfig.UpstreamRole
|
||||||
fun setLag(lag: Long)
|
fun setLag(lag: Long)
|
||||||
|
|||||||
@@ -100,11 +100,11 @@ open class BitcoinMultistream(
|
|||||||
val apis = getApiSource(matcher)
|
val apis = getApiSource(matcher)
|
||||||
apis.request(1)
|
apis.request(1)
|
||||||
return Mono.from(apis)
|
return Mono.from(apis)
|
||||||
.map(Upstream::getApi)
|
.map(Upstream::getIngressReader)
|
||||||
.switchIfEmpty(Mono.error(Exception("No API available for $chain")))
|
.switchIfEmpty(Mono.error(Exception("No API available for $chain")))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getRoutedApi(localEnabled: Boolean): Mono<JsonRpcReader> {
|
override fun getLocalReader(localEnabled: Boolean): Mono<JsonRpcReader> {
|
||||||
return Mono.just(callRouter)
|
return Mono.just(callRouter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ open class BitcoinRpcUpstream(
|
|||||||
return head
|
return head
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return directApi
|
return directApi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ open class ERC20Balance {
|
|||||||
|
|
||||||
open fun getBalance(upstream: EthereumPosRpcUpstream, token: ERC20Token, address: Address): Mono<BigInteger> {
|
open fun getBalance(upstream: EthereumPosRpcUpstream, token: ERC20Token, address: Address): Mono<BigInteger> {
|
||||||
return upstream
|
return upstream
|
||||||
.getApi()
|
.getIngressReader()
|
||||||
.read(prepareEthCall(token, address, upstream.getHead()))
|
.read(prepareEthCall(token, address, upstream.getHead()))
|
||||||
.flatMap(JsonRpcResponse::requireStringResult)
|
.flatMap(JsonRpcResponse::requireStringResult)
|
||||||
.map { Hex32.from(it).asQuantity().value }
|
.map { Hex32.from(it).asQuantity().value }
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import java.math.BigInteger
|
|||||||
*
|
*
|
||||||
* @see EthereumCachingReader
|
* @see EthereumCachingReader
|
||||||
*/
|
*/
|
||||||
class LocalCallRouter(
|
class EthereumLocalReader(
|
||||||
private val reader: EthereumCachingReader,
|
private val reader: EthereumCachingReader,
|
||||||
private val methods: CallMethods,
|
private val methods: CallMethods,
|
||||||
private val head: Head,
|
private val head: Head,
|
||||||
@@ -44,7 +44,7 @@ class LocalCallRouter(
|
|||||||
) : JsonRpcReader {
|
) : JsonRpcReader {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val log = LoggerFactory.getLogger(LocalCallRouter::class.java)
|
private val log = LoggerFactory.getLogger(EthereumLocalReader::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun read(key: JsonRpcRequest): Mono<JsonRpcResponse> {
|
override fun read(key: JsonRpcRequest): Mono<JsonRpcResponse> {
|
||||||
@@ -177,8 +177,8 @@ open class EthereumMultistream(
|
|||||||
return subscribe
|
return subscribe
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getRoutedApi(localEnabled: Boolean): Mono<JsonRpcReader> {
|
override fun getLocalReader(localEnabled: Boolean): Mono<JsonRpcReader> {
|
||||||
return Mono.just(LocalCallRouter(reader, getMethods(), getHead(), localEnabled))
|
return Mono.just(EthereumLocalReader(reader, getMethods(), getHead(), localEnabled))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getHead(mather: Selector.Matcher): Head =
|
override fun getHead(mather: Selector.Matcher): Head =
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ open class EthereumRpcUpstream(
|
|||||||
return connector.isRunning()
|
return connector.isRunning()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return connector.getApi()
|
return connector.getIngressReader()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isGrpc(): Boolean {
|
override fun isGrpc(): Boolean {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ open class EthereumUpstreamValidator(
|
|||||||
|
|
||||||
open fun validate(): Mono<UpstreamAvailability> {
|
open fun validate(): Mono<UpstreamAvailability> {
|
||||||
return upstream
|
return upstream
|
||||||
.getApi()
|
.getIngressReader()
|
||||||
.read(JsonRpcRequest("eth_syncing", listOf()))
|
.read(JsonRpcRequest("eth_syncing", listOf()))
|
||||||
.flatMap(JsonRpcResponse::requireResult)
|
.flatMap(JsonRpcResponse::requireResult)
|
||||||
.map { objectMapper.readValue(it, SyncingJson::class.java) }
|
.map { objectMapper.readValue(it, SyncingJson::class.java) }
|
||||||
@@ -62,7 +62,7 @@ open class EthereumUpstreamValidator(
|
|||||||
Mono.just(UpstreamAvailability.SYNCING)
|
Mono.just(UpstreamAvailability.SYNCING)
|
||||||
} else {
|
} else {
|
||||||
upstream
|
upstream
|
||||||
.getApi()
|
.getIngressReader()
|
||||||
.read(JsonRpcRequest("net_peerCount", listOf()))
|
.read(JsonRpcRequest("net_peerCount", listOf()))
|
||||||
.flatMap(JsonRpcResponse::requireStringResult)
|
.flatMap(JsonRpcResponse::requireStringResult)
|
||||||
.map(Integer::decode)
|
.map(Integer::decode)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.EthereumIngressSubscription
|
|||||||
interface EthereumConnector : Lifecycle {
|
interface EthereumConnector : Lifecycle {
|
||||||
fun getHead(): Head
|
fun getHead(): Head
|
||||||
|
|
||||||
fun getApi(): JsonRpcReader
|
fun getIngressReader(): JsonRpcReader
|
||||||
|
|
||||||
fun getIngressSubscription(): EthereumIngressSubscription
|
fun getIngressSubscription(): EthereumIngressSubscription
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ class EthereumRpcConnector(
|
|||||||
// do not set upstream to the WS, since it doesn't control the RPC upstream
|
// do not set upstream to the WS, since it doesn't control the RPC upstream
|
||||||
conn = wsFactory.create(null)
|
conn = wsFactory.create(null)
|
||||||
val subscriptions = WsSubscriptionsImpl(conn)
|
val subscriptions = WsSubscriptionsImpl(conn)
|
||||||
val wsHead = EthereumWsHead(id, AlwaysForkChoice(), blockValidator, getApi(), subscriptions)
|
val wsHead = EthereumWsHead(id, AlwaysForkChoice(), blockValidator, getIngressReader(), subscriptions)
|
||||||
// receive all new blocks through WebSockets, but also periodically verify with RPC in case if WS failed
|
// receive all new blocks through WebSockets, but also periodically verify with RPC in case if WS failed
|
||||||
val rpcHead = EthereumRpcHead(getApi(), AlwaysForkChoice(), id, blockValidator, Duration.ofSeconds(30))
|
val rpcHead = EthereumRpcHead(getIngressReader(), AlwaysForkChoice(), id, blockValidator, Duration.ofSeconds(30))
|
||||||
head = MergedHead(listOf(rpcHead, wsHead), forkChoice, "Merged for $id")
|
head = MergedHead(listOf(rpcHead, wsHead), forkChoice, "Merged for $id")
|
||||||
} else {
|
} else {
|
||||||
conn = null
|
conn = null
|
||||||
log.warn("Setting up connector for $id upstream with RPC-only access, less effective than WS+RPC")
|
log.warn("Setting up connector for $id upstream with RPC-only access, less effective than WS+RPC")
|
||||||
head = EthereumRpcHead(getApi(), forkChoice, id, blockValidator)
|
head = EthereumRpcHead(getIngressReader(), forkChoice, id, blockValidator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class EthereumRpcConnector(
|
|||||||
conn?.close()
|
conn?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return directReader
|
return directReader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,15 +16,15 @@ class EthereumWsConnector(
|
|||||||
blockValidator: BlockValidator
|
blockValidator: BlockValidator
|
||||||
) : EthereumConnector {
|
) : EthereumConnector {
|
||||||
private val conn: WsConnectionImpl
|
private val conn: WsConnectionImpl
|
||||||
private val api: JsonRpcReader
|
private val reader: JsonRpcReader
|
||||||
private val head: EthereumWsHead
|
private val head: EthereumWsHead
|
||||||
private val subscriptions: EthereumIngressSubscription
|
private val subscriptions: EthereumIngressSubscription
|
||||||
|
|
||||||
init {
|
init {
|
||||||
conn = wsFactory.create(upstream)
|
conn = wsFactory.create(upstream)
|
||||||
api = JsonRpcWsClient(conn)
|
reader = JsonRpcWsClient(conn)
|
||||||
val wsSubscriptions = WsSubscriptionsImpl(conn)
|
val wsSubscriptions = WsSubscriptionsImpl(conn)
|
||||||
head = EthereumWsHead(upstream.getId(), forkChoice, blockValidator, api, wsSubscriptions)
|
head = EthereumWsHead(upstream.getId(), forkChoice, blockValidator, reader, wsSubscriptions)
|
||||||
subscriptions = EthereumWsIngressSubscription(wsSubscriptions)
|
subscriptions = EthereumWsIngressSubscription(wsSubscriptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +42,8 @@ class EthereumWsConnector(
|
|||||||
head.stop()
|
head.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return api
|
return reader
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getIngressSubscription(): EthereumIngressSubscription {
|
override fun getIngressSubscription(): EthereumIngressSubscription {
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ open class EthereumPosMultiStream(
|
|||||||
return this as T
|
return this as T
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getRoutedApi(localEnabled: Boolean): Mono<JsonRpcReader> {
|
override fun getLocalReader(localEnabled: Boolean): Mono<JsonRpcReader> {
|
||||||
return Mono.just(LocalCallRouter(reader, getMethods(), getHead(), localEnabled))
|
return Mono.just(EthereumLocalReader(reader, getMethods(), getHead(), localEnabled))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEgressSubscription(): EthereumEgressSubscription {
|
override fun getEgressSubscription(): EthereumEgressSubscription {
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ open class EthereumPosRpcUpstream(
|
|||||||
return connector.isRunning()
|
return connector.isRunning()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return connector.getApi()
|
return connector.getIngressReader()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isGrpc(): Boolean {
|
override fun isGrpc(): Boolean {
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class BitcoinGrpcUpstream(
|
|||||||
return grpcHead
|
return grpcHead
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return defaultReader
|
return defaultReader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ open class EthereumGrpcUpstream(
|
|||||||
return grpcHead
|
return grpcHead
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return defaultReader
|
return defaultReader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ open class EthereumPosGrpcUpstream(
|
|||||||
return grpcHead
|
return grpcHead
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getApi(): JsonRpcReader {
|
override fun getIngressReader(): JsonRpcReader {
|
||||||
return defaultReader
|
return defaultReader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package io.emeraldpay.dshackle.quorum
|
|||||||
|
|
||||||
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
import io.emeraldpay.dshackle.config.UpstreamsConfig
|
||||||
import io.emeraldpay.dshackle.reader.Reader
|
import io.emeraldpay.dshackle.reader.Reader
|
||||||
import io.emeraldpay.dshackle.test.TestingCommons
|
|
||||||
import io.emeraldpay.dshackle.upstream.FilteredApis
|
import io.emeraldpay.dshackle.upstream.FilteredApis
|
||||||
import io.emeraldpay.dshackle.upstream.Selector
|
import io.emeraldpay.dshackle.upstream.Selector
|
||||||
import io.emeraldpay.dshackle.upstream.Upstream
|
import io.emeraldpay.dshackle.upstream.Upstream
|
||||||
@@ -40,7 +39,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
1 * getApi() >> Mock(Reader) {
|
1 * getIngressReader() >> Mock(Reader) {
|
||||||
1 * read(new JsonRpcRequest("eth_test", [])) >> Mono.just(JsonRpcResponse.ok("1"))
|
1 * read(new JsonRpcRequest("eth_test", [])) >> Mono.just(JsonRpcResponse.ok("1"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +72,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> api
|
_ * getIngressReader() >> api
|
||||||
}
|
}
|
||||||
def apis = new FilteredApis(
|
def apis = new FilteredApis(
|
||||||
Chain.ETHEREUM,
|
Chain.ETHEREUM,
|
||||||
@@ -110,7 +109,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> api
|
_ * getIngressReader() >> api
|
||||||
}
|
}
|
||||||
def apis = new FilteredApis(
|
def apis = new FilteredApis(
|
||||||
Chain.ETHEREUM,
|
Chain.ETHEREUM,
|
||||||
@@ -137,7 +136,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> Mock(Reader) {
|
_ * getIngressReader() >> Mock(Reader) {
|
||||||
2 * read(new JsonRpcRequest("eth_test", [])) >>> [
|
2 * read(new JsonRpcRequest("eth_test", [])) >>> [
|
||||||
Mono.just(JsonRpcResponse.ok("null")),
|
Mono.just(JsonRpcResponse.ok("null")),
|
||||||
Mono.just(JsonRpcResponse.ok("1"))
|
Mono.just(JsonRpcResponse.ok("1"))
|
||||||
@@ -169,7 +168,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> Mock(Reader) {
|
_ * getIngressReader() >> Mock(Reader) {
|
||||||
2 * read(new JsonRpcRequest("eth_test", [])) >>> [
|
2 * read(new JsonRpcRequest("eth_test", [])) >>> [
|
||||||
Mono.just(JsonRpcResponse.error(1, "test")),
|
Mono.just(JsonRpcResponse.error(1, "test")),
|
||||||
Mono.just(JsonRpcResponse.ok("1"))
|
Mono.just(JsonRpcResponse.ok("1"))
|
||||||
@@ -200,7 +199,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> Mock(Reader) {
|
_ * getIngressReader() >> Mock(Reader) {
|
||||||
3 * read(new JsonRpcRequest("eth_test", [])) >>> [
|
3 * read(new JsonRpcRequest("eth_test", [])) >>> [
|
||||||
Mono.just(JsonRpcResponse.ok("null")),
|
Mono.just(JsonRpcResponse.ok("null")),
|
||||||
Mono.just(JsonRpcResponse.error(1, "test")),
|
Mono.just(JsonRpcResponse.error(1, "test")),
|
||||||
@@ -239,7 +238,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> api
|
_ * getIngressReader() >> api
|
||||||
}
|
}
|
||||||
def apis = new FilteredApis(
|
def apis = new FilteredApis(
|
||||||
Chain.ETHEREUM,
|
Chain.ETHEREUM,
|
||||||
@@ -269,7 +268,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
def up = Mock(Upstream) {
|
def up = Mock(Upstream) {
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> api
|
_ * getIngressReader() >> api
|
||||||
}
|
}
|
||||||
def apis = new FilteredApis(
|
def apis = new FilteredApis(
|
||||||
Chain.ETHEREUM,
|
Chain.ETHEREUM,
|
||||||
@@ -298,7 +297,7 @@ class QuorumRpcReaderSpec extends Specification {
|
|||||||
_ * getLag() >> 0
|
_ * getLag() >> 0
|
||||||
_ * isAvailable() >> true
|
_ * isAvailable() >> true
|
||||||
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
_ * getRole() >> UpstreamsConfig.UpstreamRole.PRIMARY
|
||||||
_ * getApi() >> Mock(Reader) {
|
_ * getIngressReader() >> Mock(Reader) {
|
||||||
_ * read(new JsonRpcRequest("eth_test", [])) >>> [
|
_ * read(new JsonRpcRequest("eth_test", [])) >>> [
|
||||||
Mono.just(JsonRpcResponse.error(-3010, "test")),
|
Mono.just(JsonRpcResponse.error(-3010, "test")),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class NativeCallSpec extends Specification {
|
|||||||
1 * read(new JsonRpcRequest("eth_test", [])) >> Mono.just(new JsonRpcResponse("1".bytes, null))
|
1 * read(new JsonRpcRequest("eth_test", [])) >> Mono.just(new JsonRpcResponse("1".bytes, null))
|
||||||
}
|
}
|
||||||
def upstream = Mock(Multistream) {
|
def upstream = Mock(Multistream) {
|
||||||
1 * getRoutedApi(_) >> Mono.just(routedApi)
|
1 * getLocalReader(_) >> Mono.just(routedApi)
|
||||||
}
|
}
|
||||||
|
|
||||||
def nativeCall = nativeCall()
|
def nativeCall = nativeCall()
|
||||||
@@ -96,7 +96,7 @@ class NativeCallSpec extends Specification {
|
|||||||
1 * read(new JsonRpcRequest("eth_test", [])) >> Mono.error(new RpcException(RpcResponseError.CODE_METHOD_NOT_EXIST, "Test message"))
|
1 * read(new JsonRpcRequest("eth_test", [])) >> Mono.error(new RpcException(RpcResponseError.CODE_METHOD_NOT_EXIST, "Test message"))
|
||||||
}
|
}
|
||||||
def upstream = Mock(Multistream) {
|
def upstream = Mock(Multistream) {
|
||||||
1 * getRoutedApi(_) >> Mono.just(routedApi)
|
1 * getLocalReader(_) >> Mono.just(routedApi)
|
||||||
}
|
}
|
||||||
|
|
||||||
def nativeCall = nativeCall()
|
def nativeCall = nativeCall()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class EthereumConnectorMock implements EthereumConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Reader<JsonRpcRequest, JsonRpcResponse> getApi() {
|
Reader<JsonRpcRequest, JsonRpcResponse> getIngressReader() {
|
||||||
return this.api
|
return this.api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ class MultistreamSpec extends Specification {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
Mono<Reader<JsonRpcRequest, JsonRpcResponse>> getRoutedApi(boolean localEnabled) {
|
Mono<Reader<JsonRpcRequest, JsonRpcResponse>> getLocalReader(boolean localEnabled) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.emeraldpay.dshackle.upstream.ethereum
|
|||||||
|
|
||||||
import io.emeraldpay.dshackle.Global
|
import io.emeraldpay.dshackle.Global
|
||||||
import io.emeraldpay.dshackle.cache.Caches
|
import io.emeraldpay.dshackle.cache.Caches
|
||||||
import io.emeraldpay.dshackle.config.CacheConfig
|
|
||||||
import io.emeraldpay.dshackle.reader.EmptyReader
|
import io.emeraldpay.dshackle.reader.EmptyReader
|
||||||
import io.emeraldpay.dshackle.test.TestingCommons
|
import io.emeraldpay.dshackle.test.TestingCommons
|
||||||
import io.emeraldpay.dshackle.upstream.EmptyHead
|
import io.emeraldpay.dshackle.upstream.EmptyHead
|
||||||
@@ -18,12 +17,12 @@ import spock.lang.Specification
|
|||||||
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
|
||||||
class LocalCallRouterSpec extends Specification {
|
class EthereumLocalReaderSpec extends Specification {
|
||||||
|
|
||||||
def "Calls hardcoded"() {
|
def "Calls hardcoded"() {
|
||||||
setup:
|
setup:
|
||||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
def router = new LocalCallRouter(
|
def router = new EthereumLocalReader(
|
||||||
new EthereumCachingReader(
|
new EthereumCachingReader(
|
||||||
TestingCommons.multistream(TestingCommons.api()),
|
TestingCommons.multistream(TestingCommons.api()),
|
||||||
Caches.default(),
|
Caches.default(),
|
||||||
@@ -42,7 +41,7 @@ class LocalCallRouterSpec extends Specification {
|
|||||||
def "Returns empty if nonce set"() {
|
def "Returns empty if nonce set"() {
|
||||||
setup:
|
setup:
|
||||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
def router = new LocalCallRouter(
|
def router = new EthereumLocalReader(
|
||||||
new EthereumCachingReader(
|
new EthereumCachingReader(
|
||||||
TestingCommons.multistream(TestingCommons.api()),
|
TestingCommons.multistream(TestingCommons.api()),
|
||||||
Caches.default(),
|
Caches.default(),
|
||||||
@@ -72,7 +71,7 @@ class LocalCallRouterSpec extends Specification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
def router = new LocalCallRouter(reader, methods, head, true)
|
def router = new EthereumLocalReader(reader, methods, head, true)
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def act = router.getBlockByNumber(["latest", false])
|
def act = router.getBlockByNumber(["latest", false])
|
||||||
@@ -98,7 +97,7 @@ class LocalCallRouterSpec extends Specification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
def router = new LocalCallRouter(reader, methods, head, true)
|
def router = new EthereumLocalReader(reader, methods, head, true)
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def act = router.getBlockByNumber(["earliest", false])
|
def act = router.getBlockByNumber(["earliest", false])
|
||||||
@@ -124,7 +123,7 @@ class LocalCallRouterSpec extends Specification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
def router = new LocalCallRouter(reader, methods, head, true)
|
def router = new EthereumLocalReader(reader, methods, head, true)
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def act = router.getBlockByNumber(["0x123ef", false])
|
def act = router.getBlockByNumber(["0x123ef", false])
|
||||||
@@ -148,7 +147,7 @@ class LocalCallRouterSpec extends Specification {
|
|||||||
_ * blocksByHeightAsCont() >> new EmptyReader<>()
|
_ * blocksByHeightAsCont() >> new EmptyReader<>()
|
||||||
}
|
}
|
||||||
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
def methods = new DefaultEthereumMethods(Chain.ETHEREUM)
|
||||||
def router = new LocalCallRouter(reader, methods, head, true)
|
def router = new EthereumLocalReader(reader, methods, head, true)
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def act = router.getBlockByNumber(["0x0", true])
|
def act = router.getBlockByNumber(["0x0", true])
|
||||||
Reference in New Issue
Block a user