-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create updateSvpState method #2838
Create updateSvpState method #2838
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
// 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()) { | ||
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."); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking on how we can change the order of these two logic blocks get executed. I think it would be easier to understand if the logic related to processing svpFundTxHashUnsigned
happens first than the svpFundTxSigned
. Maybe we can do something like this:
// Check if the unsigned fund transaction hash is not present, and create the fund transaction if needed
Optional<Sha256Hash> svpFundTxHashUnsigned = provider.getSvpFundTxHashUnsigned();
if (svpFundTxHashUnsigned.isEmpty()) {
try {
processSvpFundTransactionUnsigned(rskTxHash, proposedFederation);
} catch (Exception e) {
...
}
return;
}
// Check if the signed fund transaction is present, and create the spend transaction if available
Optional<BtcTransaction> svpFundTxSigned = provider.getSvpFundTxSigned();
if (svpFundTxSigned.isPresent()) {
processSvpSpendTransactionUnsigned(rskTxHash, proposedFederation, svpFundTxSigned.get());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember that when we save the svpFundTxSigned
we remove the svpFundTxHashUnsigned
. So this order won't have the expected behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
45b45d3
to
d9cf8e0
Compare
Quality Gate passedIssues Measures |
logger.error( | ||
"[processSvpFundTransactionUnsigned] IOException getting the pegouts waiting for confirmations. Error message: {}", | ||
e.getMessage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
// 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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also be checking that there is no spend tx created? Just in case.
I know there should only be one at a time so if both are found perhaps we have a problem
@@ -1017,13 +1017,51 @@ private void logUpdateCollections(Transaction rskTx) { | |||
eventLogger.logUpdateCollections(sender); | |||
} | |||
|
|||
protected void processSVPFailure(Federation proposedFederation) { | |||
protected void updateSvpState(Transaction rskTx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I'd find it easier to follow if the logic was written in chronological order. I know it requires more validations but we can probably make use of auxiliary methods. The way it's written now, for every new condition that appears in the code, you need to keep in mind the previous condition that was already validated a few lines above and the protocol logic about one having one SVP related value in storage at once.
I'd go with a very straight forward approach
if (!proposedFederationExists) return;
if (validationPeriodIsOngoing) {
if (shouldCreateSvpFundTx()) {
createFundTx()
return;
}
if (shouldCreateSvpSpendTx()) {
createSpendTx()
return;
}
validationFailed();
}
What do you think? I think that's the only 3 cases we need to cover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
provider.setSvpFundTxHashUnsigned(svpFundTransactionUnsigned.getHash()); | ||
PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations = provider.getPegoutsWaitingForConfirmations(); | ||
settleReleaseRequest(pegoutsWaitingForConfirmations, svpFundTransactionUnsigned, rskTx.getHash(), spendableValueFromProposedFederation); | ||
private void processSvpFundTransactionUnsigned(Keccak256 rskTxHash, Federation proposedFederation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this create
rather than process
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i named it process
to be consistent with processPegoutOrMigration
method. But no big deal, I can change it :)
38c0b3f
to
7a04c05
Compare
Minor refactors to avoid duplication code Rewrite comment Fix sonar complains Handle exception when processing fund transaction. Add logs for when updating svp state Add debug level log for when proposed fed does not exist Not allow validation period end block to be part of validation ongoing period Make updateSvpState private. Call it from updateCollections Add missing import Fix test
a84f8a7
to
272f561
Compare
6994f73
to
0c6aa68
Compare
0c6aa68
to
4083234
Compare
Quality Gate passedIssues Measures |
3858201
into
feature/powpeg_validation_protocol-phase4
Background
In order to keep going with the validation process, in every
updateCollections
we will call a new validation-related method,updateSvpState
, that will update the state of the svp process to see if the validation failed, or if conditions are met for creating the fund or the spend transaction.IN THIS PR
Create a new
updateSvpState
method that will:If a proposed federation does not exist, do nothing.
If a proposed federation exists and the validation period is ended, we can conclude that the validation failed.
If a proposed federation exists, the validation period is not ended and the
svpFundTxHashUnigned
entry is empty, we have to proceed with the fund transaction creation and processing.If a proposed federation exists, the validation period is not ended and the
svpFundTxSigned
has a value stored, we will proceed with the spend tx creation.