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

Svp success #2854

Merged
merged 8 commits into from
Nov 25, 2024
Merged

Conversation

julia-zack
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented Nov 20, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

@julia-zack julia-zack force-pushed the svp_success branch 2 times, most recently from 8c79e6e to 41fccdc Compare November 20, 2024 20:10
Comment on lines -704 to -708
if (activations.isActive(RSKIP186)) {
// since we are creating the to-be-active-fed in this block,
// its creation block height is this block number
saveFederationChangeInfo(rskExecutionBlock.getNumber());
}
Copy link
Contributor Author

@julia-zack julia-zack Nov 21, 2024

Choose a reason for hiding this comment

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

this is being done in handover method now

Copy link
Contributor Author

@julia-zack julia-zack Nov 21, 2024

Choose a reason for hiding this comment

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

removing the re-declaration of activations since its being done in the setUp

@julia-zack julia-zack marked this pull request as ready for review November 21, 2024 15:00
@julia-zack julia-zack requested a review from a team as a code owner November 21, 2024 15:00

public static Script getFederationMembersP2SHScript(ActivationConfig.ForBlock activations, Federation federation) {
// when the federation is a standard multisig,
// the members p2sh script is the p2sh script
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think there's space for this to be in a single line with the above. It's a bit confusing I think.

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

}

// when the federation also has erp keys,
// the members p2sh script is the default p2sh script
Copy link
Contributor

Choose a reason for hiding this comment

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

The same here.

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!

Base automatically changed from register_spend_tx to feature/powpeg_validation_protocol-phase4 November 21, 2024 20:53
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.

Looking good, just once thing we might what to make the base branch this one #2857

@@ -52,8 +53,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP284;
import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP293;
import static org.ethereum.config.blockchain.upgrades.ConsensusRule.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move the static imports to top file

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

Comment on lines 629 to 635
if (!(federation instanceof ErpFederation)) {
return federation.getP2SHScript();
}

// when the federation also has erp keys,
// the members p2sh script is the default p2sh script
return ((ErpFederation) federation).getDefaultP2SHScript();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way we can avoid doing explicit casting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not right now

Federation currentOldFederation = provider.getOldFederation(constants, activations);
Federation currentNewFederation = provider.getNewFederation(constants, activations);
logCommitmentWithVotedFederation(eventLogger, currentOldFederation, currentNewFederation);

return FederationChangeResponseCode.SUCCESSFUL;
}

public void commitProposedFederation() {
Federation proposedFederation = provider.getProposedFederation(constants, activations)
.orElseThrow(IllegalStateException::new);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: big identation, only four spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

List<UTXO> utxosToMove = new ArrayList<>(provider.getNewFederationBtcUTXOs(constants.getBtcParams(), activations));
// since the current active fed reference will change from being 'new' to 'old',
// we have to change the UTXOs reference to match it
List<UTXO> activeFederationUTXOs = new ArrayList<>(provider.getNewFederationBtcUTXOs(constants.getBtcParams(), activations));
Copy link
Contributor

Choose a reason for hiding this comment

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

why pass the list to the constructor of another list?

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 is to create a shallow copy of the list before clear the original one. Btw, you can do this instead:

Suggested change
List<UTXO> activeFederationUTXOs = new ArrayList<>(provider.getNewFederationBtcUTXOs(constants.getBtcParams(), activations));
List<UTXO> activeFederationUTXOs = provider.getNewFederationBtcUTXOs(constants.getBtcParams(), activations).stream().toList();

Copy link
Contributor

Choose a reason for hiding this comment

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

Or simply use List.copyOf

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

import co.rsk.peg.utils.BridgeEventLogger;
import co.rsk.peg.utils.BridgeEventLoggerImpl;
import co.rsk.test.builders.BridgeSupportBuilder;
import java.io.IOException;
import java.util.*;
import java.util.stream.IntStream;

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove blank line

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

Comment on lines 38 to 42
import static co.rsk.peg.BridgeUtils.getFederationMembersP2SHScript;
import static co.rsk.peg.bitcoin.BitcoinTestUtils.flatKeysAsByteArray;
import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP377;
import static co.rsk.peg.federation.FederationStorageIndexKey.NEW_FEDERATION_BTC_UTXOS_KEY;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would move the static imports to the top for consistency

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 registerBtcTransaction_whenIsTheSpendTransaction_shouldProcessSpendTx() throws BlockStoreException, BridgeIllegalArgumentException, IOException {
void registerBtcTransaction_whenIsNotTheSpendTransaction_shouldNotProcessSpendTx() throws BlockStoreException, BridgeIllegalArgumentException, IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add the test cases when tx is a PEGIN or UNKNOWN also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the pegin case could be, the unknown i dont think is necessary.
but we definitely should be testing that the spend tx is being processed even when it does not have the minimum pegin value! So thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

This is interesting, if the spend tx is below the min peg-in value I don't think the powpeg will inform it to the Bridge

}

@Test
void registerBtcTransaction_whenSpendTransactionHashIsNotSaved_shouldNotProcessSpendTx() throws BlockStoreException, BridgeIllegalArgumentException, IOException {
void registerBtcTransaction_whenIsTheSpendTransaction_shouldProcessSpendTxAndSvpSuccess() throws BlockStoreException, BridgeIllegalArgumentException, IOException {
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 we are missing some border cases:

  • Trying to register the spend transaction for a second time. What is the expected result?
  • Trying to register the spend transaction spent by the ERP Flow. I guess it should be registered if the transaction arrives on time.

Copy link
Contributor Author

@julia-zack julia-zack Nov 22, 2024

Choose a reason for hiding this comment

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

  1. Trying to register the spend transaction for a second time. What is the expected result?

the tx is being marked as processed when registered, same as any other tx. So it won't be registered again. I will add a test for that case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Trying to register the spend transaction spent by the ERP Flow. I guess it should be registered if the transaction arrives on time.

Well, no. We specifically wanna test that the proposed federators can spend.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I followed the second part, you need a year to sign ith the ERP flow

Copy link
Contributor

@nathanieliov nathanieliov Nov 22, 2024

Choose a reason for hiding this comment

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

True, the value set is 1 year. But shouldn't we also check that we can spend using the ERP Flow? Just an idea that came to my mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -619,4 +619,17 @@ public static int calculatePegoutTxSize(ActivationConfig.ForBlock activations, F

return baseSize + signingSize;
}

public static Script getFederationMembersP2SHScript(ActivationConfig.ForBlock activations, Federation federation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite confusing, really hard to understand what's going on.

What's the idea? Get the default p2sh script or the full p2sh script? Seems like any of those can be achieved through Federation class methods

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

List<UTXO> utxosToMove = new ArrayList<>(provider.getNewFederationBtcUTXOs(constants.getBtcParams(), activations));
// since the current active fed reference will change from being 'new' to 'old',
// we have to change the UTXOs reference to match it
List<UTXO> activeFederationUTXOs = new ArrayList<>(provider.getNewFederationBtcUTXOs(constants.getBtcParams(), activations));
Copy link
Contributor

Choose a reason for hiding this comment

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

Or simply use List.copyOf

}

@Test
void registerBtcTransaction_whenSpendTransactionHashIsNotSaved_shouldNotProcessSpendTx() throws BlockStoreException, BridgeIllegalArgumentException, IOException {
void registerBtcTransaction_whenIsTheSpendTransaction_shouldProcessSpendTxAndSvpSuccess() throws BlockStoreException, BridgeIllegalArgumentException, IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I followed the second part, you need a year to sign ith the ERP flow

Copy link

sonarcloud bot commented Nov 25, 2024

@julia-zack julia-zack merged commit 2ae9834 into feature/powpeg_validation_protocol-phase4 Nov 25, 2024
8 checks passed
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.

5 participants