Search in sources :

Example 1 with BroadcastNewBlock

use of org.aion.zero.impl.sync.msg.BroadcastNewBlock in project aion by aionnetwork.

the class BlockPropagationHandler method send.

private boolean send(AionBlock block, int nodeId) {
    // current proposal is to send to all peers with lower blockNumbers
    AtomicBoolean sent = new AtomicBoolean();
    this.p2pManager.getActiveNodes().values().stream().filter(n -> n.getIdHash() != nodeId).filter(n -> n.getBestBlockNumber() <= block.getNumber()).forEach(n -> {
        if (log.isDebugEnabled())
            log.debug("<sending-new-block hash=" + block.getShortHash() + " to-node=" + n.getIdShort() + ">");
        this.p2pManager.send(n.getIdHash(), new BroadcastNewBlock(block));
        sent.getAndSet(true);
    });
    return sent.get();
}
Also used : AionLoggerFactory(org.aion.log.AionLoggerFactory) IP2pMgr(org.aion.p2p.IP2pMgr) AionBlock(org.aion.zero.impl.types.AionBlock) Logger(org.slf4j.Logger) BroadcastNewBlock(org.aion.zero.impl.sync.msg.BroadcastNewBlock) LRUMap(org.apache.commons.collections4.map.LRUMap) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BlockHeaderValidator(org.aion.mcf.valid.BlockHeaderValidator) A0BlockHeader(org.aion.zero.types.A0BlockHeader) LogEnum(org.aion.log.LogEnum) IAionBlockchain(org.aion.zero.impl.core.IAionBlockchain) Map(java.util.Map) ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper) ImportResult(org.aion.mcf.core.ImportResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BroadcastNewBlock(org.aion.zero.impl.sync.msg.BroadcastNewBlock)

Example 2 with BroadcastNewBlock

use of org.aion.zero.impl.sync.msg.BroadcastNewBlock in project aion by aionnetwork.

the class BlockPropagationHandler method propagateNewBlock.

// assumption here is that blocks propagated have unique hashes
public void propagateNewBlock(final AionBlock block) {
    if (block == null)
        return;
    ByteArrayWrapper hashWrapped = new ByteArrayWrapper(block.getHash());
    synchronized (this.cacheMap) {
        this.cacheMap.put(hashWrapped, true);
    }
    this.p2pManager.getActiveNodes().values().forEach(n -> {
        if (log.isDebugEnabled())
            log.debug("<sending-new-block=" + block.getShortHash() + " to=" + n.getIdShort() + ">");
        this.p2pManager.send(n.getIdHash(), new BroadcastNewBlock(block));
    });
}
Also used : BroadcastNewBlock(org.aion.zero.impl.sync.msg.BroadcastNewBlock) ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Aggregations

ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)2 BroadcastNewBlock (org.aion.zero.impl.sync.msg.BroadcastNewBlock)2 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AionLoggerFactory (org.aion.log.AionLoggerFactory)1 LogEnum (org.aion.log.LogEnum)1 ImportResult (org.aion.mcf.core.ImportResult)1 BlockHeaderValidator (org.aion.mcf.valid.BlockHeaderValidator)1 IP2pMgr (org.aion.p2p.IP2pMgr)1 IAionBlockchain (org.aion.zero.impl.core.IAionBlockchain)1 AionBlock (org.aion.zero.impl.types.AionBlock)1 A0BlockHeader (org.aion.zero.types.A0BlockHeader)1 LRUMap (org.apache.commons.collections4.map.LRUMap)1 Logger (org.slf4j.Logger)1