Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[NC-2058] initial scaffolding re block propagation #860

Merged
merged 12 commits into from
Feb 14, 2019
Prev Previous commit
Next Next commit
scaffolding
  • Loading branch information
smatthewenglish committed Feb 7, 2019
commit d4468a52eed67acbd5742e705e32ce0a48a60e52
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static com.google.common.base.Preconditions.checkArgument;

import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.eth.manager.ChainState.EstimatedHeightListener;
import tech.pegasys.pantheon.ethereum.eth.manager.RequestManager.ResponseStream;
Expand Down Expand Up @@ -130,6 +131,13 @@ public ResponseStream send(final MessageData messageData) throws PeerNotConnecte
}
}

// Sends block to a peer...
public void propagateBlock(Block block, UInt256 totalDifficulty) {

// New Block Message...
connection.
}

public ResponseStream getHeadersByHash(
final Hash hash, final int maxHeaders, final int skip, final boolean reverse)
throws PeerNotConnected {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tech.pegasys.pantheon.ethereum.eth.manager.EthContext;
import tech.pegasys.pantheon.ethereum.eth.manager.EthMessage;
import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer;
import tech.pegasys.pantheon.ethereum.eth.manager.EthPeers;
import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62;
import tech.pegasys.pantheon.ethereum.eth.messages.NewBlockHashesMessage;
import tech.pegasys.pantheon.ethereum.eth.messages.NewBlockHashesMessage.NewBlockHash;
Expand Down Expand Up @@ -144,6 +145,21 @@ private void onBlockAdded(final BlockAddedEvent blockAddedEvent, final Blockchai
}
}

// Predicated on the type of information requested, announce a block's availability
// or propagate it to a subset of peers: "Announced block" vs. "Propagated block".
private void broadcastBlock(Block block) {

// Determine total difficulty of block...

// If propagation is requested, send to a subset of peers
List<EthPeer> availablePeers = ethContext.getEthPeers().availablePeers().collect(Collectors.toList());

// Send the block...
for(EthPeer ethPeer : availablePeers) {
ethPeer.send();
}
}

private void handleNewBlockFromNetwork(final EthMessage message) {
final Blockchain blockchain = protocolContext.getBlockchain();
final NewBlockMessage newBlockMessage = NewBlockMessage.readFrom(message.getData());
Expand Down