Skip to content

Commit

Permalink
Handle exception when processing fund transaction. Add logs for when …
Browse files Browse the repository at this point in the history
…updating svp state
  • Loading branch information
julia-zack committed Nov 4, 2024
1 parent d0ef7bd commit 45b45d3
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1023,41 +1023,44 @@ protected void updateSvpState(Transaction rskTx) {
return;
}

Keccak256 rskTxHash = rskTx.getHash();
// if the proposed federation exists and the validation period ended,
// we can conclude that the svp failed
Federation proposedFederation = proposedFederationOpt.get();
if (!validationPeriodIsOngoing(proposedFederation)) {
logger.debug(
"[updateSvpState] Proposed federation validation failed at block {}. SVP failure will be processed",
rskExecutionBlock.getNumber()
);
processSVPFailure(proposedFederation);
return;
}

Keccak256 rskTxHash = rskTx.getHash();
// if the fund tx signed is present, then the fund transaction change was registered,
// meaning we can create the spend tx.
Optional<BtcTransaction> svpFundTxSigned = provider.getSvpFundTxSigned();
if (svpFundTxSigned.isPresent()) {
logger.debug(
"[updateSvpState] Fund tx signed was found, so spend tx creation will be processed."
);
processSvpSpendTransactionUnsigned(rskTxHash, proposedFederation, svpFundTxSigned.get());
return;
}

// if the unsigned fund tx hash is not present, meaning we can proceed with the fund tx creation
Optional<Sha256Hash> svpFundTxHashUnsigned = provider.getSvpFundTxHashUnsigned();
if (svpFundTxHashUnsigned.isEmpty()) {
try {
processSvpFundTransactionUnsigned(rskTxHash, proposedFederation);
} catch (Exception e) {
logger.error("[updateSvpState] Error processing svp fund transaction unsigned. Error message: {}", e.getMessage());
}
logger.debug(
"[updateSvpState] Fund tx hash unsigned was not found, so fund tx creation will be processed."
);
processSvpFundTransactionUnsigned(rskTxHash, proposedFederation);
}
}

private void processSVPFailure(Federation proposedFederation) {
eventLogger.logCommitFederationFailure(rskExecutionBlock, proposedFederation);
logger.warn(
"[processSVPFailure] Proposed federation validation failed at block {}, so federation election will be allowed again.",
rskExecutionBlock.getNumber()
);

logger.debug("[processSVPFailure] Federation election will be allowed again.");
allowFederationElectionAgain();
}

Expand All @@ -1079,13 +1082,24 @@ private boolean validationPeriodIsOngoing(Federation proposedFederation) {
return rskExecutionBlock.getNumber() <= validationPeriodEndBlock;
}

private void processSvpFundTransactionUnsigned(Keccak256 rskTxHash, Federation proposedFederation) throws IOException, InsufficientMoneyException {
private void processSvpFundTransactionUnsigned(Keccak256 rskTxHash, Federation proposedFederation) {
Coin spendableValueFromProposedFederation = bridgeConstants.getSpendableValueFromProposedFederation();
BtcTransaction svpFundTransactionUnsigned = createSvpFundTransaction(proposedFederation, spendableValueFromProposedFederation);

provider.setSvpFundTxHashUnsigned(svpFundTransactionUnsigned.getHash());
PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations = provider.getPegoutsWaitingForConfirmations();
settleReleaseRequest(pegoutsWaitingForConfirmations, svpFundTransactionUnsigned, rskTxHash, spendableValueFromProposedFederation);
try {
BtcTransaction svpFundTransactionUnsigned = createSvpFundTransaction(proposedFederation, spendableValueFromProposedFederation);
provider.setSvpFundTxHashUnsigned(svpFundTransactionUnsigned.getHash());
PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations = provider.getPegoutsWaitingForConfirmations();
settleReleaseRequest(pegoutsWaitingForConfirmations, svpFundTransactionUnsigned, rskTxHash, spendableValueFromProposedFederation);
} catch (InsufficientMoneyException e) {
logger.error(
"[processSvpFundTransactionUnsigned] Insufficient funds for creating the fund transaction. Error message: {}",
e.getMessage()
);
} catch (IOException e) {
logger.error(
"[processSvpFundTransactionUnsigned] IOException getting the pegouts waiting for confirmations. Error message: {}",
e.getMessage()
);
}
}

private BtcTransaction createSvpFundTransaction(Federation proposedFederation, Coin spendableValueFromProposedFederation) throws InsufficientMoneyException {
Expand Down

0 comments on commit 45b45d3

Please sign in to comment.