@@ -29,29 +29,37 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
29
29
Pair (state, listOf ())
30
30
}
31
31
is WaitForFundingSigned -> {
32
- when (cmd.message.nextFundingTxId) {
33
- // We retransmit our commit_sig, and will send our tx_signatures once we've received their commit_sig.
34
- state.signingSession.fundingTx.txId -> {
32
+ val actions = buildList {
33
+ if (cmd.message.nextFundingTxId == state.signingSession.fundingTx.txId && cmd.message.nextLocalCommitmentNumber == 0L ) {
34
+ // They haven't received our commit_sig: we retransmit it, and will send our tx_signatures once we've received
35
+ // their commit_sig or their tx_signatures (depending on who must send tx_signatures first).
36
+ logger.info { " re-sending commit_sig for channel creation with fundingTxId=${state.signingSession.fundingTx.txId} " }
35
37
val commitSig = state.signingSession.remoteCommit.sign(channelKeys(), state.channelParams, state.signingSession)
36
- Pair (state, listOf ( ChannelAction .Message .Send (commitSig) ))
38
+ add( ChannelAction .Message .Send (commitSig))
37
39
}
38
- else -> Pair (state, listOf ())
39
40
}
41
+ Pair (state, actions)
40
42
}
41
43
is WaitForFundingConfirmed -> {
42
44
when (cmd.message.nextFundingTxId) {
43
45
null -> Pair (state, listOf ())
44
46
else -> {
45
47
if (state.rbfStatus is RbfStatus .WaitingForSigs && state.rbfStatus.session.fundingTx.txId == cmd.message.nextFundingTxId) {
46
- // We retransmit our commit_sig, and will send our tx_signatures once we've received their commit_sig.
47
- logger.info { " re-sending commit_sig for rbf attempt with fundingTxId=${cmd.message.nextFundingTxId} " }
48
- val commitSig = state.rbfStatus.session.remoteCommit.sign(channelKeys(), state.commitments.params, state.rbfStatus.session)
49
- val actions = listOf (ChannelAction .Message .Send (commitSig))
48
+ val actions = buildList {
49
+ if (cmd.message.nextLocalCommitmentNumber == 0L ) {
50
+ // They haven't received our commit_sig: we retransmit it.
51
+ // We're waiting for signatures from them, and will send our tx_signatures once we receive them.
52
+ logger.info { " re-sending commit_sig for rbf attempt with fundingTxId=${cmd.message.nextFundingTxId} " }
53
+ val commitSig = state.rbfStatus.session.remoteCommit.sign(channelKeys(), state.commitments.params, state.rbfStatus.session)
54
+ add(ChannelAction .Message .Send (commitSig))
55
+ }
56
+ }
50
57
Pair (state, actions)
51
58
} else if (state.latestFundingTx.txId == cmd.message.nextFundingTxId) {
59
+ // We've already received their commit_sig and sent our tx_signatures. We retransmit our tx_signatures
60
+ // and our commit_sig if they haven't received it already.
52
61
val actions = buildList {
53
- if (state.latestFundingTx.sharedTx is PartiallySignedSharedTransaction ) {
54
- // We have not received their tx_signatures: we retransmit our commit_sig because we don't know if they received it.
62
+ if (cmd.message.nextLocalCommitmentNumber == 0L ) {
55
63
logger.info { " re-sending commit_sig for fundingTxId=${cmd.message.nextFundingTxId} " }
56
64
val commitSig = state.commitments.latest.remoteCommit.sign(
57
65
channelKeys(),
@@ -77,11 +85,11 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
77
85
}
78
86
is WaitForChannelReady -> {
79
87
val actions = ArrayList <ChannelAction >()
80
-
88
+ // We've already received their commit_sig and sent our tx_signatures. We retransmit our tx_signatures
89
+ // and our commit_sig if they haven't received it already.
81
90
if (state.commitments.latest.fundingTxId == cmd.message.nextFundingTxId) {
82
91
if (state.commitments.latest.localFundingStatus is LocalFundingStatus .UnconfirmedFundingTx ) {
83
- if (state.commitments.latest.localFundingStatus.sharedTx is PartiallySignedSharedTransaction ) {
84
- // If we have not received their tx_signatures, we can't tell whether they had received our commit_sig, so we need to retransmit it
92
+ if (cmd.message.nextLocalCommitmentNumber == 0L ) {
85
93
logger.info { " re-sending commit_sig for fundingTxId=${state.commitments.latest.fundingTxId} " }
86
94
val commitSig = state.commitments.latest.remoteCommit.sign(
87
95
channelKeys(),
@@ -101,12 +109,10 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
101
109
logger.warning { " cannot re-send tx_signatures for fundingTxId=${cmd.message.nextFundingTxId} , transaction is already confirmed" }
102
110
}
103
111
}
104
-
105
112
logger.debug { " re-sending channel_ready" }
106
113
val nextPerCommitmentPoint = channelKeys().commitmentPoint(1 )
107
114
val channelReady = ChannelReady (state.commitments.channelId, nextPerCommitmentPoint)
108
115
actions.add(ChannelAction .Message .Send (channelReady))
109
-
110
116
Pair (state, actions)
111
117
}
112
118
is LegacyWaitForFundingLocked -> {
@@ -134,16 +140,20 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
134
140
135
141
// resume splice signing session if any
136
142
val spliceStatus1 = if (state.spliceStatus is SpliceStatus .WaitingForSigs && state.spliceStatus.session.fundingTx.txId == cmd.message.nextFundingTxId) {
137
- // We retransmit our commit_sig, and will send our tx_signatures once we've received their commit_sig.
138
- logger.info { " re-sending commit_sig for splice attempt with fundingTxIndex=${state.spliceStatus.session.fundingTxIndex} fundingTxId=${state.spliceStatus.session.fundingTx.txId} " }
139
- val commitSig = state.spliceStatus.session.remoteCommit.sign(channelKeys(), state.commitments.params, state.spliceStatus.session)
140
- actions.add(ChannelAction .Message .Send (commitSig))
143
+ if (cmd.message.nextLocalCommitmentNumber == state.commitments.remoteCommitIndex) {
144
+ // They haven't received our commit_sig: we retransmit it.
145
+ // We're waiting for signatures from them, and will send our tx_signatures once we receive them.
146
+ logger.info { " re-sending commit_sig for splice attempt with fundingTxIndex=${state.spliceStatus.session.fundingTxIndex} fundingTxId=${state.spliceStatus.session.fundingTx.txId} " }
147
+ val commitSig = state.spliceStatus.session.remoteCommit.sign(channelKeys(), state.commitments.params, state.spliceStatus.session)
148
+ actions.add(ChannelAction .Message .Send (commitSig))
149
+ }
141
150
state.spliceStatus
142
151
} else if (state.commitments.latest.fundingTxId == cmd.message.nextFundingTxId) {
143
152
when (val localFundingStatus = state.commitments.latest.localFundingStatus) {
144
153
is LocalFundingStatus .UnconfirmedFundingTx -> {
145
- if (localFundingStatus.sharedTx is PartiallySignedSharedTransaction ) {
146
- // If we have not received their tx_signatures, we can't tell whether they had received our commit_sig, so we need to retransmit it
154
+ // We've already received their commit_sig and sent our tx_signatures. We retransmit our tx_signatures
155
+ // and our commit_sig if they haven't received it already.
156
+ if (cmd.message.nextLocalCommitmentNumber == state.commitments.remoteCommitIndex) {
147
157
logger.info { " re-sending commit_sig for fundingTxIndex=${state.commitments.latest.fundingTxIndex} fundingTxId=${state.commitments.latest.fundingTxId} " }
148
158
val commitSig = state.commitments.latest.remoteCommit.sign(
149
159
channelKeys(),
0 commit comments