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