Search in sources :

Example 11 with MeetingRound

use of io.nuls.consensus.poc.model.MeetingRound in project nuls by nuls-io.

the class ConsensusTool method createYellowPunishTx.

public static YellowPunishTransaction createYellowPunishTx(Block preBlock, MeetingMember self, MeetingRound round) throws NulsException, IOException {
    BlockExtendsData preBlockRoundData = new BlockExtendsData(preBlock.getHeader().getExtend());
    if (self.getRoundIndex() - preBlockRoundData.getRoundIndex() > 1) {
        return null;
    }
    int yellowCount = 0;
    if (self.getRoundIndex() == preBlockRoundData.getRoundIndex() && self.getPackingIndexOfRound() != preBlockRoundData.getPackingIndexOfRound() + 1) {
        yellowCount = self.getPackingIndexOfRound() - preBlockRoundData.getPackingIndexOfRound() - 1;
    }
    if (self.getRoundIndex() != preBlockRoundData.getRoundIndex() && (self.getPackingIndexOfRound() != 1 || preBlockRoundData.getPackingIndexOfRound() != preBlockRoundData.getConsensusMemberCount())) {
        yellowCount = self.getPackingIndexOfRound() + preBlockRoundData.getConsensusMemberCount() - preBlockRoundData.getPackingIndexOfRound() - 1;
    }
    if (yellowCount == 0) {
        return null;
    }
    List<byte[]> addressList = new ArrayList<>();
    for (int i = 1; i <= yellowCount; i++) {
        int index = self.getPackingIndexOfRound() - i;
        if (index > 0) {
            MeetingMember member = round.getMember(index);
            if (member.getAgent() == null) {
                continue;
            } else if (member.getAgent().getDelHeight() > 0) {
                continue;
            }
            addressList.add(member.getAgentAddress());
        } else {
            MeetingRound preRound = round.getPreRound();
            MeetingMember member = preRound.getMember(index + preRound.getMemberCount());
            if (member.getAgent() == null || member.getAgent().getDelHeight() > 0) {
                continue;
            }
            addressList.add(member.getAgentAddress());
        }
    }
    if (addressList.isEmpty()) {
        return null;
    }
    YellowPunishTransaction punishTx = new YellowPunishTransaction();
    YellowPunishData data = new YellowPunishData();
    data.setAddressList(addressList);
    punishTx.setTxData(data);
    punishTx.setTime(self.getPackEndTime());
    punishTx.setHash(NulsDigestData.calcDigestData(punishTx.serializeForHash()));
    return punishTx;
}
Also used : BlockExtendsData(io.nuls.consensus.poc.model.BlockExtendsData) YellowPunishTransaction(io.nuls.consensus.poc.protocol.tx.YellowPunishTransaction) YellowPunishData(io.nuls.consensus.poc.protocol.entity.YellowPunishData) MeetingMember(io.nuls.consensus.poc.model.MeetingMember) MeetingRound(io.nuls.consensus.poc.model.MeetingRound)

Example 12 with MeetingRound

use of io.nuls.consensus.poc.model.MeetingRound in project nuls by nuls-io.

the class RoundManagerTest method testClearRound.

@Test
public void testClearRound() {
    MeetingRound round = new MeetingRound();
    round.setIndex(1l);
    roundManager.addRound(round);
    round = new MeetingRound();
    round.setIndex(2l);
    roundManager.addRound(round);
    round = new MeetingRound();
    round.setIndex(3l);
    roundManager.addRound(round);
    round = new MeetingRound();
    round.setIndex(4l);
    roundManager.addRound(round);
    round = new MeetingRound();
    round.setIndex(5l);
    roundManager.addRound(round);
    round = new MeetingRound();
    round.setIndex(6l);
    roundManager.addRound(round);
    round = new MeetingRound();
    round.setIndex(7l);
    roundManager.addRound(round);
    assertEquals(7, roundManager.getRoundList().size());
    assertEquals(7L, roundManager.getCurrentRound().getIndex());
    boolean success = roundManager.clearRound(3);
    assert (success);
    assertEquals(3, roundManager.getRoundList().size());
    assertEquals(7L, roundManager.getCurrentRound().getIndex());
}
Also used : MeetingRound(io.nuls.consensus.poc.model.MeetingRound) BaseChainTest(io.nuls.consensus.poc.BaseChainTest) Test(org.junit.Test)

Aggregations

MeetingRound (io.nuls.consensus.poc.model.MeetingRound)12 MeetingMember (io.nuls.consensus.poc.model.MeetingMember)6 BaseChainTest (io.nuls.consensus.poc.BaseChainTest)4 Test (org.junit.Test)4 BlockExtendsData (io.nuls.consensus.poc.model.BlockExtendsData)3 Agent (io.nuls.consensus.poc.protocol.entity.Agent)3 IOException (java.io.IOException)3 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)2 StopAgent (io.nuls.consensus.poc.protocol.entity.StopAgent)2 ContractResult (io.nuls.contract.dto.ContractResult)2 NulsException (io.nuls.kernel.exception.NulsException)2 ValidateResult (io.nuls.kernel.validate.ValidateResult)2 Chain (io.nuls.consensus.poc.model.Chain)1 CancelDeposit (io.nuls.consensus.poc.protocol.entity.CancelDeposit)1 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)1 RedPunishData (io.nuls.consensus.poc.protocol.entity.RedPunishData)1 YellowPunishData (io.nuls.consensus.poc.protocol.entity.YellowPunishData)1 RedPunishTransaction (io.nuls.consensus.poc.protocol.tx.RedPunishTransaction)1 YellowPunishTransaction (io.nuls.consensus.poc.protocol.tx.YellowPunishTransaction)1 ProtocolContainer (io.nuls.protocol.base.version.ProtocolContainer)1