Skip to content

Commit

Permalink
Add more checks to validateDataFields
Browse files Browse the repository at this point in the history
Signed-off-by: HenrikJannsen <[email protected]>
  • Loading branch information
HenrikJannsen committed Jun 29, 2024
1 parent 6edffe6 commit d7cf503
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void updateLists() {
// So we only add proposals if they are unconfirmed and therefore not yet parsed. Once confirmed they have to be
// found in the daoStateService.
List<Proposal> myUnconfirmedProposals = myProposalListService.getList().stream()
.filter(p -> !daoStateService.getTx(p.getTxId()).isPresent()) // Tx is still not in our bsq blocks
.filter(p -> daoStateService.getTx(p.getTxId()).isEmpty()) // Tx is still not in our bsq blocks
.filter(p -> {
TransactionConfidence confidenceForTxId = bsqWalletService.getConfidenceForTxId(p.getTxId());
return confidenceForTxId != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void onProtectedDataAdded(ProtectedStorageEntry entry, boolean fromBroad
}
tempProposals.add(proposal);
} else {
log.debug("We received an invalid proposal from the P2P network. Proposal={}, blockHeight={}",
log.warn("We received an invalid proposal from the P2P network. Proposal={}, blockHeight={}",
proposal, daoStateService.getChainHeight());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import bisq.core.dao.governance.proposal.ProposalValidationException;
import bisq.core.dao.governance.proposal.ProposalValidator;
import bisq.core.dao.state.DaoStateService;
import bisq.core.dao.state.model.governance.BondedRoleType;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.dao.state.model.governance.Role;
import bisq.core.dao.state.model.governance.RoleProposal;

import javax.inject.Inject;

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang3.Validate.notNull;

/**
Expand All @@ -48,7 +51,13 @@ public void validateDataFields(Proposal proposal) throws ProposalValidationExcep
super.validateDataFields(proposal);

RoleProposal roleProposal = (RoleProposal) proposal;
notNull(roleProposal.getRole(), "Bonded role must not be null");
Role role = roleProposal.getRole();
notNull(role, "Bonded role must not be null");
BondedRoleType bondedRoleType = role.getBondedRoleType();
checkArgument(roleProposal.getUnlockTime() == bondedRoleType.getUnlockTimeInBlocks(),
"Invalid unlocktime");
checkArgument(roleProposal.getRequiredBondUnit() == bondedRoleType.getRequiredBondUnit(),
"Invalid requiredBondUnit");
} catch (Throwable throwable) {
throw new ProposalValidationException(throwable);
}
Expand Down

0 comments on commit d7cf503

Please sign in to comment.