From ad64425cfaab83466fc600c20344885a6f2015b1 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Thu, 13 Jun 2024 15:57:00 +0100 Subject: [PATCH] fix --- go/enclave/storage/enclavedb/batch.go | 13 ++++++++++--- go/enclave/storage/storage.go | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/go/enclave/storage/enclavedb/batch.go b/go/enclave/storage/enclavedb/batch.go index 4c142b03ce..00f526f377 100644 --- a/go/enclave/storage/enclavedb/batch.go +++ b/go/enclave/storage/enclavedb/batch.go @@ -116,7 +116,7 @@ func MarkBatchExecuted(ctx context.Context, dbtx *sql.Tx, seqNo *big.Int) error return err } -func WriteExecutedTransaction(ctx context.Context, dbtx *sql.Tx, batchSeqNo uint64, txId uint64, createdContract *uint64, receipt []byte) (uint64, error) { +func WriteExecutedTransaction(ctx context.Context, dbtx *sql.Tx, batchSeqNo uint64, txId *uint64, createdContract *uint64, receipt []byte) (uint64, error) { insert := "insert into exec_tx (created_contract_address, receipt, tx, batch) values " + "(?,?,?,?)" res, err := dbtx.ExecContext(ctx, insert, createdContract, receipt, txId, batchSeqNo) if err != nil { @@ -129,10 +129,17 @@ func WriteExecutedTransaction(ctx context.Context, dbtx *sql.Tx, batchSeqNo uint return uint64(id), nil } -func GetTxId(ctx context.Context, dbtx *sql.Tx, txHash gethcommon.Hash) (uint64, error) { +func GetTxId(ctx context.Context, dbtx *sql.Tx, txHash gethcommon.Hash) (*uint64, error) { var txId uint64 err := dbtx.QueryRowContext(ctx, "select id from tx where hash=? ", txHash.Bytes()).Scan(&txId) - return txId, err + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + // make sure the error is converted to obscuro-wide not found error + return nil, errutil.ErrNotFound + } + return nil, err + } + return &txId, err } func ReadBatchHeaderBySeqNo(ctx context.Context, db *sql.DB, seqNo uint64) (*common.BatchHeader, error) { diff --git a/go/enclave/storage/storage.go b/go/enclave/storage/storage.go index 4abf046c02..2973da985b 100644 --- a/go/enclave/storage/storage.go +++ b/go/enclave/storage/storage.go @@ -695,7 +695,7 @@ func (s *storageImpl) storeReceiptAndEventLogs(ctx context.Context, dbTX *sql.Tx } txId, err := enclavedb.GetTxId(ctx, dbTX, receipt.TxHash) - if err != nil { + if err != nil && !errors.Is(err, errutil.ErrNotFound) { return fmt.Errorf("could not get transaction id. Cause: %w", err) }