@@ -45,6 +45,10 @@ type GethNodeTestConfiguration struct {
4545 // The node mines proof of work blocks
4646 PoWMiner bool
4747 PoWMinerEtherBase common.Address
48+ DisableGossiping bool
49+
50+ // Block Modifier
51+ BlockModifier helper.BlockModifier
4852
4953 // In PoW production mode, produce many terminal blocks which shall be gossiped
5054 TerminalBlockSiblingCount * big.Int
@@ -81,15 +85,14 @@ var (
8185 DefaultTerminalBlockSiblingDepth = big .NewInt (1 )
8286)
8387
84- func (s GethNodeEngineStarter ) StartClient (T * hivesim.T , testContext context.Context , ClientParams hivesim.Params , ClientFiles hivesim.Params , bootClient client.EngineClient ) (client.EngineClient , error ) {
85- return s .StartGethNode (T , testContext , ClientParams , ClientFiles , bootClient )
88+ func (s GethNodeEngineStarter ) StartClient (T * hivesim.T , testContext context.Context , ClientParams hivesim.Params , ClientFiles hivesim.Params , bootClients ... client.EngineClient ) (client.EngineClient , error ) {
89+ return s .StartGethNode (T , testContext , ClientParams , ClientFiles , bootClients ... )
8690}
8791
88- func (s GethNodeEngineStarter ) StartGethNode (T * hivesim.T , testContext context.Context , ClientParams hivesim.Params , ClientFiles hivesim.Params , bootClient client.EngineClient ) (* GethNode , error ) {
92+ func (s GethNodeEngineStarter ) StartGethNode (T * hivesim.T , testContext context.Context , ClientParams hivesim.Params , ClientFiles hivesim.Params , bootClients ... client.EngineClient ) (* GethNode , error ) {
8993 var (
90- ttd = s .TerminalTotalDifficulty
91- bootnode string
92- err error
94+ ttd = s .TerminalTotalDifficulty
95+ err error
9396 )
9497 genesisPath , ok := ClientFiles ["/genesis.json" ]
9598 if ! ok {
@@ -111,10 +114,14 @@ func (s GethNodeEngineStarter) StartGethNode(T *hivesim.T, testContext context.C
111114 }
112115 genesis .Config .TerminalTotalDifficulty = ttd
113116
114- if bootClient != nil {
115- bootnode , err = bootClient .EnodeURL ()
116- if err != nil {
117- return nil , fmt .Errorf ("Unable to obtain bootnode: %v" , err )
117+ var enodes []string
118+ if bootClients != nil && len (bootClients ) > 0 {
119+ enodes = make ([]string , len (bootClients ))
120+ for i , bootClient := range bootClients {
121+ enodes [i ], err = bootClient .EnodeURL ()
122+ if err != nil {
123+ return nil , fmt .Errorf ("Unable to obtain bootnode: %v" , err )
124+ }
118125 }
119126 }
120127
@@ -138,7 +145,7 @@ func (s GethNodeEngineStarter) StartGethNode(T *hivesim.T, testContext context.C
138145 s .Config .TerminalBlockSiblingDepth = DefaultTerminalBlockSiblingDepth
139146 }
140147
141- g , err := newNode (s .Config , bootnode , & genesis )
148+ g , err := newNode (s .Config , enodes , & genesis )
142149 if err != nil {
143150 return nil , err
144151 }
@@ -166,7 +173,6 @@ type GethNode struct {
166173 mustHeadBlock * types.Block
167174
168175 datadir string
169- bootnode string
170176 genesis * core.Genesis
171177 ttd * big.Int
172178 api * ethcatalyst.ConsensusAPI
@@ -190,14 +196,14 @@ type GethNode struct {
190196 config GethNodeTestConfiguration
191197}
192198
193- func newNode (config GethNodeTestConfiguration , bootnode string , genesis * core.Genesis ) (* GethNode , error ) {
199+ func newNode (config GethNodeTestConfiguration , bootnodes [] string , genesis * core.Genesis ) (* GethNode , error ) {
194200 // Define the basic configurations for the Ethereum node
195201 datadir , _ := os .MkdirTemp ("" , "" )
196202
197- return restart (config , bootnode , datadir , genesis )
203+ return restart (config , bootnodes , datadir , genesis )
198204}
199205
200- func restart (startConfig GethNodeTestConfiguration , bootnode , datadir string , genesis * core.Genesis ) (* GethNode , error ) {
206+ func restart (startConfig GethNodeTestConfiguration , bootnodes [] string , datadir string , genesis * core.Genesis ) (* GethNode , error ) {
201207 if startConfig .Name == "" {
202208 startConfig .Name = "Modified Geth Module"
203209 }
@@ -247,16 +253,20 @@ func restart(startConfig GethNodeTestConfiguration, bootnode, datadir string, ge
247253 time .Sleep (250 * time .Millisecond )
248254 }
249255 // Connect the node to the bootnode
250- node := enode .MustParse (bootnode )
251- stack .Server ().AddPeer (node )
256+ if bootnodes != nil && len (bootnodes ) > 0 {
257+ for _ , bootnode := range bootnodes {
258+ node := enode .MustParse (bootnode )
259+ stack .Server ().AddTrustedPeer (node )
260+ stack .Server ().AddPeer (node )
261+ }
262+ }
252263
253264 stack .Server ().EnableMsgEvents = true
254265
255266 g := & GethNode {
256267 node : stack ,
257268 eth : ethBackend ,
258269 datadir : datadir ,
259- bootnode : bootnode ,
260270 genesis : genesis ,
261271 ttd : genesis .Config .TerminalTotalDifficulty ,
262272 api : ethcatalyst .NewConsensusAPI (ethBackend ),
@@ -392,6 +402,14 @@ func (n *GethNode) PoWMiningLoop() {
392402 // Wait until the previous block is succesfully propagated
393403 <- time .After (time .Millisecond * 200 )
394404
405+ // Modify the block before sealing
406+ if n .config .BlockModifier != nil {
407+ b , err = n .config .BlockModifier .ModifyUnsealedBlock (b )
408+ if err != nil {
409+ panic (err )
410+ }
411+ }
412+
395413 // Seal the next block to broadcast
396414 rChan := make (chan * types.Block , 0 )
397415 stopChan := make (chan struct {})
@@ -401,8 +419,21 @@ func (n *GethNode) PoWMiningLoop() {
401419 if b == nil {
402420 panic (fmt .Errorf ("no block got sealed" ))
403421 }
422+ // Modify the sealed block if necessary
423+ if n .config .BlockModifier != nil {
424+ sealVerifier := func (h * types.Header ) bool {
425+ return n .powEngine .VerifyHeader (n .eth .BlockChain (), h , true ) == nil
426+ }
427+ b , err = n .config .BlockModifier .ModifySealedBlock (sealVerifier , b )
428+ if err != nil {
429+ panic (err )
430+ }
431+ }
432+
404433 // Broadcast
405- n .eth .EventMux ().Post (core.NewMinedBlockEvent {Block : b })
434+ if ! n .config .DisableGossiping {
435+ n .eth .EventMux ().Post (core.NewMinedBlockEvent {Block : b })
436+ }
406437
407438 // Check whether the block was a terminal block
408439 if t , td , err := n .isBlockTerminal (b ); err == nil {
0 commit comments