Skip to content
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

Merged

Conversation

julia-zack
Copy link
Contributor

No description provided.

@julia-zack julia-zack marked this pull request as ready for review October 3, 2024 18:14
@julia-zack julia-zack requested a review from a team as a code owner October 3, 2024 18:14
Comment on lines 1710 to 1667
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);
}
Copy link
Contributor Author

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

Comment on lines +1718 to +1672
private void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHashSerialized) {
logger.info("Tx fully signed {}. Hex: {}", btcTx, Bytes.of(btcTx.bitcoinSerialize()));
eventLogger.logReleaseBtc(btcTx, rskTxHashSerialized);
}
Copy link
Contributor Author

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

Copy link
Contributor

@apancorb apancorb left a 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/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
@marcos-iov marcos-iov force-pushed the feature/powpeg_validation_protocol-phase3 branch from 5713282 to 68da5aa Compare October 8, 2024 16:22
@marcos-iov marcos-iov force-pushed the refactor_add_signature branch from 5c281f6 to 40882bd Compare October 8, 2024 16:36
@marcos-iov marcos-iov force-pushed the feature/powpeg_validation_protocol-phase3 branch from 68da5aa to 1a6e1ea Compare October 8, 2024 18:34
@marcos-iov marcos-iov force-pushed the refactor_add_signature branch from 40882bd to ae68f5e Compare October 8, 2024 18:37
rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java Outdated Show resolved Hide resolved
@@ -90,9 +90,23 @@ public static Script createBaseP2SHInputScriptThatSpendsFromRedeemScript(Script
return outputScript.createEmptyInputScript(null, redeemScript);
}

public static Script getRedeemScriptFromP2SHInputScript(Script inputScript) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

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

Copy link
Contributor Author

@julia-zack julia-zack Oct 10, 2024

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

@apancorb apancorb left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (rskTxHashSerialized.length!=32) {
if (rskTxHashSerialized.length != 32) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or,

Suggested change
if (rskTxHashSerialized.length!=32) {
if (rskTxHashSerialized.length != Keccak256.HASH_LEN) {

Or,

Suggested change
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 😁

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or,

Suggested change
if (rskTxHashSerialized.length!=32) {
if (rskTxHashSerialized.length != Keccak256.HASH_LEN) {

Or,

Suggested change
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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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());

Copy link
Contributor Author

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) {
Copy link
Contributor

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

@julia-zack julia-zack force-pushed the refactor_add_signature branch from c130496 to e7a67b1 Compare October 10, 2024 20:11
…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) {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, my bad. Thanks

Copy link
Contributor Author

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() {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks

Copy link
Contributor Author

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
Copy link

@marcos-iov marcos-iov merged commit 1060083 into feature/powpeg_validation_protocol-phase3 Oct 14, 2024
7 checks passed
@marcos-iov marcos-iov deleted the refactor_add_signature branch October 14, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants