Search in sources :

Example 1 with ChangeParamProposal

use of bisq.core.dao.governance.proposal.param.ChangeParamProposal in project bisq-core by bisq-network.

the class VoteResultService method applyParamChange.

private void applyParamChange(Set<EvaluatedProposal> acceptedEvaluatedProposals, int chainHeight) {
    Map<String, List<EvaluatedProposal>> evaluatedProposalsByParam = new HashMap<>();
    acceptedEvaluatedProposals.forEach(evaluatedProposal -> {
        if (evaluatedProposal.getProposal() instanceof ChangeParamProposal) {
            ChangeParamProposal changeParamProposal = (ChangeParamProposal) evaluatedProposal.getProposal();
            ParamChange paramChange = getParamChange(changeParamProposal, chainHeight);
            if (paramChange != null) {
                String paramName = paramChange.getParamName();
                evaluatedProposalsByParam.putIfAbsent(paramName, new ArrayList<>());
                evaluatedProposalsByParam.get(paramName).add(evaluatedProposal);
            }
        }
    });
    evaluatedProposalsByParam.forEach((key, list) -> {
        if (list.size() == 1) {
            applyAcceptedChangeParamProposal((ChangeParamProposal) list.get(0).getProposal(), chainHeight);
        } else if (list.size() > 1) {
            log.warn("There have been multiple winning param change proposals with the same item. " + "This is a sign of a social consensus failure. " + "We treat all requests as failed in such a case.");
        // TODO remove code once we are 100% sure we stick with the above solution.
        // We got multiple proposals for the same parameter. We check which one got the higher stake and that
        // one will be the winner. If both have same stake none will be the winner.
        /*list.sort(Comparator.comparing(ev -> ev.getProposalVoteResult().getStakeOfAcceptedVotes()));
                Collections.reverse(list);
                EvaluatedProposal first = list.get(0);
                EvaluatedProposal second = list.get(1);
                if (first.getProposalVoteResult().getStakeOfAcceptedVotes() >
                        second.getProposalVoteResult().getStakeOfAcceptedVotes()) {
                    applyAcceptedChangeParamProposal((ChangeParamProposal) first.getProposal(), chainHeight);
                } else {
                    // Rare case that both have the same stake. We don't need to check for a third entry as if 2 have
                    // the same we are already in the abort case to reject all proposals with that param
                    log.warn("We got the rare case that multiple changeParamProposals have received the same stake. " +
                            "None will be accepted in such a case.\n" +
                            "EvaluatedProposal={}", list);
                }*/
        }
    });
}
Also used : ChangeParamProposal(bisq.core.dao.governance.proposal.param.ChangeParamProposal) HashMap(java.util.HashMap) ParamChange(bisq.core.dao.state.governance.ParamChange) List(java.util.List) BallotList(bisq.core.dao.governance.ballot.BallotList) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) MeritList(bisq.core.dao.governance.merit.MeritList) VoteWithProposalTxIdList(bisq.core.dao.governance.blindvote.VoteWithProposalTxIdList)

Aggregations

BallotList (bisq.core.dao.governance.ballot.BallotList)1 VoteWithProposalTxIdList (bisq.core.dao.governance.blindvote.VoteWithProposalTxIdList)1 MeritList (bisq.core.dao.governance.merit.MeritList)1 ChangeParamProposal (bisq.core.dao.governance.proposal.param.ChangeParamProposal)1 ParamChange (bisq.core.dao.state.governance.ParamChange)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ObservableList (javafx.collections.ObservableList)1