Search in sources :

Example 1 with GetSmallBlockRequest

use of io.nuls.consensus.event.GetSmallBlockRequest in project nuls by nuls-io.

the class DownloadDataUtils method requestSmallBlock.

public void requestSmallBlock(NulsDigestData blockHash, String nodeId) {
    GetSmallBlockRequest request = new GetSmallBlockRequest();
    GetSmallBlockParam param = new GetSmallBlockParam();
    param.setBlockHash(blockHash);
    request.setEventBody(param);
    smbRequest.put(blockHash.getDigestHex(), System.currentTimeMillis());
    Integer value = smbRequestCount.get(blockHash.getDigestHex());
    if (value == null) {
        value = 0;
    }
    smbRequestCount.put(blockHash.getDigestHex(), 1 + value);
    if (StringUtils.isBlank(nodeId)) {
        eventBroadcaster.broadcastAndCache(request, false);
    } else {
        eventBroadcaster.sendToNode(request, nodeId);
    }
}
Also used : GetSmallBlockRequest(io.nuls.consensus.event.GetSmallBlockRequest) GetSmallBlockParam(io.nuls.consensus.entity.GetSmallBlockParam)

Example 2 with GetSmallBlockRequest

use of io.nuls.consensus.event.GetSmallBlockRequest in project nuls by nuls-io.

the class BlockHeaderHandler method onEvent.

@Override
public void onEvent(BlockHeaderEvent event, String fromId) {
    BlockHeader header = event.getEventBody();
    if (null == header) {
        Log.warn("recieved a null blockHeader!");
        return;
    }
    Block block = blockManager.getBlock(header.getHash().getDigestHex());
    if (null != block) {
        return;
    }
    GetSmallBlockRequest request = new GetSmallBlockRequest();
    GetSmallBlockParam param = new GetSmallBlockParam();
    param.setBlockHash(header.getHash());
    request.setEventBody(param);
    eventBroadcaster.sendToNode(request, fromId);
    temporaryCacheManager.cacheBlockHeader(header);
}
Also used : GetSmallBlockRequest(io.nuls.consensus.event.GetSmallBlockRequest) Block(io.nuls.core.chain.entity.Block) BlockHeader(io.nuls.core.chain.entity.BlockHeader) GetSmallBlockParam(io.nuls.consensus.entity.GetSmallBlockParam)

Aggregations

GetSmallBlockParam (io.nuls.consensus.entity.GetSmallBlockParam)2 GetSmallBlockRequest (io.nuls.consensus.event.GetSmallBlockRequest)2 Block (io.nuls.core.chain.entity.Block)1 BlockHeader (io.nuls.core.chain.entity.BlockHeader)1