From 0a9f4fc236b189eb8481dedce2ae5ebd2bec61cd Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 3 Jan 2019 22:32:27 +0100 Subject: [PATCH] Remove phase and cycle check for vote reveal txs. We do not check phase or cycle as a late voteReveal tx is considered a valid BSQ tx. The vote result though will ignore such votes. Add more log info. --- .../bisq/core/dao/node/parser/TxParser.java | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/node/parser/TxParser.java b/core/src/main/java/bisq/core/dao/node/parser/TxParser.java index 3a3b4fbbf0..a728c95881 100644 --- a/core/src/main/java/bisq/core/dao/node/parser/TxParser.java +++ b/core/src/main/java/bisq/core/dao/node/parser/TxParser.java @@ -200,7 +200,8 @@ public class TxParser { processBlindVote(blockHeight, tempTx, bsqFee); break; case VOTE_REVEAL: - processVoteReveal(blockHeight, tempTx); + // We do not check phase or cycle as a late voteReveal tx is considered a valid BSQ tx. + // The vote result though will ignore such votes. break; case LOCKUP: case ASSET_LISTING_FEE: @@ -230,14 +231,14 @@ public class TxParser { } private void processProposal(int blockHeight, TempTx tempTx, long bsqFee) { - boolean isFeeAndPhaseValid = isFeeAndPhaseValid(blockHeight, bsqFee, DaoPhase.Phase.PROPOSAL, Param.PROPOSAL_FEE); + boolean isFeeAndPhaseValid = isFeeAndPhaseValid(tempTx.getId(), blockHeight, bsqFee, DaoPhase.Phase.PROPOSAL, Param.PROPOSAL_FEE); if (!isFeeAndPhaseValid) { tempTx.setTxType(TxType.INVALID); } } private void processIssuance(int blockHeight, TempTx tempTx, long bsqFee) { - boolean isFeeAndPhaseValid = isFeeAndPhaseValid(blockHeight, bsqFee, DaoPhase.Phase.PROPOSAL, Param.PROPOSAL_FEE); + boolean isFeeAndPhaseValid = isFeeAndPhaseValid(tempTx.getId(), blockHeight, bsqFee, DaoPhase.Phase.PROPOSAL, Param.PROPOSAL_FEE); Optional optionalIssuanceCandidate = txOutputParser.getOptionalIssuanceCandidate(); if (isFeeAndPhaseValid) { if (optionalIssuanceCandidate.isPresent()) { @@ -258,7 +259,7 @@ public class TxParser { } private void processBlindVote(int blockHeight, TempTx tempTx, long bsqFee) { - boolean isFeeAndPhaseValid = isFeeAndPhaseValid(blockHeight, bsqFee, DaoPhase.Phase.BLIND_VOTE, Param.BLIND_VOTE_FEE); + boolean isFeeAndPhaseValid = isFeeAndPhaseValid(tempTx.getId(), blockHeight, bsqFee, DaoPhase.Phase.BLIND_VOTE, Param.BLIND_VOTE_FEE); if (!isFeeAndPhaseValid) { tempTx.setTxType(TxType.INVALID); txOutputParser.getOptionalBlindVoteLockStakeOutput().ifPresent(tempTxOutput -> tempTxOutput.setTxOutputType(TxOutputType.BTC_OUTPUT)); @@ -267,22 +268,6 @@ public class TxParser { } } - private void processVoteReveal(int blockHeight, TempTx tempTx) { - boolean isPhaseValid = isPhaseValid(blockHeight, DaoPhase.Phase.VOTE_REVEAL); - if (!isPhaseValid) { - tempTx.setTxType(TxType.INVALID); - } - - // We must not use an `if else` here! - if (!isPhaseValid || !txInputParser.isVoteRevealInputValid()) { - txOutputParser.getOptionalVoteRevealUnlockStakeOutput().ifPresent( - tempTxOutput -> tempTxOutput.setTxOutputType(TxOutputType.BTC_OUTPUT)); - // Empty Optional case is a possible valid case where a random tx matches our opReturn rules but it is not a - // valid BSQ tx. - } - } - - /** * Whether the BSQ fee and phase is valid for a transaction. * @@ -292,10 +277,11 @@ public class TxParser { * @param param The parameter for the fee, e.g {@code Param.PROPOSAL_FEE}. * @return True if the fee and phase was valid, false otherwise. */ - private boolean isFeeAndPhaseValid(int blockHeight, long bsqFee, DaoPhase.Phase phase, Param param) { + private boolean isFeeAndPhaseValid(String txId, int blockHeight, long bsqFee, DaoPhase.Phase phase, Param param) { // The leftover BSQ balance from the inputs is the BSQ fee in case we are in an OP_RETURN output - if (!isPhaseValid(blockHeight, phase)) { + if (!periodService.isInPhase(blockHeight, phase)) { + log.warn("Tx with ID {} is not in required phase ({}). blockHeight={}", txId, phase, blockHeight); return false; } long paramValue = daoStateService.getParamValueAsCoin(param, blockHeight).value; @@ -306,14 +292,6 @@ public class TxParser { return isFeeCorrect; } - private boolean isPhaseValid(int blockHeight, DaoPhase.Phase phase) { - boolean isInPhase = periodService.isInPhase(blockHeight, phase); - if (!isInPhase) { - log.warn("Tx is not in required phase ({}). blockHeight={}", phase, blockHeight); - } - return isInPhase; - } - /////////////////////////////////////////////////////////////////////////////////////////// // Static methods