Skip to content
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

Persist SendPay.groupid as TEXT to cover full u64 range #1124

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

ok300
Copy link
Contributor

@ok300 ok300 commented Nov 15, 2024

Restoring a node kept panicking with a ToSqlConversionFailure(TryFromIntError(())) error. Turns out this was caused by how we persist SendPay.groupid.

In cln_grpc this field is defined as uint64 and deserialized as u64:

https://github.com/ElementsProject/lightning/blob/e66653fa1d847e28bd812356a762225a44bfae83/cln-grpc/proto/node.proto#L935

However we map it to an INTEGER in the DB, which actually accepts signed 64 bit numbers. If we try to persist positive integers that use the 64th bit, inserting it into SQL will fail with ToSqlConversionFailure(TryFromIntError(())).

This is exactly what caused restore to fail in my case, as I had several groupids bigger than 2^63.

This PR fixes this by converting SendPay.groupid to String and storing it as TEXT. Since we only use it as a String, we don't have to re-convert it back to u64 when deserializing SendPay from the DB.

@JssDWt
Copy link
Contributor

JssDWt commented Nov 15, 2024

This PR fixes this by converting SendPay.groupid to String and storing it as TEXT. Since we only use it as a String, we don't have to re-convert it back to u64 when deserializing SendPay from the DB.

If I understand correctly, you had invalid groupids stored in your send_pays table. If we create the new table and insert everything from the old table, I think the groupids migrated from the old table would still be invalid? Potentially we won't identify multiple parts belonging to the same group correctly during sync because of it.

I think it's best to

  • drop the send_pays table and recreate it with the new schema
  • drop the sync state by removing the sync_state entry from the cache

The sdk will then resync everything.

@ok300
Copy link
Contributor Author

ok300 commented Nov 15, 2024

If I understand correctly, you had invalid groupids stored in your send_pays table.

No, started the CLI with a fresh data directory, so restore only pulled fresh new data.

I think it's best to

  • drop the send_pays table and recreate it with the new schema
  • drop the sync state by removing the sync_state entry from the cache

The sdk will then resync everything.

Done: 7c16a50

Copy link
Contributor

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit, then I'll test

libs/sdk-core/src/persist/migrations.rs Outdated Show resolved Hide resolved
@ok300
Copy link
Contributor Author

ok300 commented Nov 15, 2024

Done.

Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@JssDWt
Copy link
Contributor

JssDWt commented Nov 15, 2024

Tested this on an existing node, and it works.
Thinking about whether we should also clear the payments table as a precaution for potentially invalid updates. It might not be necessary, but it won't do any harm either. What do you think @ok300?

@roeierez
Copy link
Member

Tested this on an existing node, and it works. Thinking about whether we should also clear the payments table as a precaution for potentially invalid updates. It might not be necessary, but it won't do any harm either. What do you think @ok300?

I think it is not necessary because syncing will replace invalid payments.

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ok300 ok300 merged commit 4e488e4 into main Nov 18, 2024
9 checks passed
erdemyerebasmaz pushed a commit that referenced this pull request Nov 26, 2024
* Persist SendPay.groupid as TEXT to cover full u64 range

* Don't keep old send_pays data, force re-sync

* Update libs/sdk-core/src/persist/migrations.rs

Co-authored-by: Jesse de Wit <[email protected]>

---------

Co-authored-by: Jesse de Wit <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants