From 397ddd7865ba5ea9437adcdf89c72db190f099c5 Mon Sep 17 00:00:00 2001 From: KirillPamPam Date: Fri, 17 Mar 2023 15:05:18 +0400 Subject: [PATCH] Fix issues with caches - Fix read block - Fix read not enrich blocks, refactoring read tx receipts --- emerald-grpc | 2 +- .../io/emeraldpay/dshackle/cache/BlocksMemCache.kt | 7 ++++--- .../upstream/ethereum/EthereumDirectReader.kt | 14 ++++++-------- .../dshackle/upstream/ethereum/WsConnectionImpl.kt | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/emerald-grpc b/emerald-grpc index 37a356fd..1c9a9554 160000 --- a/emerald-grpc +++ b/emerald-grpc @@ -1 +1 @@ -Subproject commit 37a356fdee02abbca383e83d3bb40177eba31922 +Subproject commit 1c9a9554e63031ee23217f0e54fc3d8c185fe19f diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt index b6ce3f5a..5d3671a8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt @@ -35,12 +35,13 @@ open class BlocksMemCache( } open fun get(key: BlockId): BlockContainer? { - return mapping.getIfPresent(key)?.let { - return@let if (it.enriched) it else null - } + return mapping.getIfPresent(key) } open fun add(block: BlockContainer) { + if (!block.enriched) { + return + } mapping.put(block.hash, block) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt index bc8c10a8..29b819ff 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt @@ -121,10 +121,11 @@ class EthereumDirectReader( return readWithQuorum(request) .timeout(Defaults.timeoutInternal, Mono.error(TimeoutException("Receipt not read $key"))) .flatMap { json -> - try { - // Caching needs some additional data (ex. Height) to make a decision on how long and where to cache - // So we have to parse the JSON here and extract reference data - val receipt = objectMapper.readValue(json, TransactionReceiptJson::class.java) + val receipt = objectMapper.readValue(json, TransactionReceiptJson::class.java) + if (receipt == null) { + log.debug("Empty receipt for txId $key") + Mono.empty() + } else { caches.cacheReceipt( Caches.Tag.REQUESTED, DefaultContainer( @@ -135,11 +136,8 @@ class EthereumDirectReader( parsed = receipt ) ) - } catch (t: Throwable) { - log.warn("Failed to cache Tx Receipt", t) - return@flatMap Mono.empty() + Mono.just(json) } - Mono.just(json) } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt index 9f623960..103cb4ac 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt @@ -286,7 +286,7 @@ open class WsConnectionImpl( ) val sender = currentRequests.remove(msg.id.asNumber().toInt()) if (sender == null) { - log.warn("Unknown response received for ${msg.id} with body ${msg.value?.let { String(it) }}") + log.warn("Unknown response received for ${msg.id}") } else { try { val emitResult = sender.tryEmitValue(rpcResponse)