Skip to content

tapfreighter: fix OutboundParcel.Copy and add generic Copy fn test #1580

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

Merged
merged 2 commits into from
Jun 3, 2025

Conversation

bhandras
Copy link
Member

@bhandras bhandras commented Jun 2, 2025

The main goal of this commit is to give us a tool to be able to catch regressions when extending a copyable struct. We also fix OutboundParcel.Copy() along the way.

@bhandras bhandras force-pushed the copy-fixes branch 3 times, most recently from 3b02cbd to 97c5026 Compare June 2, 2025 14:14
@bhandras bhandras requested a review from guggero June 2, 2025 14:25
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 and test!
Just one comment about the commitment version, the rest is non-blocking.

copy_test.go Outdated
)

// FillFakeData recursively fills a struct with dummy values.
func FillFakeData[T any](t *testing.T, debug bool, maxDepth int, v T) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: should we move these helper functions to the internal/test package? Then we can more easily re-use them in other places. And the copy test could actually be in the tapfreighter test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, done!

copy_test.go Outdated
// CopyFnTest checks that the Copy method returns a value that:
// 1) is deeply equal
// 2) does not alias mutable fields (pointers, slices, maps)
func CopyFnTest[T fn.Copyable[T]](t *testing.T, debug, strict bool,
Copy link
Member

Choose a reason for hiding this comment

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

nit: rename to AssertCopyEqual() or something like that? Was initially not very clear to me what this function really does, at least from its name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

copy_test.go Outdated
}

// fillFakeData is the recursive helper to fill a value with fake data.
func fillFakeData(t *testing.T, debug bool, depth, maxDepth int,
Copy link
Member

Choose a reason for hiding this comment

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

Very nice! I wish the fuzz library exposed some of their helpers that are used to generate such random values. But nice to have such a compact version we can use here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, ideally something similar should be in the standard library.

Inputs: fn.CopySlice(o.Inputs),
Outputs: fn.CopySlice(o.Outputs),
Label: o.Label,
SkipAnchorTxBroadcast: o.SkipAnchorTxBroadcast,
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Member Author

Choose a reason for hiding this comment

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

The initial bug that i found was that subscribing to send events did not correctly fill the confirmation height upon finished transfer.

TaprootAssetRoot: fn.CopySlice(
oldAnchor.TaprootAssetRoot,
),
CommitmentVersion: &commitmentVersion,
Copy link
Member

Choose a reason for hiding this comment

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

This should remain nil (instead of becoming a pointer to a 0 value) if the original is nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, indeed! Done.

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, LGTM 🎉

@bhandras bhandras enabled auto-merge June 3, 2025 16:54
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

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

LGTM! ©️

@bhandras bhandras added this pull request to the merge queue Jun 3, 2025
Merged via the queue into lightninglabs:main with commit f76d926 Jun 3, 2025
18 checks passed
@bhandras bhandras deleted the copy-fixes branch June 3, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants