From 9eef2d9cb5116dfe9c85bc1c757d394e1c0f0487 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 27 Dec 2024 17:09:05 +0200 Subject: [PATCH] fixes --- go/enclave/rpc/GetTransaction.go | 4 ++-- go/enclave/rpc/GetTransactionReceipt.go | 13 ++++--------- go/enclave/storage/cache_service.go | 5 +++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/go/enclave/rpc/GetTransaction.go b/go/enclave/rpc/GetTransaction.go index fed8375b5..0e5631f42 100644 --- a/go/enclave/rpc/GetTransaction.go +++ b/go/enclave/rpc/GetTransaction.go @@ -50,7 +50,7 @@ func GetTransactionExecute(builder *CallBuilder[gethcommon.Hash, RpcTransaction] } if rec != nil { - rpc.logger.Info("Cache hit for tx", log.TxKey, txHash) + rpc.logger.Debug("Cache hit for tx", log.TxKey, txHash) // authorise - only the signer can request the transaction if rec.From.Hex() != requester.Hex() { builder.Status = NotAuthorised @@ -60,7 +60,7 @@ func GetTransactionExecute(builder *CallBuilder[gethcommon.Hash, RpcTransaction] return nil } - rpc.logger.Info("Cache miss for tx", log.TxKey, txHash) + rpc.logger.Debug("Cache miss for tx", log.TxKey, txHash) // Unlike in the Geth impl, we do not try and retrieve unconfirmed transactions from the mempool. tx, blockHash, blockNumber, index, err := rpc.storage.GetTransaction(builder.ctx, *builder.Param) diff --git a/go/enclave/rpc/GetTransactionReceipt.go b/go/enclave/rpc/GetTransactionReceipt.go index 7562537d2..049bf1180 100644 --- a/go/enclave/rpc/GetTransactionReceipt.go +++ b/go/enclave/rpc/GetTransactionReceipt.go @@ -60,12 +60,12 @@ func GetTransactionReceiptExecute(builder *CallBuilder[gethcommon.Hash, map[stri } if result != nil { - rpc.logger.Info("Cache hit for receipt", log.TxKey, txHash) + rpc.logger.Debug("Cache hit for receipt", log.TxKey, txHash) builder.ReturnValue = &result return nil } - rpc.logger.Info("Cache miss for receipt", log.TxKey, txHash.String()) + rpc.logger.Debug("Cache miss for receipt", log.TxKey, txHash.String()) exists, err := rpc.storage.ExistsTransactionReceipt(builder.ctx, txHash) if err != nil { return fmt.Errorf("could not retrieve transaction receipt in eth_getTransactionReceipt request. Cause: %w", err) @@ -79,7 +79,7 @@ func GetTransactionReceiptExecute(builder *CallBuilder[gethcommon.Hash, map[stri // We retrieve the transaction receipt. receipt, err := rpc.storage.GetFilteredInternalReceipt(builder.ctx, txHash, requester, false) if err != nil { - rpc.logger.Trace("error getting tx receipt", log.TxKey, txHash, log.ErrKey, err) + rpc.logger.Trace("Error getting tx receipt", log.TxKey, txHash, log.ErrKey, err) if errors.Is(err, errutil.ErrNotFound) { builder.Status = NotAuthorised return nil @@ -127,13 +127,8 @@ func fetchFromCache(ctx context.Context, storage storage.Storage, cacheService * } } } - r := marshalReceipt(rec.Receipt, logs, rec.From, rec.To) - // after the receipt was requested by a user remove it from the cache - //err = cacheService.DelReceipt(ctx, txHash) - //if err != nil { - // return nil, err - //} + r := marshalReceipt(rec.Receipt, logs, rec.From, rec.To) return r, nil } diff --git a/go/enclave/storage/cache_service.go b/go/enclave/storage/cache_service.go index f6fda973c..0d86a77f5 100644 --- a/go/enclave/storage/cache_service.go +++ b/go/enclave/storage/cache_service.go @@ -87,6 +87,7 @@ func NewCacheService(logger gethlog.Logger, testMode bool) *CacheService { nrEnclaves := 20 nrReceipts := 15_000 // ~100M + receiptsTimeout := 4 * time.Minute if testMode { nrReceipts = 2500 } @@ -106,7 +107,7 @@ func NewCacheService(logger gethlog.Logger, testMode bool) *CacheService { eventTypeCache: newLFUCache[[]byte, *enclavedb.EventType](logger, nrEventTypes), eventTopicCache: newLFUCache[[]byte, *enclavedb.EventTopic](logger, nrEventTypes), - receiptCache: newFifoCache(nrReceipts, 180*time.Second), + receiptCache: newFifoCache(nrReceipts, receiptsTimeout), attestedEnclavesCache: newLFUCache[[]byte, *AttestedEnclave](logger, nrEnclaves), // cache the latest received batches to avoid a lookup when streaming it back to the host after processing @@ -235,7 +236,7 @@ func (cs *CacheService) CacheReceipts(results core.TxExecResults) { From: txExecResult.TxWithSender.Sender, To: txExecResult.TxWithSender.Tx.To(), } - cs.logger.Info("Cache receipt", "tx", txExecResult.TxWithSender.Tx.Hash().String()) + cs.logger.Debug("Cache receipt", "tx", txExecResult.TxWithSender.Tx.Hash().String()) } cs.receiptCache.SetAll(receipts) }