@@ -111,6 +111,18 @@ func (c *Conn) read66() (uint64, Message) {
111
111
msg = new (Transactions )
112
112
case (NewPooledTransactionHashes {}).Code ():
113
113
msg = new (NewPooledTransactionHashes )
114
+ case (GetPooledTransactions {}.Code ()):
115
+ ethMsg := new (eth.GetPooledTransactionsPacket66 )
116
+ if err := rlp .DecodeBytes (rawData , ethMsg ); err != nil {
117
+ return 0 , errorf ("could not rlp decode message: %v" , err )
118
+ }
119
+ return ethMsg .RequestId , GetPooledTransactions (ethMsg .GetPooledTransactionsPacket )
120
+ case (PooledTransactions {}.Code ()):
121
+ ethMsg := new (eth.PooledTransactionsPacket66 )
122
+ if err := rlp .DecodeBytes (rawData , ethMsg ); err != nil {
123
+ return 0 , errorf ("could not rlp decode message: %v" , err )
124
+ }
125
+ return ethMsg .RequestId , PooledTransactions (ethMsg .PooledTransactionsPacket )
114
126
default :
115
127
msg = errorf ("invalid message code: %d" , code )
116
128
}
@@ -124,6 +136,15 @@ func (c *Conn) read66() (uint64, Message) {
124
136
return 0 , errorf ("invalid message: %s" , string (rawData ))
125
137
}
126
138
139
+ func (c * Conn ) waitForResponse (chain * Chain , timeout time.Duration , requestID uint64 ) Message {
140
+ for {
141
+ id , msg := c .readAndServe66 (chain , timeout )
142
+ if id == requestID {
143
+ return msg
144
+ }
145
+ }
146
+ }
147
+
127
148
// ReadAndServe serves GetBlockHeaders requests while waiting
128
149
// on another message from the node.
129
150
func (c * Conn ) readAndServe66 (chain * Chain , timeout time.Duration ) (uint64 , Message ) {
@@ -173,27 +194,33 @@ func (s *Suite) testAnnounce66(t *utesting.T, sendConn, receiveConn *Conn, block
173
194
}
174
195
175
196
func (s * Suite ) waitAnnounce66 (t * utesting.T , conn * Conn , blockAnnouncement * NewBlock ) {
176
- timeout := 20 * time .Second
177
- _ , msg := conn .readAndServe66 (s .chain , timeout )
178
- switch msg := msg .(type ) {
179
- case * NewBlock :
180
- t .Logf ("received NewBlock message: %s" , pretty .Sdump (msg .Block ))
181
- assert .Equal (t ,
182
- blockAnnouncement .Block .Header (), msg .Block .Header (),
183
- "wrong block header in announcement" ,
184
- )
185
- assert .Equal (t ,
186
- blockAnnouncement .TD , msg .TD ,
187
- "wrong TD in announcement" ,
188
- )
189
- case * NewBlockHashes :
190
- blockHashes := * msg
191
- t .Logf ("received NewBlockHashes message: %s" , pretty .Sdump (blockHashes ))
192
- assert .Equal (t , blockAnnouncement .Block .Hash (), blockHashes [0 ].Hash ,
193
- "wrong block hash in announcement" ,
194
- )
195
- default :
196
- t .Fatalf ("unexpected: %s" , pretty .Sdump (msg ))
197
+ for {
198
+ _ , msg := conn .readAndServe66 (s .chain , timeout )
199
+ switch msg := msg .(type ) {
200
+ case * NewBlock :
201
+ t .Logf ("received NewBlock message: %s" , pretty .Sdump (msg .Block ))
202
+ assert .Equal (t ,
203
+ blockAnnouncement .Block .Header (), msg .Block .Header (),
204
+ "wrong block header in announcement" ,
205
+ )
206
+ assert .Equal (t ,
207
+ blockAnnouncement .TD , msg .TD ,
208
+ "wrong TD in announcement" ,
209
+ )
210
+ return
211
+ case * NewBlockHashes :
212
+ blockHashes := * msg
213
+ t .Logf ("received NewBlockHashes message: %s" , pretty .Sdump (blockHashes ))
214
+ assert .Equal (t , blockAnnouncement .Block .Hash (), blockHashes [0 ].Hash ,
215
+ "wrong block hash in announcement" ,
216
+ )
217
+ return
218
+ case * NewPooledTransactionHashes :
219
+ // ignore old txs being propagated
220
+ continue
221
+ default :
222
+ t .Fatalf ("unexpected: %s" , pretty .Sdump (msg ))
223
+ }
197
224
}
198
225
}
199
226
@@ -268,3 +295,24 @@ func headersMatch(t *utesting.T, chain *Chain, headers BlockHeaders) {
268
295
assert .Equal (t , chain .blocks [int (num )].Header (), header )
269
296
}
270
297
}
298
+
299
+ func (s * Suite ) sendNextBlock66 (t * utesting.T ) {
300
+ sendConn , receiveConn := s .setupConnection66 (t ), s .setupConnection66 (t )
301
+ defer sendConn .Close ()
302
+ defer receiveConn .Close ()
303
+
304
+ // create new block announcement
305
+ nextBlock := len (s .chain .blocks )
306
+ blockAnnouncement := & NewBlock {
307
+ Block : s .fullChain .blocks [nextBlock ],
308
+ TD : s .fullChain .TD (nextBlock + 1 ),
309
+ }
310
+ // send announcement and wait for node to request the header
311
+ s .testAnnounce66 (t , sendConn , receiveConn , blockAnnouncement )
312
+ // update test suite chain
313
+ s .chain .blocks = append (s .chain .blocks , s .fullChain .blocks [nextBlock ])
314
+ // wait for client to update its chain
315
+ if err := receiveConn .waitForBlock66 (s .chain .Head ()); err != nil {
316
+ t .Fatal (err )
317
+ }
318
+ }
0 commit comments