Search in sources :

Example 16 with BlockExtendsData

use of io.nuls.consensus.poc.model.BlockExtendsData 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)

Aggregations

BlockExtendsData (io.nuls.consensus.poc.model.BlockExtendsData)16 BlockHeader (io.nuls.kernel.model.BlockHeader)7 ArrayList (java.util.ArrayList)6 PunishLogPo (io.nuls.consensus.poc.storage.po.PunishLogPo)5 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)5 MeetingRound (io.nuls.consensus.poc.model.MeetingRound)3 YellowPunishData (io.nuls.consensus.poc.protocol.entity.YellowPunishData)3 MeetingMember (io.nuls.consensus.poc.model.MeetingMember)2 YellowPunishTransaction (io.nuls.consensus.poc.protocol.tx.YellowPunishTransaction)2 RandomSeedStatusPo (io.nuls.consensus.poc.storage.po.RandomSeedStatusPo)2 ProtocolContainer (io.nuls.protocol.base.version.ProtocolContainer)2 CoinBaseTransaction (io.nuls.protocol.model.tx.CoinBaseTransaction)2 ProtocolTempInfoPo (io.nuls.protocol.storage.po.ProtocolTempInfoPo)2 IOException (java.io.IOException)2 BlockData (io.nuls.consensus.poc.model.BlockData)1 Chain (io.nuls.consensus.poc.model.Chain)1 Evidence (io.nuls.consensus.poc.model.Evidence)1 Agent (io.nuls.consensus.poc.protocol.entity.Agent)1 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)1 RedPunishData (io.nuls.consensus.poc.protocol.entity.RedPunishData)1