@ -20,8 +20,8 @@ import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.Hash ;
import tech.pegasys.pantheon.ethereum.core.Hash ;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol ;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol ;
import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62 ;
import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62 ;
import tech.pegasys.pantheon.ethereum.eth.messages.NewBlockMessage ;
import tech.pegasys.pantheon.ethereum.eth.messages.StatusMessage ;
import tech.pegasys.pantheon.ethereum.eth.messages.StatusMessage ;
import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster ;
import tech.pegasys.pantheon.ethereum.p2p.api.Message ;
import tech.pegasys.pantheon.ethereum.p2p.api.Message ;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData ;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData ;
import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection ;
import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection ;
@ -37,7 +37,6 @@ import tech.pegasys.pantheon.util.uint.UInt256;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.List ;
import java.util.List ;
import java.util.Optional ;
import java.util.concurrent.CountDownLatch ;
import java.util.concurrent.CountDownLatch ;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.concurrent.atomic.AtomicBoolean ;
@ -64,6 +63,7 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
private final boolean fastSyncEnabled ;
private final boolean fastSyncEnabled ;
private List < Capability > supportedCapabilities ;
private List < Capability > supportedCapabilities ;
private final Blockchain blockchain ;
private final Blockchain blockchain ;
private final BlockBroadcaster blockBroadcaster ;
EthProtocolManager (
EthProtocolManager (
final Blockchain blockchain ,
final Blockchain blockchain ,
@ -73,7 +73,6 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
final int requestLimit ,
final int requestLimit ,
final EthScheduler scheduler ) {
final EthScheduler scheduler ) {
this . networkId = networkId ;
this . networkId = networkId ;
this . scheduler = scheduler ;
this . scheduler = scheduler ;
this . blockchain = blockchain ;
this . blockchain = blockchain ;
this . fastSyncEnabled = fastSyncEnabled ;
this . fastSyncEnabled = fastSyncEnabled ;
@ -85,6 +84,8 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
ethMessages = new EthMessages ( ) ;
ethMessages = new EthMessages ( ) ;
ethContext = new EthContext ( getSupportedProtocol ( ) , ethPeers , ethMessages , scheduler ) ;
ethContext = new EthContext ( getSupportedProtocol ( ) , ethPeers , ethMessages , scheduler ) ;
this . blockBroadcaster = new BlockBroadcaster ( ethContext ) ;
// Set up request handlers
// Set up request handlers
new EthServer ( blockchain , worldStateArchive , ethMessages , requestLimit ) ;
new EthServer ( blockchain , worldStateArchive , ethMessages , requestLimit ) ;
}
}
@ -271,24 +272,13 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
@Override
@Override
public void blockMined ( final Block block ) {
public void blockMined ( final Block block ) {
// This assumes the block has already been included in the chain
// This assumes the block has already been included in the chain
final UInt256 totalDifficulty =
final Optional < UInt256 > totalDifficulty = blockchain . getTotalDifficultyByHash ( block . getHash ( ) ) ;
blockchain
if ( ! totalDifficulty . isPresent ( ) ) {
. getTotalDifficultyByHash ( block . getHash ( ) )
throw new IllegalStateException (
. orElseThrow (
"Unable to get total difficulty from blockchain for mined block." ) ;
( ) - >
}
new IllegalStateException (
"Unable to get total difficulty from blockchain for mined block." ) ) ;
final NewBlockMessage newBlockMessage = NewBlockMessage . create ( block , totalDifficulty . get ( ) ) ;
blockBroadcaster . propagate ( block , totalDifficulty ) ;
ethPeers
. availablePeers ( )
. forEach (
peer - > {
try {
peer . send ( newBlockMessage ) ;
} catch ( final PeerNotConnected ex ) {
// Peers may disconnect while traversing the list, this is a normal occurrence.
}
} ) ;
}
}
}
}