Skip to content

Commit

Permalink
Merge pull request #2584 from ManfredKarrer/add-issuance-limit
Browse files Browse the repository at this point in the history
Add ISSUANCE_LIMIT param and check for max issuance per cycle
  • Loading branch information
ManfredKarrer authored Mar 25, 2019
2 parents 2a46133 + f75ddf9 commit 15bf8ff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public enum Param {
// Using BSQ as type is not really the best option but we don't want to introduce a new ParamType just for that one Param.
// As the end rules is in fact BSQ it is not completely incorrect as well.
BONDED_ROLE_FACTOR("1000", ParamType.BSQ, 2, 2),
ISSUANCE_LIMIT("200000", ParamType.BSQ, 2, 2), // Max. issuance+reimbursement per cycle.

// The last block in the proposal and vote phases are not shown to the user as he cannot make a tx there as it would be
// confirmed in the next block which would be the following break phase. To hide that complexity we show only the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.dao.governance.blindvote.VoteWithProposalTxId;
import bisq.core.dao.governance.blindvote.VoteWithProposalTxIdList;
import bisq.core.dao.governance.merit.MeritConsensus;
import bisq.core.dao.governance.param.Param;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.governance.proposal.IssuanceProposal;
import bisq.core.dao.governance.proposal.ProposalListPresentation;
Expand Down Expand Up @@ -535,15 +536,35 @@ private Set<EvaluatedProposal> getEvaluatedProposals(Set<DecryptedBallotsWithMer
proposalListPresentation.getActiveOrMyUnconfirmedProposals().stream()
.filter(proposal -> !evaluatedProposalsByTxIdMap.containsKey(proposal.getTxId()))
.forEach(proposal -> {
long requiredQuorum = daoStateService.getParamValueAsCoin(proposal.getQuorumParam(), chainHeight).value;
long requiredVoteThreshold = getRequiredVoteThreshold(chainHeight, proposal);

ProposalVoteResult proposalVoteResult = new ProposalVoteResult(proposal, 0,
0, 0, 0, decryptedBallotsWithMeritsSet.size());
EvaluatedProposal evaluatedProposal = new EvaluatedProposal(false, proposalVoteResult);
evaluatedProposals.add(evaluatedProposal);
log.info("Proposal ignored by all voters: {}", evaluatedProposal);
});

// Check if our issuance sum is not exceeding the limit
long sumIssuance = evaluatedProposals.stream()
.filter(EvaluatedProposal::isAccepted)
.map(EvaluatedProposal::getProposal)
.filter(proposal -> proposal instanceof IssuanceProposal)
.map(proposal -> (IssuanceProposal) proposal)
.mapToLong(proposal -> proposal.getRequestedBsq().value)
.sum();
long limit = daoStateService.getParamValueAsCoin(Param.ISSUANCE_LIMIT, chainHeight).value;
if (sumIssuance > limit) {
Set<EvaluatedProposal> evaluatedProposals2 = new HashSet<>();
evaluatedProposals.stream().filter(EvaluatedProposal::isAccepted)
.forEach(e -> evaluatedProposals2.add(new EvaluatedProposal(false, e.getProposalVoteResult())));
String msg = "We have a total issuance amount of " + sumIssuance / 100 + " BSQ but our limit for a cycle is " + limit / 100 + " BSQ. " +
"We consider that cycle as invalid and have set all proposals as rejected.";
log.warn(msg);

checkNotNull(daoStateService.getCurrentCycle(), "daoStateService.getCurrentCycle() must not be null");
voteResultExceptions.add(new VoteResultException(daoStateService.getCurrentCycle(), new VoteResultException.ConsensusException(msg)));
return evaluatedProposals2;
}

return evaluatedProposals;
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,8 @@ dao.param.MAX_TRADE_LIMIT=Max. trade limit in BTC

# suppress inspection "UnusedProperty"
dao.param.BONDED_ROLE_FACTOR=Bonded role unit factor in BSQ
# suppress inspection "UnusedProperty"
dao.param.ISSUANCE_LIMIT=Issuance limit per cycle in BSQ

dao.param.currentValue=Current value: {0}
dao.param.blocks={0} blocks
Expand Down

0 comments on commit 15bf8ff

Please sign in to comment.