From 0b791a2c8e05a576ee9cf7c23e4474236464f33a Mon Sep 17 00:00:00 2001 From: arkadiuszos4chain Date: Tue, 17 Oct 2023 13:15:12 +0200 Subject: [PATCH] tests: try to sync tx again if return txInfo has no markle proof --- model_sync_transactions.go | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/model_sync_transactions.go b/model_sync_transactions.go index 68405eb3..b0fc0117 100644 --- a/model_sync_transactions.go +++ b/model_sync_transactions.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "encoding/hex" + "encoding/json" "errors" "fmt" "runtime" @@ -640,6 +641,19 @@ func processSyncTransaction(ctx context.Context, syncTx *SyncTransaction, transa return err } + // Get the transaction + if transaction == nil { + if transaction, err = getTransactionByID( + ctx, "", syncTx.ID, syncTx.GetOptions(false)..., + ); err != nil { + return err + } + } + + if transaction == nil { + return ErrMissingTransaction + } + // Find on-chain var txInfo *chainstate.TransactionInfo // only mAPI currently provides merkle proof, so QueryTransaction should be used here @@ -647,6 +661,8 @@ func processSyncTransaction(ctx context.Context, syncTx *SyncTransaction, transa ctx, syncTx.ID, chainstate.RequiredOnChain, defaultQueryTxTimeout, ); err != nil { if errors.Is(err, chainstate.ErrTransactionNotFound) { + syncTx.client.Logger().Info(ctx, fmt.Sprintf("processSyncTransaction(): Transaction %s not found on-chain, will try again later", syncTx.ID)) + bailAndSaveSyncTransaction( ctx, syncTx, SyncStatusReady, syncActionSync, "all", "transaction not found on-chain", ) @@ -655,17 +671,15 @@ func processSyncTransaction(ctx context.Context, syncTx *SyncTransaction, transa return err } - // Get the transaction - if transaction == nil { - if transaction, err = getTransactionByID( - ctx, "", syncTx.ID, syncTx.GetOptions(false)..., - ); err != nil { - return err - } - } + // validate txInfo + if txInfo.BlockHash == "" || txInfo.MerkleProof == nil || txInfo.MerkleProof.TxOrID == "" || len(txInfo.MerkleProof.Nodes) == 0 { + syncTx.client.Logger().Warn(ctx, fmt.Sprintf("processSyncTransaction(): txInfo for %s is invalid, will try again later", syncTx.ID)) - if transaction == nil { - return ErrMissingTransaction + if syncTx.client.IsDebug() { + txInfoJSON, _ := json.Marshal(txInfo) //nolint:nolintlint,nilerr // error is not needed + syncTx.DebugLog(string(txInfoJSON)) + } + return nil } // Add additional information (if found on-chain) @@ -700,6 +714,8 @@ func processSyncTransaction(ctx context.Context, syncTx *SyncTransaction, transa return err } + syncTx.client.Logger().Trace(ctx, fmt.Sprintf("processSyncTransaction(): Transaction %s processed successfully", syncTx.ID)) + // Done! return nil }