Skip to content

Commit

Permalink
Merge pull request #73 from covalenthq/retry_fox
Browse files Browse the repository at this point in the history
avoid exit when proofchain submission fails after retries
  • Loading branch information
sudeepdino008 authored Apr 28, 2022
2 parents 37b3338 + eb7c7d6 commit b7b1e45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
2 changes: 2 additions & 0 deletions internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func EncodeProveAndUploadReplicaSegment(ctx context.Context, config *config.EthC
return pTxHash, nil
case strings.Contains(pTxHash, "mine timeout"):
return pTxHash, nil
case strings.Contains(pTxHash, "retry fail"):
return pTxHash, nil
case pTxHash == "":
return "", fmt.Errorf("failed to prove & upload block-replica segment event: %v", segmentName)
default:
Expand Down
32 changes: 12 additions & 20 deletions internal/proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
)

const (
proofTxTimeout uint64 = 301
proofTxTimeout uint64 = 301
retryCountLimit int = 1 // 1 retry for proofchain submission
)

// SendBlockReplicaProofTx calls the proof-chain contract to make a transaction for the block-replica that it is processing
Expand Down Expand Up @@ -53,6 +54,10 @@ func SendBlockReplicaProofTx(ctx context.Context, config *config.EthConfig, proo
}
sha256Result := sha256.Sum256(jsonResult)

executeWithRetry(ctx, proofChainContract, ethClient, opts, blockReplica, txHash, chainHeight, replicaURL, sha256Result, 0)
}

func executeWithRetry(ctx context.Context, proofChainContract *ProofChain, ethClient *ethclient.Client, opts *bind.TransactOpts, blockReplica *ty.BlockReplica, txHash chan string, chainHeight uint64, replicaURL string, sha256Result [sha256.Size]byte, retryCount int) {
transaction, err := proofChainContract.SubmitBlockSpecimenProof(opts, blockReplica.NetworkId, chainHeight, blockReplica.Hash, sha256Result, replicaURL)

if err != nil {
Expand All @@ -75,35 +80,22 @@ func SendBlockReplicaProofTx(ctx context.Context, config *config.EthConfig, proo
}

receipt, err := bind.WaitMined(ctx, ethClient, transaction)

if err != nil {
log.Error("proof tx wait on mine timeout in seconds: ", proofTxTimeout, " with err: ", err.Error())
txHash <- "mine timeout"

return
}
if receipt.Status != types.ReceiptStatusSuccessful {
log.Error("proof tx failed/revereted, retrying proof tx for block hash: ", blockReplica.Hash)
retryTx, retryTxErr := proofChainContract.SubmitBlockSpecimenProof(opts, blockReplica.NetworkId, chainHeight, blockReplica.Hash, sha256Result, replicaURL)
if retryTxErr != nil {
log.Error("error retrying tx to deployed contract: ", retryTxErr)
txHash <- ""
if retryCount >= retryCountLimit {
log.Error("proof tx failed/reverted on tx retry, skipping: ", transaction.Hash())
txHash <- "retry fail"

return
}
retryReceipt, retryReceiptErr := bind.WaitMined(ctx, ethClient, retryTx)
if retryReceiptErr != nil {
log.Error("proof tx wait on mine timeout in seconds: ", proofTxTimeout, " with err: ", retryReceiptErr.Error())
txHash <- "mine timeout"

return
}
if retryReceipt.Status != types.ReceiptStatusSuccessful {
log.Error("proof tx failed/revereted on tx retry, skipping: ", retryTx.Hash())

txHash <- retryTx.Hash().String()
}

txHash <- retryTx.Hash().String()
log.Error("proof tx failed/reverted, retrying proof tx for block hash: ", blockReplica.Hash.String())
executeWithRetry(ctx, proofChainContract, ethClient, opts, blockReplica, txHash, chainHeight, replicaURL, sha256Result, retryCount+1)

return
}
Expand Down

0 comments on commit b7b1e45

Please sign in to comment.