Skip to content

Commit

Permalink
Correct and make updateSvpState easier to follow
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Nov 13, 2024
1 parent 272f561 commit 0c6aa68
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ private void logUpdateCollections(Transaction rskTx) {
private void updateSvpState(Transaction rskTx) {
Optional<Federation> proposedFederationOpt = federationSupport.getProposedFederation();
if (proposedFederationOpt.isEmpty()) {
logger.debug("[updateSvpState] Proposed federation does not exist, so there's no svp going on.");
logger.trace("[updateSvpState] Proposed federation does not exist, so there's no svp going on.");
return;
}

Expand All @@ -1034,11 +1034,19 @@ private void updateSvpState(Transaction rskTx) {
"[updateSvpState] Proposed federation validation failed at block {}. SVP failure will be processed",
rskExecutionBlock.getNumber()
);
processSVPFailure(proposedFederation);
processSvpFailure(proposedFederation);
return;
}

Keccak256 rskTxHash = rskTx.getHash();

if (shouldCreateAndProcessSvpFundTransaction()) {
logger.info(
"[updateSvpState] No svp values were found, so fund tx creation will be processed."
);
processSvpFundTransactionUnsigned(rskTxHash, proposedFederation);
}

// 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();
Expand All @@ -1047,20 +1055,22 @@ private void updateSvpState(Transaction rskTx) {
"[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
private boolean shouldCreateAndProcessSvpFundTransaction() {
// the fund tx will be created when the svp starts,
// so we must ensure all svp values are clear to proceed with its creation
Optional<Sha256Hash> svpFundTxHashUnsigned = provider.getSvpFundTxHashUnsigned();
if (svpFundTxHashUnsigned.isEmpty()) {
logger.info(
"[updateSvpState] Fund tx hash unsigned was not found, so fund tx creation will be processed."
);
processSvpFundTransactionUnsigned(rskTxHash, proposedFederation);
}
Optional<BtcTransaction> svpFundTxSigned = provider.getSvpFundTxSigned();
Optional<Sha256Hash> svpSpendTxHashUnsigned = provider.getSvpSpendTxHashUnsigned(); // spendTxHash will be removed the last, after spendTxWFS, so is enough checking just this value

return svpFundTxHashUnsigned.isEmpty()
&& svpFundTxSigned.isEmpty()
&& svpSpendTxHashUnsigned.isEmpty();
}

private void processSVPFailure(Federation proposedFederation) {
private void processSvpFailure(Federation proposedFederation) {
eventLogger.logCommitFederationFailure(rskExecutionBlock, proposedFederation);

logger.info("[processSVPFailure] Federation election will be allowed again.");
Expand Down

0 comments on commit 0c6aa68

Please sign in to comment.