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

Store transfer output proof delivery status #1035

Merged
merged 7 commits into from
Jul 29, 2024

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Jul 19, 2024

Summary

This PR is work towards fixing #1009 (making the proof transfer process more robust).

This pull request adds a new proof_deliver_complete column to the asset_transfer_outputs table. It includes updates to the table schema, modifications to SQL statements, and adjustments to unit tests. Additionally, it integrates changes to the tapfreighter component for logging proof delivery confirmations.

Changes

  1. Schema Update:

    • Added the proof_deliver_complete column to the asset_transfer_outputs table.
  2. SQL Statement Modifications:

    • Updated the row insertion and retrieval SQL statements to include the proof_deliver_complete column.
    • Added a new SQL statement specifically for modifying the proof_deliver_complete column.
  3. Field Population:

    • Set the proof_deliver_complete field for new transfer output rows.
    • Ensured the proof_deliver_complete field is populated when reading from the database.
  4. Proof Delivery Logging:

    • Added a ConfirmProofDelivery method to the tapfreighter export log.
    • The ConfirmProofDelivery function is called after a proof has been successfully delivered to a remote peer.
  5. Unit Test Adjustment:

    • Modified a unit test to verify that a transfer output proof is correctly flagged as confirmed.

@ffranr ffranr requested review from jharveyb and GeorgeTsagk July 19, 2024 10:06
@ffranr ffranr self-assigned this Jul 19, 2024
@ffranr ffranr added the proofs label Jul 19, 2024
@dstadulis dstadulis added this to the v0.4.1 milestone Jul 19, 2024
@dstadulis dstadulis added documentation Improvements or additions to documentation database testing logging unit-test labels Jul 19, 2024
@ffranr ffranr requested review from guggero and removed request for GeorgeTsagk July 23, 2024 11:02
Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

Looks good overall!

AFAICT this is missing the reordering of when proof delivery occurs mentioned here:

#1009 (comment)

Is that intended for a follow-up PR?

tapdb/sqlc/queries/transfers.sql Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
@ffranr
Copy link
Contributor Author

ffranr commented Jul 24, 2024

Looks good overall!

AFAICT this is missing the reordering of when proof delivery occurs mentioned here:

#1009 (comment)

Is that intended for a follow-up PR?

@jharveyb Thanks for the review. Yes, will definitely get done. I was thinking in a follow up PR.

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice approach!
Makes sense to me but I think the current implementation on the SQL level is a bit brittle and will likely lead to issues down the line.
Added a suggestion in there that should solve it in a nice way (and with probably a smaller diff too).

tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/sqlc/queries/transfers.sql Outdated Show resolved Hide resolved
@ffranr ffranr force-pushed the store-proof-delivery-status branch from f11dc88 to 696261d Compare July 25, 2024 16:18
@ffranr ffranr requested a review from guggero July 25, 2024 16:18
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Very happy with the SQL part, should make things more reliable.
Almost there on the rest!

tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
ffranr added 7 commits July 26, 2024 19:38
Add the `proof_delivery_complete` and `position` columns to the
`asset_transfer_outputs` table. The `position` column indicates the
position of the output in the transfer output list.

The position and anchor outpoint uniquely identify a transfer output.

This change updates the row insertion and retrieval SQL statements for
this table. Additionally, new SQL statements are included for modifying
these new columns.
ShouldDeliverProof returns true if a proof corresponding to the subject
transfer output should be delivered to a peer.
Set and retrieve the `proof_delivery_complete` and
`position` columns from the `asset_transfer_outputs` table.
Refactors the `transferReceiverProof` method in `ChainPorter` by
utilizing the new `ShouldDeliverProof` method for transfer output. This
change simplifies the method's implementation. Note: This refactoring is
not related to the primary objectives of this series of commits.
Add a `ConfirmProofDelivery` method to the export log. This function is
called after a proof has been successfully delivered to a remote peer.
This commit introduces a unit test for the
`SetTransferOutputProofDeliveryStatus` functionality to ensure proof
delivery confirmation.
@ffranr ffranr force-pushed the store-proof-delivery-status branch from 696261d to 25f0aba Compare July 26, 2024 22:42
@ffranr ffranr requested review from guggero and jharveyb July 26, 2024 23:15
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Very nice, LGTM 🚀

Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

Looks good overall! The newer version is definitely a smaller / simpler diff. Just one note on the position type itself.

tapfreighter/chain_porter.go Show resolved Hide resolved

// Check if position value can be stored in a 32-bit integer. Type cast
// if possible, otherwise return an error.
if output.Position > math.MaxInt32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

See note elsewhere re: switching to int64.

@ffranr ffranr added this pull request to the merge queue Jul 29, 2024
ADD COLUMN proof_delivery_complete BOOL;

-- Add column `position` which indicates the index of the output in the list of
-- outputs for a given transfer. This index position in conjunction with the
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we just use the existing primary key for this?


// If this is an output that is going to our own node/wallet, we don't
// need to deliver a proof.
if out.ScriptKey.TweakedScriptKey != nil && out.ScriptKeyLocal {
Copy link
Member

Choose a reason for hiding this comment

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

We should double check this with some of the litd itests we have for channels. At times, we verify that a proof was uploaded even if it was a local script key.


// If the script key is a burn key, we don't need to deliver a proof.
if len(out.WitnessData) > 0 && asset.IsBurnKey(
out.ScriptKey.PubKey, out.WitnessData[0],
Copy link
Member

Choose a reason for hiding this comment

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

Aren't burns still relevant? So to proof to someone that you've burnt an asset.


// Burns are also always kept local and not sent to any
// receiver.
if len(out.WitnessData) > 0 && asset.IsBurnKey(
Copy link
Member

Choose a reason for hiding this comment

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

Ah I see this was also just existing behavior, feel free to ignore those other comments.

Merged via the queue into lightninglabs:main with commit 4925c31 Jul 29, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

5 participants