Search in sources :

Example 1 with TxGroup

use of io.nuls.consensus.entity.TxGroup 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 2 with TxGroup

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

the class GetTxGroupHandler method onEvent.

@Override
public void onEvent(GetTxGroupRequest event, String fromId) {
    GetTxGroupParam eventBody = event.getEventBody();
    Block block = blockService.getBlock(eventBody.getBlockHash().getDigestHex());
    if (null == block) {
        return;
    }
    TxGroupEvent txGroupEvent = new TxGroupEvent();
    TxGroup txGroup = new TxGroup();
    txGroup.setBlockHash(block.getHeader().getHash());
    List<Transaction> txList = getTxList(block, eventBody.getTxHashList());
    txGroup.setTxList(txList);
    txGroupEvent.setEventBody(txGroup);
    eventBroadcaster.sendToNode(txGroupEvent, fromId);
}
Also used : TxGroup(io.nuls.consensus.entity.TxGroup) Transaction(io.nuls.core.chain.entity.Transaction) GetTxGroupParam(io.nuls.consensus.entity.GetTxGroupParam) Block(io.nuls.core.chain.entity.Block) TxGroupEvent(io.nuls.consensus.event.TxGroupEvent)

Aggregations

TxGroup (io.nuls.consensus.entity.TxGroup)2 GetTxGroupParam (io.nuls.consensus.entity.GetTxGroupParam)1 RedPunishData (io.nuls.consensus.entity.RedPunishData)1 TxGroupEvent (io.nuls.consensus.event.TxGroupEvent)1 AssembledBlockNotice (io.nuls.consensus.event.notice.AssembledBlockNotice)1 Block (io.nuls.core.chain.entity.Block)1 Transaction (io.nuls.core.chain.entity.Transaction)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 ArrayList (java.util.ArrayList)1