-
Notifications
You must be signed in to change notification settings - Fork 267
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
Mark invalid pegin as processed #2910
Changes from 3 commits
aca9920
208b14f
b2a1d48
61bd76f
bf15222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -503,33 +503,50 @@ protected void registerPegIn( | |
); | ||
|
||
PeginProcessAction peginProcessAction = peginEvaluationResult.getPeginProcessAction(); | ||
|
||
if (peginProcessAction == PeginProcessAction.CAN_BE_REGISTERED) { | ||
logger.debug("[{}] Peg-in is valid, going to register", METHOD_NAME); | ||
executePegIn(btcTx, peginInformation, totalAmount); | ||
} else { | ||
Optional<RejectedPeginReason> rejectedPeginReasonOptional = peginEvaluationResult.getRejectedPeginReason(); | ||
if (rejectedPeginReasonOptional.isEmpty()) { | ||
return; | ||
} | ||
|
||
// If the peg-in cannot be registered means it should be rejected | ||
RejectedPeginReason rejectedPeginReason = peginEvaluationResult.getRejectedPeginReason() | ||
.map(reason -> { | ||
logger.debug("[{}] Rejected peg-in, reason {}", METHOD_NAME, reason); | ||
eventLogger.logRejectedPegin(btcTx, reason); | ||
return reason; | ||
}).orElseThrow(() -> { | ||
// This flow should never be reached. There should always be a rejected pegin reason. | ||
String message = "Invalid state. No rejected reason was returned from evaluatePegin method"; | ||
logger.error("[{}}] {}", METHOD_NAME, message); | ||
throw new IllegalStateException(message); | ||
String message = "Invalid state. No rejected reason was returned for an invalid pegin."; | ||
logger.error("[{}] {}", METHOD_NAME, message); | ||
return new IllegalStateException(message); | ||
}); | ||
|
||
switch (peginProcessAction) { | ||
case CAN_BE_REFUNDED -> { | ||
logger.debug("[{}] Refunding to address {} ", METHOD_NAME, | ||
peginInformation.getBtcRefundAddress()); | ||
generateRejectionRelease(btcTx, peginInformation.getBtcRefundAddress(), rskTxHash, | ||
totalAmount); | ||
markTxAsProcessed(btcTx); | ||
} | ||
case CANNOT_BE_REFUNDED -> { | ||
logger.debug("[{}] Nonrefundable transaction {}.", METHOD_NAME, btcTx.getHash()); | ||
handleNonRefundablePegin(btcTx, peginInformation.getProtocolVersion(), | ||
rejectedPeginReason); | ||
|
||
if (!activations.isActive(RSKIP459)) { | ||
return; | ||
} | ||
|
||
RejectedPeginReason rejectedPeginReason = rejectedPeginReasonOptional.get(); | ||
logger.debug("[{}] Rejected peg-in, reason {}", METHOD_NAME, rejectedPeginReason); | ||
eventLogger.logRejectedPegin(btcTx, rejectedPeginReason); | ||
if (peginProcessAction == PeginProcessAction.CAN_BE_REFUNDED) { | ||
logger.debug("[{}] Refunding to address {} ", METHOD_NAME, peginInformation.getBtcRefundAddress()); | ||
generateRejectionRelease(btcTx, peginInformation.getBtcRefundAddress(), rskTxHash, totalAmount); | ||
// Since RSKIP459, rejected peg-ins should be marked as processed | ||
markTxAsProcessed(btcTx); | ||
} else { | ||
logger.debug("[{}] Unprocessable transaction {}.", METHOD_NAME, btcTx.getHash()); | ||
handleUnprocessableBtcTx(btcTx, peginInformation.getProtocolVersion(), rejectedPeginReason); | ||
} | ||
} | ||
} | ||
|
||
private void handleUnprocessableBtcTx( | ||
private void handleNonRefundablePegin( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the same renaming idea could apply here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
BtcTransaction btcTx, | ||
int protocolVersion, | ||
RejectedPeginReason rejectedPeginReason | ||
|
@@ -543,7 +560,8 @@ private void handleUnprocessableBtcTx( | |
UnrefundablePeginReason.LEGACY_PEGIN_UNDETERMINED_SENDER; | ||
} | ||
|
||
logger.debug("[handleUnprocessableBtcTx] Unprocessable tx {}. Reason {}", btcTx.getHash(), unrefundablePeginReason); | ||
logger.debug("[handleNonRefundablePegin] Nonrefundable tx {}. Reason {}", btcTx.getHash(), | ||
unrefundablePeginReason); | ||
eventLogger.logUnrefundablePegin(btcTx, unrefundablePeginReason); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
public enum PeginProcessAction { | ||
CAN_BE_REGISTERED, | ||
CAN_BE_REFUNDED, | ||
CANNOT_BE_PROCESSED | ||
CANNOT_BE_REFUNDED | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an idea, to rename this for clarity
What do you think? A bit more straightforward. Last one could also be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks simpler. I'll update it. |
||
} |
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 we can use here the new switch expression with arrow labels
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