@@ -181,17 +181,17 @@ impl IHandshakeState for ResponderAwaitingActOneState {
181
181
// https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md#act-two (sender)
182
182
fn next ( self , input : & [ u8 ] ) -> Result < ( Option < Act > , HandshakeState ) , String > {
183
183
let mut act_one_builder = self . act_one_builder ;
184
- let remaining = act_one_builder. fill ( input) ;
184
+ let bytes_read = act_one_builder. fill ( input) ;
185
185
186
- // Any payload larger than ACT_ONE_LENGTH indicates a bad peer since initiator data
187
- // is required to generate act3 (so it can't come before we transition)
188
- if remaining . len ( ) != 0 {
186
+ // Any payload that is not fully consumed by the builder indicates a bad peer since responder
187
+ // data is required to generate act3 (so it can't come before we transition)
188
+ if bytes_read < input . len ( ) {
189
189
return Err ( "Act One too large" . to_string ( ) ) ;
190
190
}
191
191
192
192
// In the event of a partial fill, stay in the same state and wait for more data
193
193
if !act_one_builder. is_finished ( ) {
194
- assert_eq ! ( remaining . len( ) , 0 ) ;
194
+ assert_eq ! ( bytes_read , input . len( ) ) ;
195
195
return Ok ( (
196
196
None ,
197
197
HandshakeState :: ResponderAwaitingActOne ( Self {
@@ -247,17 +247,17 @@ impl IHandshakeState for InitiatorAwaitingActTwoState {
247
247
// https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md#act-three (sender)
248
248
fn next ( self , input : & [ u8 ] ) -> Result < ( Option < Act > , HandshakeState ) , String > {
249
249
let mut act_two_builder = self . act_two_builder ;
250
- let remaining = act_two_builder. fill ( input) ;
250
+ let bytes_read = act_two_builder. fill ( input) ;
251
251
252
- // Any payload larger than ACT_TWO_LENGTH indicates a bad peer since responder data
252
+ // Any payload that is not fully consumed by the builder indicates a bad peer since responder data
253
253
// is required to generate post-authentication messages (so it can't come before we transition)
254
- if remaining . len ( ) != 0 {
254
+ if bytes_read < input . len ( ) {
255
255
return Err ( "Act Two too large" . to_string ( ) ) ;
256
256
}
257
257
258
258
// In the event of a partial fill, stay in the same state and wait for more data
259
259
if !act_two_builder. is_finished ( ) {
260
- assert_eq ! ( remaining . len( ) , 0 ) ;
260
+ assert_eq ! ( bytes_read , input . len( ) ) ;
261
261
return Ok ( (
262
262
None ,
263
263
HandshakeState :: InitiatorAwaitingActTwo ( Self {
@@ -325,11 +325,11 @@ impl IHandshakeState for ResponderAwaitingActThreeState {
325
325
// https://github.com/lightningnetwork/lightning-rfc/blob/master/08-transport.md#act-three (receiver)
326
326
fn next ( self , input : & [ u8 ] ) -> Result < ( Option < Act > , HandshakeState ) , String > {
327
327
let mut act_three_builder = self . act_three_builder ;
328
- let remaining = act_three_builder. fill ( input) ;
328
+ let bytes_read = act_three_builder. fill ( input) ;
329
329
330
330
// In the event of a partial fill, stay in the same state and wait for more data
331
331
if !act_three_builder. is_finished ( ) {
332
- assert_eq ! ( remaining . len( ) , 0 ) ;
332
+ assert_eq ! ( bytes_read , input . len( ) ) ;
333
333
return Ok ( (
334
334
None ,
335
335
HandshakeState :: ResponderAwaitingActThree ( Self {
@@ -392,7 +392,7 @@ impl IHandshakeState for ResponderAwaitingActThreeState {
392
392
393
393
// Any remaining data in the read buffer would be encrypted, so transfer ownership
394
394
// to the Conduit for future use.
395
- conduit. read ( remaining ) ;
395
+ conduit. read ( & input [ bytes_read.. ] ) ;
396
396
397
397
Ok ( (
398
398
None ,
0 commit comments