Fix issues with caches

- Fix read block
- Fix read not enrich blocks, refactoring read tx receipts
This commit is contained in:
KirillPamPam
2023-03-17 15:05:18 +04:00
committed by GitHub
parent 1bca196387
commit 397ddd7865
4 changed files with 12 additions and 13 deletions

View File

@@ -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)
}

View File

@@ -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)
}
}
}

View File

@@ -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)