Skip to content

Commit

Permalink
Merge pull request #2881 from rsksmart/add_methods_to_clear_svp_values
Browse files Browse the repository at this point in the history
Use clear methods instead of setting null values
  • Loading branch information
marcos-iov authored Dec 9, 2024
2 parents 7025ca4 + dc3bca0 commit 4bfa2ac
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 26 deletions.
26 changes: 21 additions & 5 deletions rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ public void setSvpFundTxHashUnsigned(Sha256Hash hash) {
this.isSvpFundTxHashUnsignedSet = true;
}

public void clearSvpFundTxHashUnsigned() {
setSvpFundTxHashUnsigned(null);
}

private void saveSvpFundTxHashUnsigned() {
if (!activations.isActive(RSKIP419) || !isSvpFundTxHashUnsignedSet) {
return;
Expand All @@ -630,6 +634,10 @@ public void setSvpFundTxSigned(BtcTransaction svpFundTxSigned) {
this.isSvpFundTxSignedSet = true;
}

public void clearSvpFundTxSigned() {
setSvpFundTxSigned(null);
}

private void saveSvpFundTxSigned() {
if (!activations.isActive(RSKIP419) || !isSvpFundTxSignedSet) {
return;
Expand All @@ -646,6 +654,10 @@ public void setSvpSpendTxHashUnsigned(Sha256Hash hash) {
this.isSvpSpendTxHashUnsignedSet = true;
}

public void clearSvpSpendTxHashUnsigned() {
setSvpSpendTxHashUnsigned(null);
}

private void saveSvpSpendTxHashUnsigned() {
if (!activations.isActive(RSKIP419) || !isSvpSpendTxHashUnsignedSet) {
return;
Expand All @@ -670,6 +682,10 @@ public void setSvpSpendTxWaitingForSignatures(Map.Entry<Keccak256, BtcTransactio
this.isSvpSpendTxWaitingForSignaturesSet = true;
}

public void clearSvpSpendTxWaitingForSignatures() {
setSvpSpendTxWaitingForSignatures(null);
}

private void saveSvpSpendTxWaitingForSignatures() {
if (!activations.isActive(RSKIP419) || !isSvpSpendTxWaitingForSignaturesSet) {
return;
Expand All @@ -685,12 +701,12 @@ private void saveSvpSpendTxWaitingForSignatures() {
public void clearSvpValues() {
if (svpFundTxHashUnsigned != null) {
logger.warn("[clearSvpValues] Clearing fund tx hash unsigned {} value.", svpFundTxHashUnsigned);
setSvpFundTxHashUnsigned(null);
clearSvpFundTxHashUnsigned();
}

if (svpFundTxSigned != null) {
logger.warn("[clearSvpValues] Clearing fund tx signed {} value.", svpFundTxSigned.getHash());
setSvpFundTxSigned(null);
clearSvpFundTxSigned();
}

if (svpSpendTxWaitingForSignatures != null) {
Expand All @@ -700,13 +716,13 @@ public void clearSvpValues() {
"[clearSvpValues] Clearing spend tx waiting for signatures with spend tx {} and rsk creation hash {} value.",
svpSpendTx.getHash(), rskCreationHash
);
setSvpSpendTxWaitingForSignatures(null);
setSvpSpendTxHashUnsigned(null);
clearSvpSpendTxWaitingForSignatures();
clearSvpSpendTxHashUnsigned();
}

if (svpSpendTxHashUnsigned != null) {
logger.warn("[clearSvpValues] Clearing spend tx hash unsigned {} value.", svpSpendTxHashUnsigned);
setSvpSpendTxHashUnsigned(null);
clearSvpSpendTxHashUnsigned();
}
}

Expand Down
6 changes: 3 additions & 3 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private void registerSvpFundTx(BtcTransaction btcTx) throws IOException {

private void registerSvpSpendTx(BtcTransaction btcTx) throws IOException {
registerNewUtxos(btcTx);
provider.setSvpSpendTxHashUnsigned(null);
provider.clearSvpSpendTxHashUnsigned();

logger.info("[registerSvpSpendTx] Going to commit the proposed federation.");
federationSupport.commitProposedFederation();
Expand All @@ -458,7 +458,7 @@ private void updateSvpFundTransactionValues(BtcTransaction transaction) {
);

provider.setSvpFundTxSigned(transaction);
provider.setSvpFundTxHashUnsigned(null);
provider.clearSvpFundTxHashUnsigned();
}

@VisibleForTesting
Expand Down Expand Up @@ -1775,7 +1775,7 @@ private void addSvpSpendTxSignatures(
}

logReleaseBtc(svpSpendTx, svpSpendTxCreationRskTxHash.getBytes());
provider.setSvpSpendTxWaitingForSignatures(null);
provider.clearSvpSpendTxWaitingForSignatures();
}

private boolean areSignaturesEnoughToSignAllTxInputs(BtcTransaction releaseTx, List<byte[]> signatures) {
Expand Down
Loading

0 comments on commit 4bfa2ac

Please sign in to comment.