Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use clear methods instead of setting null values #2881

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading