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