Search in sources :

Example 1 with GetTxGroupParam

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

the class SmallBlockHandler method onEvent.

@Override
public void onEvent(SmallBlockEvent event, String fromId) {
    ValidateResult result = event.getEventBody().verify();
    if (result.isFailed()) {
        return;
    }
    temporaryCacheManager.cacheSmallBlock(event.getEventBody());
    downloadDataUtils.removeSmallBlock(event.getEventBody().getBlockHash().getDigestHex());
    GetTxGroupRequest request = new GetTxGroupRequest();
    GetTxGroupParam param = new GetTxGroupParam();
    param.setBlockHash(event.getEventBody().getBlockHash());
    for (NulsDigestData hash : event.getEventBody().getTxHashList()) {
        if (!receivedTxCacheManager.txExist(hash)) {
            param.addHash(hash);
        }
    }
    request.setEventBody(param);
    this.eventBroadcaster.sendToNode(request, fromId);
}
Also used : GetTxGroupRequest(io.nuls.consensus.event.GetTxGroupRequest) ValidateResult(io.nuls.core.validate.ValidateResult) GetTxGroupParam(io.nuls.consensus.entity.GetTxGroupParam) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData)

Example 2 with GetTxGroupParam

use of io.nuls.consensus.entity.GetTxGroupParam 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)

Example 3 with GetTxGroupParam

use of io.nuls.consensus.entity.GetTxGroupParam 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

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