-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: retransmission for tlc #89
Conversation
Only the messages sent by us need to be resent on connection reestablishment. We don't have to deliberately resend our That is, we may previously send a sequence of events after a
In case 1, assume we don't have message after the But how do we know if we need to resend a What if we still have messages after our
Say the local commitment number for In the case 2, all we need is just pretend to send a commitment transaction. And do not send the actual |
src/ckb/channel.rs
Outdated
ChannelState::ChannelReady() => { | ||
// resend AddTlc, RemoveTlc and CommitmentSigned messages if needed | ||
let local_commitment_number = reestablish_channel.local_commitment_number; | ||
let mut need_resend_commitment_signed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check whether we need to resend a CommitmentSigned
as previous comment.
src/ckb/channel.rs
Outdated
// resend AddTlc, RemoveTlc and CommitmentSigned messages if needed | ||
let local_commitment_number = reestablish_channel.local_commitment_number; | ||
let mut need_resend_commitment_signed = false; | ||
for info in self.tlcs.values() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to repeat all this logic here. https://github.com/nervosnetwork/cfn-node/blob/f9e79b060f7329309eff752b7485bfacc91a629f/src/ckb/channel.rs#L2027 This function may be modified to check whether we need to resend a AddTlc
or SendTlc
. Just exclude all tlcs from previous round.
79c5258
to
ac5399c
Compare
ac5399c
to
87782d5
Compare
// resend AddTlc, RemoveTlc and CommitmentSigned messages if needed | ||
let mut need_resend_commitment_signed = false; | ||
for info in self.tlcs.values() { | ||
if info.is_offered() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have multiple implicit assumptions.
- If a TLC is added by us or a TLC is removed by us then we need to resend a
CommitmentSigned
message. - We only need to resend a single
CommitmentSigned
message (or we only have a single TLC added/removed in this commitment phase). - We only need to resend
AddTlc
orRemoveTlc
messages when the channel is established.
Assumption 1 and assumption 2 are correct in current implementation. Assumption 2 is a direct corollary of assumption 1, but the code here can be a little fragile if we don't know all these assumptions and try to refactor the logic here. Can we add a warning if there are multiple AddTlc
/RemoveTlc
need to be processed?
Assumption 3 is actually wrong. For RemoveTlc
, we may need to transition the state to Shutdown
if both parties agreed to shutdown and this is the last pending TLC to be removed. https://github.com/nervosnetwork/cfn-node/blob/975f25668aff31b54ccad0eaf97a177069367de2/src/ckb/channel.rs#L593
In regard to assumption 3, I think we can create a AddTlc
or RemoveTlc
from the DetailedTlcInfo
, then call handle_add_tlc_command
or handle_remove_tlc_command
, and make sure handle_add_tlc_command
and handle_remove_tlc_command
are always idempotent (note that functions handle_add_tlc_command
and handle_remove_tlc_command
will send CommitmentSigned
, so we don't have to resend CommitmentSigned
here). This way even if code changes, we can keep the the processing logic of RemoveTlc
in channel reestablishment and normal operations in sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to reuse all the code of handle_add_tlc_command
and handle_remove_tlc_command
. The common logic can be extracted to new functions.
No description provided.