Search in sources :

Example 1 with RedPunishData

use of io.nuls.consensus.entity.RedPunishData in project nuls by nuls-io.

the class RedPunishTxService method onCommit.

@Override
public void onCommit(RedPunishTransaction tx) throws NulsException {
    RedPunishData data = tx.getTxData();
    PunishLogPo po = new PunishLogPo();
    po.setAddress(data.getAddress());
    po.setHeight(data.getHeight());
    po.setId(StringUtils.getNewUUID());
    po.setTime(tx.getTime());
    po.setType(PunishType.RED.getCode());
    punishLogDataService.save(po);
}
Also used : RedPunishData(io.nuls.consensus.entity.RedPunishData) PunishLogPo(io.nuls.db.entity.PunishLogPo)

Example 2 with RedPunishData

use of io.nuls.consensus.entity.RedPunishData in project nuls by nuls-io.

the class TxGroupHandler method onEvent.

@Override
public void onEvent(TxGroupEvent event, String fromId) {
    TxGroup txGroup = event.getEventBody();
    BlockHeader header = temporaryCacheManager.getBlockHeader(event.getEventBody().getBlockHash().getDigestHex());
    if (header == null) {
        return;
    }
    SmallBlock smallBlock = temporaryCacheManager.getSmallBlock(header.getHash().getDigestHex());
    if (null == smallBlock) {
        return;
    }
    Block block = new Block();
    block.setHeader(header);
    List<Transaction> txs = new ArrayList<>();
    for (NulsDigestData txHash : smallBlock.getTxHashList()) {
        Transaction tx = txCacheManager.getTx(txHash);
        if (null == tx) {
            tx = txGroup.getTx(txHash.getDigestHex());
        }
        if (null == tx) {
            throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
        }
        txs.add(tx);
    }
    block.setTxs(txs);
    ValidateResult<RedPunishData> vResult = block.verify();
    if (null == vResult || (vResult.isFailed() && vResult.getErrorCode() != ErrorCode.ORPHAN_TX)) {
        if (vResult.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
            RedPunishData data = vResult.getObject();
            ConsensusMeetingRunner.putPunishData(data);
            networkService.blackNode(fromId, NodePo.BLACK);
        } else {
            networkService.removeNode(fromId, NodePo.YELLOW);
        }
        return;
    }
    blockManager.addBlock(block, false, fromId);
    downloadDataUtils.removeTxGroup(block.getHeader().getHash().getDigestHex());
    AssembledBlockNotice notice = new AssembledBlockNotice();
    notice.setEventBody(header);
    eventBroadcaster.publishToLocal(notice);
}
Also used : TxGroup(io.nuls.consensus.entity.TxGroup) RedPunishData(io.nuls.consensus.entity.RedPunishData) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) AssembledBlockNotice(io.nuls.consensus.event.notice.AssembledBlockNotice)

Example 3 with RedPunishData

use of io.nuls.consensus.entity.RedPunishData in project nuls by nuls-io.

the class ConsensusMeetingRunner method redPunishTx.

private void redPunishTx(Block bestBlock, List<Transaction> txList) throws NulsException, IOException {
    // todo check it
    for (long height : punishMap.keySet()) {
        RedPunishData data = punishMap.get(height);
        punishMap.remove(height);
        if (data.getHeight() < (bestBlock.getHeader().getHeight() + 1)) {
            continue;
        }
        RedPunishTransaction tx = new RedPunishTransaction();
        tx.setTxData(data);
        tx.setTime(TimeService.currentTimeMillis());
        tx.setFee(Na.ZERO);
        tx.setHash(NulsDigestData.calcDigestData(tx));
        tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), consensusManager.getConsensusStatusInfo().getAccount(), NulsContext.CACHED_PASSWORD_OF_WALLET).serialize());
        txList.add(tx);
    }
}
Also used : RedPunishTransaction(io.nuls.consensus.entity.tx.RedPunishTransaction) RedPunishData(io.nuls.consensus.entity.RedPunishData)

Example 4 with RedPunishData

use of io.nuls.consensus.entity.RedPunishData in project nuls by nuls-io.

the class RedPunishTxService method onRollback.

@Override
public void onRollback(RedPunishTransaction tx) throws NulsException {
    RedPunishData data = tx.getTxData();
    this.punishLogDataService.deleteByHeight(data.getHeight());
}
Also used : RedPunishData(io.nuls.consensus.entity.RedPunishData)

Example 5 with RedPunishData

use of io.nuls.consensus.entity.RedPunishData in project nuls by nuls-io.

the class DownloadDataUtils method requestTxGroup.

public void requestTxGroup(NulsDigestData blockHash, String nodeId) {
    GetTxGroupRequest request = new GetTxGroupRequest();
    GetTxGroupParam data = new GetTxGroupParam();
    data.setBlockHash(blockHash);
    List<NulsDigestData> txHashList = new ArrayList<>();
    SmallBlock smb = temporaryCacheManager.getSmallBlock(blockHash.getDigestHex());
    for (NulsDigestData txHash : smb.getTxHashList()) {
        boolean exist = txCacheManager.txExist(txHash);
        if (!exist) {
            txHashList.add(txHash);
        }
    }
    if (txHashList.isEmpty()) {
        BlockHeader header = temporaryCacheManager.getBlockHeader(smb.getBlockHash().getDigestHex());
        if (null == header) {
            return;
        }
        Block block = new Block();
        block.setHeader(header);
        List<Transaction> txs = new ArrayList<>();
        for (NulsDigestData txHash : smb.getTxHashList()) {
            Transaction tx = txCacheManager.getTx(txHash);
            if (null == tx) {
                throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
            }
            txs.add(tx);
        }
        block.setTxs(txs);
        ValidateResult<RedPunishData> vResult = block.verify();
        if (null == vResult || vResult.isFailed()) {
            if (vResult.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
                RedPunishData redPunishData = vResult.getObject();
                ConsensusMeetingRunner.putPunishData(redPunishData);
            }
            return;
        }
        blockManager.addBlock(block, false, nodeId);
        AssembledBlockNotice notice = new AssembledBlockNotice();
        notice.setEventBody(header);
        eventBroadcaster.publishToLocal(notice);
        return;
    }
    data.setTxHashList(txHashList);
    request.setEventBody(data);
    tgRequest.put(blockHash.getDigestHex(), System.currentTimeMillis());
    Integer value = tgRequestCount.get(blockHash.getDigestHex());
    if (null == value) {
        value = 0;
    }
    tgRequestCount.put(blockHash.getDigestHex(), 1 + value);
    if (StringUtils.isBlank(nodeId)) {
        eventBroadcaster.broadcastAndCache(request, false);
    } else {
        eventBroadcaster.sendToNode(request, nodeId);
    }
}
Also used : GetTxGroupRequest(io.nuls.consensus.event.GetTxGroupRequest) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) RedPunishData(io.nuls.consensus.entity.RedPunishData) GetTxGroupParam(io.nuls.consensus.entity.GetTxGroupParam) AssembledBlockNotice(io.nuls.consensus.event.notice.AssembledBlockNotice)

Aggregations

RedPunishData (io.nuls.consensus.entity.RedPunishData)5 AssembledBlockNotice (io.nuls.consensus.event.notice.AssembledBlockNotice)2 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 ArrayList (java.util.ArrayList)2 GetTxGroupParam (io.nuls.consensus.entity.GetTxGroupParam)1 TxGroup (io.nuls.consensus.entity.TxGroup)1 RedPunishTransaction (io.nuls.consensus.entity.tx.RedPunishTransaction)1 GetTxGroupRequest (io.nuls.consensus.event.GetTxGroupRequest)1 PunishLogPo (io.nuls.db.entity.PunishLogPo)1