-
Notifications
You must be signed in to change notification settings - Fork 42
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
improve payment sync #1099
improve payment sync #1099
Conversation
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.
LGTM
)?; | ||
let mut send_pays = Vec::new(); | ||
for hash in hashes { | ||
for hash_group in hash_groups { |
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.
I think we can use IN filter expression to get all these in one shot but this is also good for now. Only the first will probably end with lots of queries.
}) | ||
.await? | ||
.into_inner(); | ||
let updated_invoices = updated_invoices_res?.into_inner(); | ||
if let Some(last) = updated_invoices.invoices.last() { | ||
new_sync_state.list_invoices_index.updated = last.created_index() |
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.
Looking at the CLN API for listinvoices there is also an updated_index
. Just want to confirm created_index
is correct.
} | ||
let updated_send_pays = updated_send_pays_res?.into_inner(); | ||
if let Some(last) = updated_send_pays.payments.last() { | ||
new_sync_state.send_pays_index.updated = last.created_index() |
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.
Same here with the updated_index/created_index
0 => Ok(Self::Pending), | ||
1 => Ok(Self::Failed), | ||
2 => Ok(Self::Complete), | ||
_ => Err(NodeError::generic("invalid send_pay status")), |
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.
_ => Err(NodeError::generic("invalid send_pay status")), | |
_ => Err(NodeError::generic("Invalid send_pay status")), |
Ok(SendPay { | ||
created_index: value | ||
.created_index | ||
.ok_or(NodeError::generic("missing created index"))?, |
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.
.ok_or(NodeError::generic("missing created index"))?, | |
.ok_or(NodeError::generic("Missing created index"))?, |
let status = if value.state & 2 > 0 { | ||
PaymentStatus::Complete | ||
} else if value.state & 1 > 0 { | ||
PaymentStatus::Pending | ||
} else { | ||
PaymentStatus::Failed | ||
}; |
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.
I'm not sure this works. From https://github.com/breez/breez-sdk-greenlight/pull/1095/files#diff-7466a53546c6cded460ef5502a9168b13cc930d94fdf7d0ea8166bb10c75fe7eR843-R858, here are the cases:
send_pay.status
==Pending
(0) =>SendPayAgg.state
= 0 + 1 = 1send_pay.status
==Complete
(1) =>SendPayAgg.state
= 0 + 2 = 2send_pay.status
==Failed
(2) =>SendPayAgg.state
= 0 + 4 = 4
When we go ahead and decode the state, we get:
SendPayAgg.state
== 1 => 1 & 2 (=0), 1 & 1 = 1 =>Pending
OKSendPayAgg.state
== 2 => 2 & 2 (=2) =>Complete
OKSendPayAgg.state
== 4 => 4 & 2 (=0), 4 & 1 (=0) =>Failed
OK
Edit: Double-checked. Everything seems fine 👍
c453a72
to
47548b7
Compare
Discussed with @hydra-yse the amount was not initialized, that's why the amounts were 0. Thanks for catching that @hydra-yse! |
417fbf9
to
185df2f
Compare
- request all payments and invoices at the same time - only query used payment groups from the db
Now sync only fetches the latest payments, don't delete pending payments from the database. They will be updated by payment syc automagically.
This fixes races between fetching updated and created. There was also a bug where the 'updated' index would be set to the 'created' index accidentally.
185df2f
to
2d01527
Compare
Hopefully fixes breez/c-breez#909