Skip to content

Commit

Permalink
When signed, save the svp fund tx instead of its hash
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Sep 18, 2024
1 parent e468239 commit 47da759
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum BridgeStorageIndexKey {
PEGOUT_TX_SIG_HASH("pegoutTxSigHash"),

SVP_FUND_TX_HASH_UNSIGNED("svpFundTxHashUnsigned"),
SVP_FUND_TX_HASH_SIGNED("svpFundTxHashSigned"),
SVP_FUND_TX_SIGNED("svpFundTxSigned"),
SVP_SPEND_TX_HASH_UNSIGNED("svpSpendTxHashUnsigned"),
SVP_SPEND_TX_WAITING_FOR_SIGNATURES("svpSpendTxWaitingForSignatures"),
;
Expand Down
34 changes: 17 additions & 17 deletions rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public class BridgeStorageProvider {

private Sha256Hash svpFundTxHashUnsigned;
private boolean isSvpFundTxHashUnsignedSet = false;
private Sha256Hash svpFundTxHashSigned;
private boolean isSvpFundTxHashSignedSet = false;
private BtcTransaction svpFundTxSigned;
private boolean isSvpFundTxSignedSet = false;
private Sha256Hash svpSpendTxHashUnsigned;
private boolean isSvpSpendTxHashUnsignedSet = false;
private Map.Entry<Keccak256, BtcTransaction> svpSpendTxWaitingForSignatures;
Expand Down Expand Up @@ -381,7 +381,7 @@ public Optional<FlyoverFederationInformation> getFlyoverFederationInformation(by
return Optional.empty();
}

FlyoverFederationInformation flyoverFederationInformationInStorage = this.safeGetFromRepository(
FlyoverFederationInformation flyoverFederationInformationInStorage = safeGetFromRepository(
getStorageKeyForFlyoverFederationInformation(flyoverFederationRedeemScriptHash),
data -> BridgeSerializationUtils.deserializeFlyoverFederationInformation(data, flyoverFederationRedeemScriptHash)
);
Expand Down Expand Up @@ -547,23 +547,23 @@ public Optional<Sha256Hash> getSvpFundTxHashUnsigned() {
return Optional.ofNullable(svpFundTxHashUnsigned);
}

public Optional<Sha256Hash> getSvpFundTxHashSigned() {
public Optional<BtcTransaction> getSvpFundTxSigned() {
if (!activations.isActive(RSKIP419)) {
return Optional.empty();
}

if (svpFundTxHashSigned != null) {
return Optional.of(svpFundTxHashSigned);
if (svpFundTxSigned != null) {
return Optional.of(svpFundTxSigned);
}

// Return empty if the svp fund tx hash unsigned was explicitly set to null
if (isSvpFundTxHashSignedSet) {
if (isSvpFundTxSignedSet) {
return Optional.empty();
}

svpFundTxHashSigned = safeGetFromRepository(
SVP_FUND_TX_HASH_SIGNED.getKey(), BridgeSerializationUtils::deserializeSha256Hash);
return Optional.ofNullable(svpFundTxHashSigned);
svpFundTxSigned = safeGetFromRepository(SVP_FUND_TX_SIGNED,
data -> BridgeSerializationUtils.deserializeBtcTransaction(data, networkParameters));
return Optional.ofNullable(svpFundTxSigned);
}

public Optional<Sha256Hash> getSvpSpendTxHashUnsigned() {
Expand Down Expand Up @@ -601,20 +601,20 @@ private void saveSvpFundTxHashUnsigned() {
BridgeSerializationUtils::serializeSha256Hash);
}

public void setSvpFundTxHashSigned(Sha256Hash hash) {
this.svpFundTxHashSigned = hash;
this.isSvpFundTxHashSignedSet = true;
public void setSvpFundTxSigned(BtcTransaction svpFundTxSigned) {
this.svpFundTxSigned = svpFundTxSigned;
this.isSvpFundTxSignedSet = true;
}

private void saveSvpFundTxHashSigned() {
if (!activations.isActive(RSKIP419) || !isSvpFundTxHashSignedSet) {
if (!activations.isActive(RSKIP419) || !isSvpFundTxSignedSet) {
return;
}

safeSaveToRepository(
SVP_FUND_TX_HASH_SIGNED,
svpFundTxHashSigned,
BridgeSerializationUtils::serializeSha256Hash);
SVP_FUND_TX_SIGNED,
svpFundTxSigned,
BridgeSerializationUtils::serializeBtcTransaction);
}

public void setSvpSpendTxHashUnsigned(Sha256Hash hash) {
Expand Down
Loading

0 comments on commit 47da759

Please sign in to comment.