Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into rskip351+rskip144
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Nov 15, 2023
2 parents 027ee5b + 3542363 commit afa01b8
Show file tree
Hide file tree
Showing 102 changed files with 5,043 additions and 1,882 deletions.
1 change: 1 addition & 0 deletions rskj-core/src/main/java/co/rsk/config/BridgeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.Federation;
import java.util.List;

import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.ECKey;

Expand Down Expand Up @@ -58,7 +58,7 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) {

// Expected federation address is:
// 2NCEo1RdmGDj6MqiipD6DUSerSxKv79FNWX
genesisFederation = new Federation(
genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import com.google.common.collect.Lists;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.ECKey;
Expand Down Expand Up @@ -53,7 +53,7 @@ public class BridgeMainNetConstants extends BridgeConstants {
// Wednesday, January 3, 2018 12:00:00 AM GMT-03:00
Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1514948400l);

genesisFederation = new Federation(
genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.HashUtil;
Expand Down Expand Up @@ -56,7 +56,7 @@ public BridgeRegTestConstants(List<BtcECKey> federationPublicKeys) {

Instant genesisFederationCreatedAt = ZonedDateTime.parse("2016-01-01T00:00:00Z").toInstant();

genesisFederation = new Federation(
genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationCreatedAt,
1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.Federation;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.ECKey;

Expand Down Expand Up @@ -61,7 +61,7 @@ public class BridgeTestNetConstants extends BridgeConstants {
// Currently set to: Monday, October 8, 2018 12:00:00 AM GMT-03:00
Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1538967600l);

genesisFederation = new Federation(
genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
Expand Down
20 changes: 10 additions & 10 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private static byte[] serializeFederationWithSerializer(Federation federation, F
}

// For the serialization format, see BridgeSerializationUtils::serializeFederationWithSerializer
private static Federation deserializeFederationWithDeserializer(
private static StandardMultisigFederation deserializeStandardMultisigFederationWithDeserializer(
byte[] data,
NetworkParameters networkParameters,
FederationMemberDesserializer federationMemberDesserializer) {
Expand All @@ -273,7 +273,7 @@ private static Federation deserializeFederationWithDeserializer(
federationMembers.add(member);
}

return new Federation(federationMembers, creationTime, creationBlockNumber, networkParameters);
return new StandardMultisigFederation(federationMembers, creationTime, creationBlockNumber, networkParameters);
}

/**
Expand All @@ -287,8 +287,8 @@ public static byte[] serializeFederationOnlyBtcKeys(Federation federation) {
}

// For the serialization format, see BridgeSerializationUtils::serializeFederationOnlyBtcKeys
public static Federation deserializeFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters) {
return deserializeFederationWithDeserializer(data, networkParameters,
public static StandardMultisigFederation deserializeStandardMultisigFederationOnlyBtcKeys(byte[] data, NetworkParameters networkParameters) {
return deserializeStandardMultisigFederationWithDeserializer(data, networkParameters,
(pubKeyBytes -> FederationMember.getFederationMemberFromKey(BtcECKey.fromPublicOnly(pubKeyBytes))));
}

Expand All @@ -304,29 +304,29 @@ public static byte[] serializeFederation(Federation federation) {
}

// For the serialization format, see BridgeSerializationUtils::serializeFederation
public static Federation deserializeFederation(
public static StandardMultisigFederation deserializeStandardMultisigFederation(
byte[] data,
NetworkParameters networkParameters
) {
return deserializeFederationWithDeserializer(
return deserializeStandardMultisigFederationWithDeserializer(
data,
networkParameters,
BridgeSerializationUtils::deserializeFederationMember
);
}

public static ErpFederation deserializeErpFederation(
public static LegacyErpFederation deserializeLegacyErpFederation(
byte[] data,
BridgeConstants bridgeConstants,
ActivationConfig.ForBlock activations
) {
Federation federation = deserializeFederationWithDeserializer(
Federation federation = deserializeStandardMultisigFederationWithDeserializer(
data,
bridgeConstants.getBtcParams(),
BridgeSerializationUtils::deserializeFederationMember
);

return new ErpFederation(
return new LegacyErpFederation(
federation.getMembers(),
federation.creationTime,
federation.getCreationBlockNumber(),
Expand All @@ -342,7 +342,7 @@ public static P2shErpFederation deserializeP2shErpFederation(
BridgeConstants bridgeConstants,
ActivationConfig.ForBlock activations
) {
Federation federation = deserializeFederationWithDeserializer(
Federation federation = deserializeStandardMultisigFederationWithDeserializer(
data,
bridgeConstants.getBtcParams(),
BridgeSerializationUtils::deserializeFederationMember
Expand Down
38 changes: 23 additions & 15 deletions rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
* @author Oscar Guindzberg
*/
public class BridgeStorageProvider {
private static final int FEDERATION_FORMAT_VERSION_MULTIKEY = 1000;
private static final int ERP_FEDERATION_FORMAT_VERSION = 2000;
private static final int P2SH_ERP_FEDERATION_FORMAT_VERSION = 3000;
protected static final int STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION = 1000;
protected static final int LEGACY_ERP_FEDERATION_FORMAT_VERSION = 2000;
protected static final int P2SH_ERP_FEDERATION_FORMAT_VERSION = 3000;

// Dummy value to use when saved Fast Bridge Derivation Argument Hash
private static final byte FLYOVER_FEDERATION_DERIVATION_HASH_TRUE_VALUE = (byte) 1;
Expand Down Expand Up @@ -336,7 +336,7 @@ public Federation getNewFederation() {
return deserializeFederationAccordingToVersion(data, storageVersion.get(), bridgeConstants);
}

return BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(data, networkParameters);
return BridgeSerializationUtils.deserializeStandardMultisigFederationOnlyBtcKeys(data, networkParameters);
}
);

Expand Down Expand Up @@ -364,15 +364,15 @@ public void saveNewFederation() {
NEW_FEDERATION_FORMAT_VERSION.getKey(),
P2SH_ERP_FEDERATION_FORMAT_VERSION
);
} else if (activations.isActive(RSKIP201) && newFederation instanceof ErpFederation) {
} else if (activations.isActive(RSKIP201) && newFederation instanceof LegacyErpFederation) {
saveStorageVersion(
NEW_FEDERATION_FORMAT_VERSION.getKey(),
ERP_FEDERATION_FORMAT_VERSION
LEGACY_ERP_FEDERATION_FORMAT_VERSION
);
} else {
saveStorageVersion(
NEW_FEDERATION_FORMAT_VERSION.getKey(),
FEDERATION_FORMAT_VERSION_MULTIKEY
STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION
);
}
serializer = BridgeSerializationUtils::serializeFederation;
Expand All @@ -398,7 +398,7 @@ public Federation getOldFederation() {
return deserializeFederationAccordingToVersion(data, storageVersion.get(), bridgeConstants);
}

return BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(data, networkParameters);
return BridgeSerializationUtils.deserializeStandardMultisigFederationOnlyBtcKeys(data, networkParameters);
}
);

Expand Down Expand Up @@ -428,12 +428,12 @@ protected void saveOldFederation() {
} else if (activations.isActive(RSKIP201) && oldFederation instanceof ErpFederation) {
saveStorageVersion(
OLD_FEDERATION_FORMAT_VERSION.getKey(),
ERP_FEDERATION_FORMAT_VERSION
LEGACY_ERP_FEDERATION_FORMAT_VERSION
);
} else {
saveStorageVersion(
OLD_FEDERATION_FORMAT_VERSION.getKey(),
FEDERATION_FORMAT_VERSION_MULTIKEY
STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION
);
}

Expand Down Expand Up @@ -480,7 +480,7 @@ public void savePendingFederation() {
RepositorySerializer<PendingFederation> serializer = BridgeSerializationUtils::serializePendingFederationOnlyBtcKeys;

if (activations.isActive(RSKIP123)) {
saveStorageVersion(PENDING_FEDERATION_FORMAT_VERSION.getKey(), FEDERATION_FORMAT_VERSION_MULTIKEY);
saveStorageVersion(PENDING_FEDERATION_FORMAT_VERSION.getKey(), STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION);
serializer = BridgeSerializationUtils::serializePendingFederation;
}

Expand Down Expand Up @@ -1028,8 +1028,8 @@ private Federation deserializeFederationAccordingToVersion(
BridgeConstants bridgeConstants
) {
switch (version) {
case ERP_FEDERATION_FORMAT_VERSION:
return BridgeSerializationUtils.deserializeErpFederation(
case LEGACY_ERP_FEDERATION_FORMAT_VERSION:
return BridgeSerializationUtils.deserializeLegacyErpFederation(
data,
bridgeConstants,
activations
Expand All @@ -1040,9 +1040,17 @@ private Federation deserializeFederationAccordingToVersion(
bridgeConstants,
activations
);
case STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION:
return BridgeSerializationUtils.deserializeStandardMultisigFederation(
data,
networkParameters
);
default:
// Assume this is the multi-key version
return BridgeSerializationUtils.deserializeFederation(data, networkParameters);
// To keep backwards compatibility
return BridgeSerializationUtils.deserializeStandardMultisigFederation(
data,
networkParameters
);
}
}

Expand Down
Loading

0 comments on commit afa01b8

Please sign in to comment.