From 801d5600e8b5af2845362400242c411e35c238fd Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Mon, 4 Dec 2023 12:32:33 +0000 Subject: [PATCH] - use the cached head block (#1678) - add canonical condition to sql to hit the index (cherry picked from commit fb50c7bada8ebb2220002274ce9f9bb079eaf332) --- go/enclave/enclave.go | 4 ++-- go/enclave/storage/enclavedb/batch.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/enclave/enclave.go b/go/enclave/enclave.go index 18b4885431..092f80f24f 100644 --- a/go/enclave/enclave.go +++ b/go/enclave/enclave.go @@ -322,7 +322,7 @@ func (e *enclaveImpl) Status() (common.Status, common.SystemError) { return common.Status{StatusCode: common.Unavailable}, responses.ToInternalError(err) } var l1HeadHash gethcommon.Hash - l1Head, err := e.storage.FetchHeadBlock() + l1Head, err := e.l1BlockProcessor.GetHead() if err != nil { // this might be normal while enclave is starting up, just send empty hash e.logger.Debug("failed to fetch L1 head block for status response", log.ErrKey, err) @@ -1470,7 +1470,7 @@ func extractGetLogsParams(paramList []interface{}) (*filters.FilterCriteria, *ge func (e *enclaveImpl) rejectBlockErr(cause error) *errutil.BlockRejectError { var hash common.L1BlockHash - l1Head, err := e.storage.FetchHeadBlock() + l1Head, err := e.l1BlockProcessor.GetHead() // todo - handle error if err == nil { hash = l1Head.Hash() diff --git a/go/enclave/storage/enclavedb/batch.go b/go/enclave/storage/enclavedb/batch.go index 39e10337b8..33c0ed7cc2 100644 --- a/go/enclave/storage/enclavedb/batch.go +++ b/go/enclave/storage/enclavedb/batch.go @@ -44,8 +44,8 @@ const ( isCanonQuery = "select is_canonical from block where hash=?" - queryTxList = "select tx.full_hash, batch.height from exec_tx join batch on batch.sequence=exec_tx.batch join tx on tx.hash=exec_tx.tx" - queryTxCountList = "select count(1) from exec_tx join batch on batch.sequence=exec_tx.batch" + queryTxList = "select tx.full_hash, batch.height from exec_tx join batch on batch.sequence=exec_tx.batch join tx on tx.hash=exec_tx.tx where batch.is_canonical=true" + queryTxCountList = "select count(1) from exec_tx join batch on batch.sequence=exec_tx.batch where batch.is_canonical=true" ) // WriteBatchAndTransactions - persists the batch and the transactions