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.
This commit is contained in:
Manfred Karrer 2019-01-03 22:32:27 +01:00
parent c137e7ec09
commit 0a9f4fc236
No known key found for this signature in database
GPG key ID: 401250966A6B2C46

View file

@ -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<TempTxOutput> 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