Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bridge Constants Refactor Integration #2309

Merged
merged 20 commits into from
May 17, 2024

Conversation

wilmerrootstock
Copy link
Contributor

@wilmerrootstock wilmerrootstock commented Apr 29, 2024

Description

All these changes are part of a general Bridge Constants Refactor:

  • Moving BridgeConstants class and all classes (regtest, testnet, mainnet, devnet) related to co.rsk.peg.constants package to Peg package.
  • Moving the BridgeConstantsTest class to the same package inside the test section.
  • For the sake of decoupling RSKj, we are applying some changes to remove the dependency between BridgeConstants and Federation classes.
  • The FederationMember class contains a KeyType enum. This enum has a Value field that must be declared with the final keyword.
  • releaseBtc method is printing a message showing the wrong unit. We changed the log message to print Weis as the unit instead of Satoshis getting the value in Weis from the Rsk transaction before converting it to satoshis with rskTx.getValue().
  • There are 2 bridge constants related to the minimum pegout value. legacyMinimumPegoutTxValueInSatoshis and minimumPegoutTxValueInSatoshis. These names are not precise, because the data type is actually a Coin object, so it’s not an amount and should not have a unit. For this reason, we renamed both constants to legacyMinimumPegoutTxValue and minimumPegoutTxValue respectively.

fed:bridge-constants-refactor-integration

Motivation and Context

  • We are passing all the objects to Peg package to put all objects related to Powpeg together. With this, we are taking a step forward to decouple Powpeg.
  • Decouple RSKj
  • This is part of a tech debt and improves good practices on the project. The Final keyword will make this attribute immutable, which is a good practice for handling concurrent transactions and avoiding state modification after creation.
  • This improves the traceability of the project.
  • To improve naming conventions.

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

@wilmerrootstock wilmerrootstock requested review from a team as code owners April 29, 2024 15:43
@wilmerrootstock
Copy link
Contributor Author

pipeline:run

@wilmerrootstock wilmerrootstock force-pushed the bridge-constants-refactor-integration branch from 036c773 to 6849f76 Compare May 3, 2024 07:05
@@ -743,7 +743,7 @@
BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationsBeforeForks);

provider0.getReleaseRequestQueue().add(new BtcECKey().toAddress(btcParams), Coin.COIN);
provider0.getNewFederationBtcUTXOs().add(new UTXO(PegTestUtils.createHash(), 1, Coin.COIN.add(Coin.valueOf(100)), 0, false, ScriptBuilder.createOutputScript(federation.getAddress())));
provider0.getNewFederationBtcUTXOs().add(new UTXO(PegTestUtils.createHash(), 1, Coin.COIN.add(Coin.valueOf(100)), 0, false, ScriptBuilder.createOutputScript(genesisFederation.getAddress())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
PegTestUtils.createHash
should be avoided because it has been deprecated.
FederationArgs genesisFedArgs = new FederationArgs(FederationTestUtils.getFederationMembersWithKeys(
Stream.iterate(1, i -> i + 1)
.limit(6)
.map(i -> BtcECKey.fromPrivate(BigInteger.valueOf((i) * 100)))

Check warning

Code scanning / CodeQL

Result of multiplication cast to wider type Warning test

Potential overflow in
int multiplication
before it is converted to long by use in an invocation context.
@wilmerrootstock wilmerrootstock force-pushed the bridge-constants-refactor-integration branch from 6849f76 to eed3809 Compare May 4, 2024 00:51
@marcos-iov marcos-iov force-pushed the bridge-constants-refactor-integration branch from eed3809 to 7b8a31b Compare May 8, 2024 21:45
@marcos-iov
Copy link
Contributor

pipeline:run

@marcos-iov marcos-iov force-pushed the bridge-constants-refactor-integration branch from 30bf8ed to e186005 Compare May 15, 2024 15:12
@marcos-iov
Copy link
Contributor

pipeline:run

1 similar comment
@marcos-iov
Copy link
Contributor

pipeline:run

@marcos-iov marcos-iov force-pushed the bridge-constants-refactor-integration branch from 0fade16 to 9b13500 Compare May 15, 2024 16:40
@marcos-iov
Copy link
Contributor

pipeline:run

@marcos-iov marcos-iov force-pushed the bridge-constants-refactor-integration branch from 9b13500 to d0f57a9 Compare May 17, 2024 13:11
wilmerrootstock and others added 15 commits May 17, 2024 10:37
- Moving BridgeConstants class and all classes (regtest, testnet, mainnet, DevNet) related to co.rsk.peg.constants package.
- Moving BridgeConstantsTest class to the same package inside tests section.
- Converting list as an unmodifiableList to fix issue reported by SonarQube for List that are declared as public static since making a mutable field, such as an array, final will keep the variable from being reassigned, but doing so has no effect on the mutability of the internal state of the array.
- Moving BridgeConstants class and all classes (regtest, testnet, mainnet, DevNet) related to co.rsk.peg.constants package.
- Moving BridgeConstantsTest class to the same package inside tests section.
- Removing class variable, injection in the constructor and its implementation.
- Modifying isFromGenesisFederation method signature to add List<BtcECKey> genesisFederationPublicKeys as an in parameter.
- Adding changes to the tests to adapt it to new way to get Genesis Federation.
- Creating a new constant called GENESIS_FEDERATION_CREATION_BLOCK_NUMBER in FederationTestUtils.java and this same variable/constant in FederationSupport#getGenesisFederation
- Improving the readability in the statement lambda in BridgeUtils#isFromGenesisFederation
- New test to make sure BrigdeConstants has the correct GenesisFederationCreationTime according to the network.
- Improving Utils classes:
FederationTestUtils:
adding final keyword at level class to avoid this class could be inherited and to improve the class performance.
adding a private constructor to avoid this utility class could be instantiated

BridgeUtils: adding final keyword at level class to avoid this class could be inherited and to improve the class performance.
- Reformat code in a code block in BridgeSupportAddSignatureTest.java
- Reusing mainnet in classes where it already exists. Replacing Regtest.
- Addressing review comment: Use meaningful variable names. Improving Federation variables
- Cleaning up fix for the unit test BridgeSupportTestIntegration#getFederationMethods_genesis.
- Fixing variable names issues:
1.genesisFederation turns into activeFederation since it is used by a When clause like an activeFederation.
2. genesisFederation2 turns into genesisFederation.
1. Indentation on BridgeSupportAddSignatureTest#addSignature_fedPubKey_belongs_to_active_federation
2. On BridgeUtils#createPegOutTx, variable genesisFederation turns into federation since it could be different types of Federations
3. On FederationSupportTest was improved the whenNewFederationIsNullThenActiveFederationIsGenesisFederation Unit Test.
4. GENESIS_FEDERATION_CREATION_BLOCK_NUMBER was removed as class level constant and was included in the only one method it is being used.
5. On P2shErpFederationTest#getBtcPublicKeys() was removed the creation of genesisFederation and use getGenesisFederationPublicKeys() directly from BridgeConstants
Replacing BridgeRegTestConstants values with BridgeMainNetConstants values.
wilmerrootstock and others added 5 commits May 17, 2024 10:37
The FederationMember class contains a KeyType enum. This enum has a Value field that must be declared with the final keyword.
releaseBtc method is printing a message showing the wrong unit. Change the log message to print Weis as the unit.

Get the value in weis from the rsk transaction before converting it to satoshis with rskTx.getValue().
- Changed RBTC to weis in the log message.
There are 2 bridge constants related to the minimum pegout value. legacyMinimumPegoutTxValueInSatoshis and minimumPegoutTxValueInSatoshis

The name is not precise, because the data type is actually a Coin object, so it’s not an amount and should not have a unit. For this reason, we renamed both constants to legacyMinimumPegoutTxValue and minimumPegoutTxValue respectively.
@marcos-iov marcos-iov force-pushed the bridge-constants-refactor-integration branch from d0f57a9 to 36ca811 Compare May 17, 2024 13:37
Copy link

@marcos-iov
Copy link
Contributor

pipeline:run

@marcos-iov
Copy link
Contributor

pipeline:run

@Vovchyk Vovchyk merged commit 0eae5fb into master May 17, 2024
10 checks passed
@Vovchyk Vovchyk deleted the bridge-constants-refactor-integration branch May 17, 2024 15:14
@aeidelman aeidelman added this to the Arrowhead 6.4.0 milestone Oct 30, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants