-
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
Refactor addSignature as previous step to create addSvpSpendTxSignature method #2788
Refactor addSignature as previous step to create addSvpSpendTxSignature method #2788
Conversation
private void logMissingSignatures(BtcTransaction btcTx, Keccak256 rskTxHash, int neededSignatures, int federationSize) { | ||
int missingSignatures = BridgeUtils.countMissingSignatures(btcContext, btcTx); | ||
int signaturesCount = neededSignatures - missingSignatures; | ||
|
||
logger.debug("Tx {} not yet fully signed. Requires {}/{} signatures but has {}", | ||
rskTxHash, neededSignatures, federationSize, signaturesCount); | ||
} |
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.
this might seem unnecessary, but it would be needed when adding new method
private void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHashSerialized) { | ||
logger.info("Tx fully signed {}. Hex: {}", btcTx, Bytes.of(btcTx.bitcoinSerialize())); | ||
eventLogger.logReleaseBtc(btcTx, rskTxHashSerialized); | ||
} |
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.
this might seem unnecessary, but it would be needed when adding new method
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.
Very nice refactor, left comments :)
rskj-core/src/test/java/co/rsk/peg/BridgeSupportAddSignatureTest.java
Outdated
Show resolved
Hide resolved
rskj-core/src/test/java/co/rsk/peg/BridgeSupportAddSignatureTest.java
Outdated
Show resolved
Hide resolved
5713282
to
68da5aa
Compare
5c281f6
to
40882bd
Compare
68da5aa
to
1a6e1ea
Compare
40882bd
to
ae68f5e
Compare
@@ -90,9 +90,23 @@ public static Script createBaseP2SHInputScriptThatSpendsFromRedeemScript(Script | |||
return outputScript.createEmptyInputScript(null, redeemScript); | |||
} | |||
|
|||
public static Script getRedeemScriptFromP2SHInputScript(Script inputScript) { |
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.
tests?
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
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.
Looking a bit more into this, we already have a method here extractRedeemScriptFromInput
. Why not use that one passing the input directly? Instead of extracting the input script and then calling this
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.
could be, i find it weird that that method returns an optional. I think it should return the script or an exception, wdyt?
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 think the Optional gives a bit more flexibility, it get the redeem script if there is one. Then you can do all kinds of functional stuff with the optional return.
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
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 (rskTxHash.length!=32) { | ||
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHash)); | ||
byte[] rskTxHashSerialized = (byte[]) args[2]; | ||
if (rskTxHashSerialized.length!=32) { |
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.
if (rskTxHashSerialized.length!=32) { | |
if (rskTxHashSerialized.length != 32) { |
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.
Or,
if (rskTxHashSerialized.length!=32) { | |
if (rskTxHashSerialized.length != Keccak256.HASH_LEN) { |
Or,
if (rskTxHashSerialized.length!=32) { | |
Keccack256 rskTxHash = BridgeUtils.deserializeKeccack256(rskTxHashSerialized); |
That would imply writing deserializeKeccack256
function, which should check for length and throw an exception if not valid. And add tests for that function 😁
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.
updateddddd
if (rskTxHash.length!=32) { | ||
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHash)); | ||
byte[] rskTxHashSerialized = (byte[]) args[2]; | ||
if (rskTxHashSerialized.length!=32) { |
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.
Or,
if (rskTxHashSerialized.length!=32) { | |
if (rskTxHashSerialized.length != Keccak256.HASH_LEN) { |
Or,
if (rskTxHashSerialized.length!=32) { | |
Keccack256 rskTxHash = BridgeUtils.deserializeKeccack256(rskTxHashSerialized); |
That would imply writing deserializeKeccack256
function, which should check for length and throw an exception if not valid. And add tests for that function 😁
try { | ||
txSigs = getTransactionSignatures(federatorBtcPublicKey, sigHashes, signatures); | ||
} catch (SignatureException e) { | ||
logger.error("[processSigning] Unable to proceed with signing as the transaction signatures are incorrect."); |
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.
logger.error("[processSigning] Unable to proceed with signing as the transaction signatures are incorrect."); | |
logger.error("[processSigning] Unable to proceed with signing as the transaction signatures are incorrect. {}", 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.
updated
@@ -90,9 +90,23 @@ public static Script createBaseP2SHInputScriptThatSpendsFromRedeemScript(Script | |||
return outputScript.createEmptyInputScript(null, redeemScript); | |||
} | |||
|
|||
public static Script getRedeemScriptFromP2SHInputScript(Script inputScript) { |
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.
Looking a bit more into this, we already have a method here extractRedeemScriptFromInput
. Why not use that one passing the input directly? Instead of extracting the input script and then calling this
…doc. Replace times(0) for never().
…ility to be more accurate. Change btcTx name for releaseTx name. Return false when catching exception when signing
…eccak rskTxHash. Remove logger.isDebugEnabled condition.
c130496
to
e7a67b1
Compare
…cated exception in addSignature to better handling. Make deserializeRskTxHash method public to reuse it. Add tests.
} catch (Exception e) { | ||
} catch (IllegalArgumentException e) { | ||
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHashSerialized)); | ||
} catch (IOException e) { |
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.
Is this change a good idea? I think all Bridge methods are capturing generic exceptions
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.
There might be unchecked exception thrown
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
@@ -2025,4 +2026,27 @@ void testGetUTXOsSentToAddresses_no_utxo_sent_to_given_address_after_RSKIP293() | |||
|
|||
Assertions.assertTrue(foundUTXOs.isEmpty()); | |||
} | |||
|
|||
@Test |
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 these tests go in BridgeSerializationUtilsTest?
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.
yes, my bad. Thanks
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
} | ||
|
||
@Test | ||
void deserializeRskTxHash_withInvalidLength_throwsIllegalArgumentException() { |
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.
A test passing a null value?
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.
good catch, thanks
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
…right file. Catch generic exceptions in Bridge method
Quality Gate passedIssues Measures |
1060083
into
feature/powpeg_validation_protocol-phase3
No description provided.