@@ -199,7 +199,7 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
199
199
}
200
200
201
201
// we may need to retransmit updates and/or commit_sig and/or revocation
202
- actions.addAll(syncResult.retransmit.map { ChannelAction . Message . Send (it) } )
202
+ actions.addAll(syncResult.retransmit)
203
203
204
204
// then we clean up unsigned updates
205
205
val commitments1 = discardUnsignedUpdates(state.commitments)
@@ -231,8 +231,8 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
231
231
val commitments1 = discardUnsignedUpdates(state.commitments)
232
232
val actions = buildList {
233
233
addAll(syncResult.retransmit)
234
- add(state.localShutdown)
235
- }.map { ChannelAction . Message . Send (it) }
234
+ add(ChannelAction . Message . Send ( state.localShutdown) )
235
+ }
236
236
Pair (state.copy(commitments = commitments1), actions)
237
237
}
238
238
}
@@ -379,7 +379,7 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
379
379
380
380
// @formatter:off
381
381
sealed class SyncResult {
382
- data class Success (val retransmit : List <LightningMessage >) : SyncResult()
382
+ data class Success (val retransmit : List <ChannelAction . Message >) : SyncResult()
383
383
sealed class Failure : SyncResult () {
384
384
data class LocalLateProven (val ourLocalCommitmentNumber : Long , val theirRemoteCommitmentNumber : Long ) : Failure()
385
385
data class LocalLateUnproven (val ourRemoteCommitmentNumber : Long , val theirLocalCommitmentNumber : Long ) : Failure()
@@ -400,31 +400,32 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
400
400
// step 2 depends on step 1 because we need to preserve ordering between commit_sig and revocation
401
401
402
402
// step 2: we check the remote commitment
403
- fun checkRemoteCommit (remoteChannelReestablish : ChannelReestablish , retransmitRevocation : RevokeAndAck ? ): SyncResult {
403
+ fun checkRemoteCommit (remoteChannelReestablish : ChannelReestablish , revocation : RevokeAndAck ? ): SyncResult {
404
+ val retransmitRevocation = revocation?.let { ChannelAction .Message .Send (it) }
404
405
return when (val rnci = commitments.remoteNextCommitInfo) {
405
406
is Either .Left -> {
406
407
when {
407
408
remoteChannelReestablish.nextLocalCommitmentNumber == commitments.nextRemoteCommitIndex -> {
408
409
// we just sent a new commit_sig but they didn't receive it
409
410
// we resend the same updates and the same sig, and preserve the same ordering
410
- val signedUpdates = commitments.changes.localChanges.signed
411
- val commitSigs = commitments.active.map { it.nextRemoteCommit }.filterIsInstance< NextRemoteCommit >(). map { it.sig }
411
+ val signedUpdates = commitments.changes.localChanges.signed.map { ChannelAction . Message . Send (it) }
412
+ val commitSigs = ChannelAction . Message . SendBatch ( commitments.active.mapNotNull { it.nextRemoteCommit }.map { it.sig })
412
413
val retransmit = when (retransmitRevocation) {
413
414
null -> buildList {
414
415
addAll(signedUpdates)
415
- addAll (commitSigs)
416
+ add (commitSigs)
416
417
}
417
418
else -> if (commitments.localCommitIndex > rnci.value.sentAfterLocalCommitIndex) {
418
419
buildList {
419
420
addAll(signedUpdates)
420
- addAll (commitSigs)
421
+ add (commitSigs)
421
422
add(retransmitRevocation)
422
423
}
423
424
} else {
424
425
buildList {
425
426
add(retransmitRevocation)
426
427
addAll(signedUpdates)
427
- addAll (commitSigs)
428
+ add (commitSigs)
428
429
}
429
430
}
430
431
}
@@ -477,7 +478,7 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
477
478
// step 1: we check our local commitment
478
479
return if (commitments.localCommitIndex == remoteChannelReestablish.nextRemoteRevocationNumber) {
479
480
// our local commitment is in sync, let's check the remote commitment
480
- checkRemoteCommit(remoteChannelReestablish, retransmitRevocation = null )
481
+ checkRemoteCommit(remoteChannelReestablish, revocation = null )
481
482
} else if (commitments.localCommitIndex == remoteChannelReestablish.nextRemoteRevocationNumber + 1 ) {
482
483
// they just sent a new commit_sig, we have received it but they didn't receive our revocation
483
484
val localPerCommitmentSecret = channelKeys.commitmentSecret(commitments.localCommitIndex - 1 )
@@ -487,7 +488,7 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
487
488
perCommitmentSecret = localPerCommitmentSecret,
488
489
nextPerCommitmentPoint = localNextPerCommitmentPoint
489
490
)
490
- checkRemoteCommit(remoteChannelReestablish, retransmitRevocation = revocation)
491
+ checkRemoteCommit(remoteChannelReestablish, revocation)
491
492
} else if (commitments.localCommitIndex > remoteChannelReestablish.nextRemoteRevocationNumber + 1 ) {
492
493
SyncResult .Failure .RemoteLate
493
494
} else {
0 commit comments