Skip to content

Commit

Permalink
Merge pull request #115 from rsksmart/new-erp-script-4.1.1
Browse files Browse the repository at this point in the history
New erp script 4.1.1
  • Loading branch information
marcos-iov authored Nov 16, 2022
2 parents 2326218 + 6a95c1d commit 3da60d1
Show file tree
Hide file tree
Showing 5 changed files with 547 additions and 161 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tasks.withType(AbstractArchiveTask) {

ext {
bitcoinjcoreVersion = '0.15.6-rsk-2'
bitcoinjVersion = '0.14.4-rsk-12'
bitcoinjVersion = '0.14.4-rsk-14'
commonsLang3Version = '3.5'
commonsIoVersion = '2.5'
slf4jVersion = '1.7.25'
Expand All @@ -65,7 +65,7 @@ ext {
junitVersion = '4.12'
mockitoVersion = '2.23.4'
powermockitoVersion = '2.0.2'
rskjcoreVersion = '4.1.0-HOP'
rskjcoreVersion = '4.1.1-HOP-TESTNET'
}

dependencies {
Expand Down
20 changes: 10 additions & 10 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
<sha256 value="6f9c5578df1e4dd58debf5b6693e88cd7a76653908e8e675e9a74ca093231aae" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="co.rsk" name="rskj-core" version="4.1.0-HOP">
<artifact name="rskj-core-4.1.0-HOP.jar">
<sha256 value="65f3b183d72166e3cce209e6546b687e9b10b9c9e0750e4a4a7f1bb28f957fed" origin="Generated by Gradle"/>
<component group="co.rsk" name="rskj-core" version="4.1.1-HOP-TESTNET">
<artifact name="rskj-core-4.1.1-HOP-TESTNET.jar">
<sha256 value="d31fd099d26fd2edd1f9fa726e2d3e3a5cbaaec6ca4c803b1bc51cacd704603f" origin="Generated by Gradle"/>
</artifact>
<artifact name="rskj-core-4.1.0-HOP.module">
<sha256 value="a7df6994466abffeac61405984be4237f937dd25ce0fd1c42fed1c387b2835de" origin="Generated by Gradle"/>
<artifact name="rskj-core-4.1.1-HOP-TESTNET.module">
<sha256 value="9c689f5476c36e64969d80cacdbb7951d5fbe16579dc482b41177c94d0d25c2a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="co.rsk.bitcoinj" name="bitcoinj-thin" version="0.14.4-rsk-12">
<artifact name="bitcoinj-thin-0.14.4-rsk-12.jar">
<sha256 value="c7089559775c62d212fe839cf5bfeb3592f4545dd41f54d2fe474cf6b8f9641a" origin="Generated by Gradle"/>
<component group="co.rsk.bitcoinj" name="bitcoinj-thin" version="0.14.4-rsk-14">
<artifact name="bitcoinj-thin-0.14.4-rsk-14.jar">
<sha256 value="76c16c354cdbe1844ab7501eb536b3f8da31c8679f1765813af4748e7af31abe" origin="Generated by Gradle"/>
</artifact>
<artifact name="bitcoinj-thin-0.14.4-rsk-12.pom">
<sha256 value="e79cb080ed7569b7e6e4c1533edeb62ba9b81c784b3da9dca5d7aa473402aa46" origin="Generated by Gradle"/>
<artifact name="bitcoinj-thin-0.14.4-rsk-14.pom">
<sha256 value="3e650b44d944cbbf886f2b04fb03f9d829a0b73c084d602ea481ff8571fba8cb" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.fasterxml" name="oss-parent" version="27">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import co.rsk.peg.ErpFederation;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.P2shErpFederation;
import org.ethereum.crypto.ECKey;

import java.time.Instant;
Expand Down Expand Up @@ -75,25 +76,14 @@ public Federation getActiveFederation() {
Instant creationTime = federatorSupport.getFederationCreationTime();
long creationBlockNumber = federatorSupport.getFederationCreationBlockNumber();

Federation initialFederation =
new Federation(members, creationTime, creationBlockNumber, federatorSupport.getBtcParams());

Address federationAddress = federatorSupport.getFederationAddress();

if (initialFederation.getAddress().equals(federationAddress)) {
return initialFederation;
}

// There is no reason for addresses not to match but being an ERP federation
return new ErpFederation(
Federation initialFederation = new Federation(
members,
creationTime,
creationBlockNumber,
federatorSupport.getBtcParams(),
bridgeConstants.getErpFedPubKeysList(),
bridgeConstants.getErpFedActivationDelay(),
federatorSupport.getConfigForBestBlock()
federatorSupport.getBtcParams()
);

return getExpectedFederation(initialFederation, getActiveFederationAddress());
}

@Override
Expand All @@ -104,10 +94,13 @@ public Address getActiveFederationAddress() {
@Override
public Optional<Federation> getRetiringFederation() {
Integer federationSize = federatorSupport.getRetiringFederationSize();
if (federationSize == -1) {
Optional<Address> optionalRetiringFederationAddress = getRetiringFederationAddress();

if (federationSize == -1 || !optionalRetiringFederationAddress.isPresent()) {
return Optional.empty();
}

Address retiringFederationAddress = optionalRetiringFederationAddress.get();
boolean useTypedPublicKeyGetter = federatorSupport.getConfigForBestBlock().isActive(RSKIP123);
List<FederationMember> members = new ArrayList<>();
for (int i = 0; i < federationSize; i++) {
Expand All @@ -133,31 +126,14 @@ public Optional<Federation> getRetiringFederation() {
Instant creationTime = federatorSupport.getRetiringFederationCreationTime();
long creationBlockNumber = federatorSupport.getRetiringFederationCreationBlockNumber();

Federation initialFederation =
new Federation(members, creationTime, creationBlockNumber, federatorSupport.getBtcParams());

Optional<Address> optionalFederationAddress = federatorSupport.getRetiringFederationAddress();
Address federationAddress = null;

if (optionalFederationAddress.isPresent()) {
federationAddress = optionalFederationAddress.get();
}

if (initialFederation.getAddress().equals(federationAddress)) {
return Optional.of(initialFederation);
}

return Optional.of(
new ErpFederation(
members,
creationTime,
creationBlockNumber,
federatorSupport.getBtcParams(),
bridgeConstants.getErpFedPubKeysList(),
bridgeConstants.getErpFedActivationDelay(),
federatorSupport.getConfigForBestBlock()
)
Federation initialFederation = new Federation(
members,
creationTime,
creationBlockNumber,
federatorSupport.getBtcParams()
);

return Optional.of(getExpectedFederation(initialFederation, retiringFederationAddress));
}

@Override
Expand All @@ -175,4 +151,41 @@ public List<Federation> getLiveFederations() {

return result;
}

private Federation getExpectedFederation(Federation initialFederation, Address expectedFederationAddress) {
// First check if the initial federation address matches the expected one
if (initialFederation.getAddress().equals(expectedFederationAddress)) {
return initialFederation;
}

// If addresses do not match build an ERP federation
Federation erpFederation = new ErpFederation(
initialFederation.getMembers(),
initialFederation.getCreationTime(),
initialFederation.getCreationBlockNumber(),
federatorSupport.getBtcParams(),
bridgeConstants.getErpFedPubKeysList(),
bridgeConstants.getErpFedActivationDelay(),
federatorSupport.getConfigForBestBlock()
);

if (erpFederation.getAddress().equals(expectedFederationAddress)) {
return erpFederation;
}

// Finally, try building a P2SH ERP federation
return new P2shErpFederation(
initialFederation.getMembers(),
initialFederation.getCreationTime(),
initialFederation.getCreationBlockNumber(),
federatorSupport.getBtcParams(),
bridgeConstants.getErpFedPubKeysList(),
bridgeConstants.getErpFedActivationDelay(),
federatorSupport.getConfigForBestBlock()
);

// TODO: what if no federation built matches the expected address?
// It could mean that there is a different type of federation in the Bridge that we are not considering here
// We should consider throwing an exception and shutting down the node
}
}
2 changes: 1 addition & 1 deletion src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
versionNumber='4.1.1.0'
modifier="RC"
modifier="HOP-TESTNET"
Loading

0 comments on commit 3da60d1

Please sign in to comment.