Skip to content

Commit

Permalink
Handle state sync execution failures properly (#1676)
Browse files Browse the repository at this point in the history
* Handle state sync execution failures properly

* Fix cluster script

* If state sync result is not matched, continue the loop
  • Loading branch information
Stefan-Ethernal committed Jun 30, 2023
1 parent dcc6950 commit beeb461
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions consensus/polybft/statesyncrelayer/state_sync_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (r *StateSyncRelayer) AddLog(log *ethgo.Log) {
}

if err := r.executeStateSync(stateSyncProof); err != nil {
r.logger.Error("Failed to execute state sync", "err", err)
r.logger.Error("State sync execution failed", "err", err)

continue
}
Expand Down Expand Up @@ -204,11 +204,27 @@ func (r *StateSyncRelayer) executeStateSync(proof *types.Proof) error {

receipt, err := r.txRelayer.SendTransaction(txn, r.key)
if err != nil {
return fmt.Errorf("failed to send state sync transaction: %w", err)
return fmt.Errorf("failed to send execute state sync transaction for id %d: %w", sse.ID, err)
}

if receipt.Status == uint64(types.ReceiptFailed) {
return fmt.Errorf("state sync execution failed: %d", execute.Obj.ID)
return fmt.Errorf("transaction execution reverted for state sync id: %d", sse.ID)
}

var stateSyncResult contractsapi.StateSyncResultEvent
for _, log := range receipt.Logs {
matches, err := stateSyncResult.ParseLog(log)
if err != nil {
return fmt.Errorf("failed to find state sync event result log for state sync id: %d", sse.ID)
}

if !matches {
continue
}

if !stateSyncResult.Status {
return fmt.Errorf("failed to execute state sync id: %d", sse.ID)
}
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions scripts/cluster
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ if [[ "$1" == "polybft" ]] && ! command -v nc >/dev/null 2>&1; then
fi

# Stop script if any of the dependencies have failed
if [[ "$dp_error_flag" -eq 1]]; then
if [[ "$dp_error_flag" -eq 1 ]]; then
echo "Missing dependencies. Please install them and run the script again."
exit 1
fi
fi

function initIbftConsensus() {
echo "Running with ibft consensus"
Expand Down

0 comments on commit beeb461

Please sign in to comment.