Search in sources :

Example 1 with ParamChange

use of bisq.core.dao.state.governance.ParamChange 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)

Example 2 with ParamChange

use of bisq.core.dao.state.governance.ParamChange in project bisq-core by bisq-network.

the class BsqStateService method setNewParam.

// /////////////////////////////////////////////////////////////////////////////////////////
// Param
// /////////////////////////////////////////////////////////////////////////////////////////
public void setNewParam(int blockHeight, Param param, long paramValue) {
    List<ParamChange> paramChangeList = bsqState.getParamChangeList();
    getStartHeightOfNextCycle(blockHeight).ifPresent(heightOfNewCycle -> {
        ParamChange paramChange = new ParamChange(param.name(), paramValue, heightOfNewCycle);
        paramChangeList.add(paramChange);
        // Addition with older height should not be possible but to ensure correct sorting lets run a sort.
        paramChangeList.sort(Comparator.comparingInt(ParamChange::getActivationHeight));
    });
}
Also used : ParamChange(bisq.core.dao.state.governance.ParamChange)

Aggregations

ParamChange (bisq.core.dao.state.governance.ParamChange)2 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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ObservableList (javafx.collections.ObservableList)1