-
Notifications
You must be signed in to change notification settings - Fork 266
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
Register spend tx #2851
Register spend tx #2851
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
5b4e5cc
to
9dd9f2a
Compare
9dd9f2a
to
65cb239
Compare
markTxAsProcessed(btcTx); | ||
saveNewUTXOs(btcTx); | ||
provider.setSvpSpendTxHashUnsigned(null); | ||
// proceed with svp success |
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 will be addressed in next task
private void setUpForTransactionRegistration(BtcTransaction transaction) throws BlockStoreException { | ||
// recreate a valid chain that has the tx, so it passes the previous checks in registerBtcTransaction | ||
BtcBlockStoreWithCache.Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(btcMainnetParams, 100, 100); | ||
BtcBlockStoreWithCache btcBlockStoreWithCache = btcBlockStoreFactory.newInstance(repository, bridgeMainNetConstants, bridgeStorageProvider, allActivations); | ||
|
||
pmtWithTransactions = createValidPmtForTransactions(Collections.singletonList(transaction.getHash()), btcMainnetParams); | ||
btcBlockWithPmtHeight = bridgeMainNetConstants.getBtcHeightWhenPegoutTxIndexActivates() + bridgeMainNetConstants.getPegoutTxIndexGracePeriodInBtcBlocks(); // we want pegout tx index to be activated | ||
|
||
int chainHeight = btcBlockWithPmtHeight + bridgeMainNetConstants.getBtc2RskMinimumAcceptableConfirmations(); | ||
recreateChainFromPmt(btcBlockStoreWithCache, chainHeight, pmtWithTransactions, btcBlockWithPmtHeight, btcMainnetParams); | ||
|
||
bridgeStorageProvider.save(); | ||
|
||
bridgeSupport = bridgeSupportBuilder | ||
.withBridgeConstants(bridgeMainNetConstants) | ||
.withProvider(bridgeStorageProvider) | ||
.withActivations(allActivations) | ||
.withFederationSupport(federationSupport) | ||
.withFeePerKbSupport(feePerKbSupport) | ||
.withExecutionBlock(rskExecutionBlock) | ||
.withBtcBlockStoreFactory(btcBlockStoreFactory) | ||
.withRepository(repository) | ||
.build(); | ||
} | ||
|
||
private void assertActiveFederationUtxosSize(int expectedActiveFederationUtxosSize) { | ||
assertEquals(expectedActiveFederationUtxosSize, federationSupport.getActiveFederationBtcUTXOs().size()); | ||
} | ||
|
||
private void assertTransactionWasProcessed(Sha256Hash transactionHash) throws IOException { | ||
Optional<Long> rskBlockHeightAtWhichBtcTxWasProcessed = bridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(transactionHash); | ||
assertTrue(rskBlockHeightAtWhichBtcTxWasProcessed.isPresent()); | ||
|
||
long rskExecutionBlockNumber = rskExecutionBlock.getNumber(); | ||
assertEquals(rskExecutionBlockNumber, rskBlockHeightAtWhichBtcTxWasProcessed.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.
this was just moved outside to be reused
65cb239
to
30dafce
Compare
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.
rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java
Outdated
Show resolved
Hide resolved
fbb0e14
to
32e510c
Compare
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.
Well done. Just some minor comments to improve the naming of the unit tests to be more specific on what's the result expected
32e510c
to
007ffad
Compare
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
return provider.getSvpSpendTxHashUnsigned() | ||
.map(svpSpendTransactionHashUnsigned -> | ||
getMultiSigTransactionHashWithoutSignatures(networkParameters, transaction).equals(svpSpendTransactionHashUnsigned) | ||
) | ||
.orElse(false); |
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.
return provider.getSvpSpendTxHashUnsigned() | |
.map(svpSpendTransactionHashUnsigned -> | |
getMultiSigTransactionHashWithoutSignatures(networkParameters, transaction).equals(svpSpendTransactionHashUnsigned) | |
) | |
.orElse(false); | |
return provider.getSvpFundTxHashUnsigned() | |
.filter(svpFundTransactionHashUnsigned -> | |
getMultiSigTransactionHashWithoutSignatures(networkParameters, transaction).equals(svpFundTransactionHashUnsigned) | |
) | |
.isPresent(); |
Just an alternative for you to consider. No difference in practice, not sure if somehow using a filter
to find something is more appropiate than using a map
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
@@ -57,7 +57,17 @@ public static Optional<Script> extractRedeemScriptFromInput(TransactionInput txI | |||
} | |||
} | |||
|
|||
public static void removeSignaturesFromTransactionWithP2shMultiSigInputs(BtcTransaction transaction) { | |||
public static Sha256Hash getMultiSigTransactionHashWithoutSignatures(NetworkParameters networkParameters, BtcTransaction transaction) { | |||
if (!transaction.hasWitness()) { |
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 (!transaction.hasWitness()) { | |
if (transaction.hasWitness()) { | |
return transaction.getHash(); | |
} | |
... |
Nit, just to return early
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 put it this way considering the txs are normally segwit (correct me if im wrong! :) ), so we will have the common behavior outside the check
} | ||
|
||
@Test | ||
void removeSignaturesFromTransaction_whenTransactionInputsDoNotHaveP2shMultiSigInputScript_shouldThrowIllegalArgumentException() { | ||
void getTransactionHashWithoutSignatures_whenTxIsNotSegwitAndTransactionInputsDoNotHaveP2shMultiSigInputScript_shouldThrowIllegalArgumentException() { |
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.
An idea to add a test for this new method and removeSignatures..
one.
Take a pegout from mainnet. Get the raw transaction from a release_btc event, that is the signed transaction. Then get the unsigned tx hash from the corresponding release_requested
event. We can use these 2 values to do a test with real transactions
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.
super nice, 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 :)
Quality Gate passedIssues Measures |
0d4c61c
into
feature/powpeg_validation_protocol-phase4
No description provided.