@ -63,6 +63,7 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem ;
import org.hyperledger.besu.plugin.services.MetricsSystem ;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat ;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat ;
import org.hyperledger.besu.testutil.TestClock ;
import org.hyperledger.besu.testutil.TestClock ;
import org.hyperledger.besu.util.number.ByteUnits ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.List ;
import java.util.List ;
@ -95,6 +96,7 @@ public abstract class AbstractBlockPropagationManagerTest {
protected SyncState syncState ;
protected SyncState syncState ;
protected final MetricsSystem metricsSystem = new NoOpMetricsSystem ( ) ;
protected final MetricsSystem metricsSystem = new NoOpMetricsSystem ( ) ;
private final Hash finalizedHash = Hash . fromHexStringLenient ( "0x1337" ) ;
private final Hash finalizedHash = Hash . fromHexStringLenient ( "0x1337" ) ;
private final int maxMessageSize = 10 * ByteUnits . MEGABYTE ;
protected void setup ( final DataStorageFormat dataStorageFormat ) {
protected void setup ( final DataStorageFormat dataStorageFormat ) {
blockchainUtil = BlockchainSetupUtil . forTesting ( dataStorageFormat ) ;
blockchainUtil = BlockchainSetupUtil . forTesting ( dataStorageFormat ) ;
@ -222,11 +224,14 @@ public abstract class AbstractBlockPropagationManagerTest {
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final NewBlockMessage nextAnnouncement =
final NewBlockMessage nextAnnouncement =
NewBlockMessage . create (
NewBlockMessage . create (
nextBlock , getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ) ;
nextBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final NewBlockMessage nextNextAnnouncement =
final NewBlockMessage nextNextAnnouncement =
NewBlockMessage . create (
NewBlockMessage . create (
nextNextBlock ,
nextNextBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextNextBlock . getHash ( ) ) . get ( ) ) ;
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextNextBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
// Broadcast first message
// Broadcast first message
@ -256,11 +261,14 @@ public abstract class AbstractBlockPropagationManagerTest {
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final NewBlockMessage nextAnnouncement =
final NewBlockMessage nextAnnouncement =
NewBlockMessage . create (
NewBlockMessage . create (
nextBlock , getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ) ;
nextBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final NewBlockMessage nextNextAnnouncement =
final NewBlockMessage nextNextAnnouncement =
NewBlockMessage . create (
NewBlockMessage . create (
nextNextBlock ,
nextNextBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextNextBlock . getHash ( ) ) . get ( ) ) ;
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextNextBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
// Broadcast second message first
// Broadcast second message first
@ -299,7 +307,9 @@ public abstract class AbstractBlockPropagationManagerTest {
block1 . getHash ( ) , block1 . getHeader ( ) . getNumber ( ) ) ) ) ;
block1 . getHash ( ) , block1 . getHeader ( ) . getNumber ( ) ) ) ) ;
final NewBlockMessage block2Msg =
final NewBlockMessage block2Msg =
NewBlockMessage . create (
NewBlockMessage . create (
block2 , getFullBlockchain ( ) . getTotalDifficultyByHash ( block2 . getHash ( ) ) . get ( ) ) ;
block2 ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( block2 . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final NewBlockHashesMessage block3Msg =
final NewBlockHashesMessage block3Msg =
NewBlockHashesMessage . create (
NewBlockHashesMessage . create (
Collections . singletonList (
Collections . singletonList (
@ -307,7 +317,9 @@ public abstract class AbstractBlockPropagationManagerTest {
block3 . getHash ( ) , block3 . getHeader ( ) . getNumber ( ) ) ) ) ;
block3 . getHash ( ) , block3 . getHeader ( ) . getNumber ( ) ) ) ) ;
final NewBlockMessage block4Msg =
final NewBlockMessage block4Msg =
NewBlockMessage . create (
NewBlockMessage . create (
block4 , getFullBlockchain ( ) . getTotalDifficultyByHash ( block4 . getHash ( ) ) . get ( ) ) ;
block4 ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( block4 . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
// Broadcast older blocks
// Broadcast older blocks
@ -362,7 +374,9 @@ public abstract class AbstractBlockPropagationManagerTest {
nextBlock . getHash ( ) , nextBlock . getHeader ( ) . getNumber ( ) ) ) ) ;
nextBlock . getHash ( ) , nextBlock . getHeader ( ) . getNumber ( ) ) ) ) ;
final NewBlockMessage newBlock =
final NewBlockMessage newBlock =
NewBlockMessage . create (
NewBlockMessage . create (
nextBlock , getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ) ;
nextBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
// Broadcast first message
// Broadcast first message
@ -413,7 +427,9 @@ public abstract class AbstractBlockPropagationManagerTest {
nextBlock . getHash ( ) , nextBlock . getHeader ( ) . getNumber ( ) ) ) ) ;
nextBlock . getHash ( ) , nextBlock . getHeader ( ) . getNumber ( ) ) ) ) ;
final NewBlockMessage newBlock =
final NewBlockMessage newBlock =
NewBlockMessage . create (
NewBlockMessage . create (
nextBlock , getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ) ;
nextBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
// Broadcast messages
// Broadcast messages
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , newBlock ) ;
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , newBlock ) ;
@ -467,7 +483,9 @@ public abstract class AbstractBlockPropagationManagerTest {
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final NewBlockMessage futureAnnouncement =
final NewBlockMessage futureAnnouncement =
NewBlockMessage . create (
NewBlockMessage . create (
futureBlock , getFullBlockchain ( ) . getTotalDifficultyByHash ( futureBlock . getHash ( ) ) . get ( ) ) ;
futureBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( futureBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
// Broadcast
// Broadcast
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , futureAnnouncement ) ;
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , futureAnnouncement ) ;
@ -522,7 +540,8 @@ public abstract class AbstractBlockPropagationManagerTest {
// Setup peer and messages
// Setup peer and messages
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final NewBlockMessage oldAnnouncement = NewBlockMessage . create ( oldBlock , Difficulty . ZERO ) ;
final NewBlockMessage oldAnnouncement =
NewBlockMessage . create ( oldBlock , Difficulty . ZERO , maxMessageSize ) ;
// Broadcast
// Broadcast
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , oldAnnouncement ) ;
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , oldAnnouncement ) ;
@ -559,7 +578,7 @@ public abstract class AbstractBlockPropagationManagerTest {
blockPropagationManager . start ( ) ;
blockPropagationManager . start ( ) ;
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final NewBlockMessage blockAnnouncementMsg =
final NewBlockMessage blockAnnouncementMsg =
NewBlockMessage . create ( blockToPurge , Difficulty . ZERO ) ;
NewBlockMessage . create ( blockToPurge , Difficulty . ZERO , maxMessageSize ) ;
// Broadcast
// Broadcast
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , blockAnnouncementMsg ) ;
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , blockAnnouncementMsg ) ;
@ -597,7 +616,8 @@ public abstract class AbstractBlockPropagationManagerTest {
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHeader ( ) . getParentHash ( ) ) . get ( ) ;
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHeader ( ) . getParentHash ( ) ) . get ( ) ;
final Difficulty totalDifficulty =
final Difficulty totalDifficulty =
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ;
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ;
final NewBlockMessage nextAnnouncement = NewBlockMessage . create ( nextBlock , totalDifficulty ) ;
final NewBlockMessage nextAnnouncement =
NewBlockMessage . create ( nextBlock , totalDifficulty , maxMessageSize ) ;
// Broadcast message
// Broadcast message
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , nextAnnouncement ) ;
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , nextAnnouncement ) ;
@ -735,7 +755,8 @@ public abstract class AbstractBlockPropagationManagerTest {
final Difficulty totalDifficulty =
final Difficulty totalDifficulty =
getFullBlockchain ( ) . getTotalDifficultyByHash ( block . getHash ( ) ) . get ( ) ;
getFullBlockchain ( ) . getTotalDifficultyByHash ( block . getHash ( ) ) . get ( ) ;
final NewBlockMessage newBlockMessage = NewBlockMessage . create ( block , totalDifficulty ) ;
final NewBlockMessage newBlockMessage =
NewBlockMessage . create ( block , totalDifficulty , maxMessageSize ) ;
// Broadcast message
// Broadcast message
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , newBlockMessage ) ;
EthProtocolManagerTestUtil . broadcastMessage ( ethProtocolManager , peer , newBlockMessage ) ;
@ -933,7 +954,9 @@ public abstract class AbstractBlockPropagationManagerTest {
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final RespondingEthPeer peer = EthProtocolManagerTestUtil . createPeer ( ethProtocolManager , 0 ) ;
final NewBlockMessage nextAnnouncement =
final NewBlockMessage nextAnnouncement =
NewBlockMessage . create (
NewBlockMessage . create (
nextBlock , getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ) ;
nextBlock ,
getFullBlockchain ( ) . getTotalDifficultyByHash ( nextBlock . getHash ( ) ) . get ( ) ,
maxMessageSize ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
final Responder responder = RespondingEthPeer . blockchainResponder ( getFullBlockchain ( ) ) ;
syncState . setReachedTerminalDifficulty ( true ) ;
syncState . setReachedTerminalDifficulty ( true ) ;