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

StaticAddr: fix deposit detection #864

Merged

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Dec 9, 2024

The height hint for deposit confirmations was previously set to the initiation height of the deposit manager, which does not work in case the manager is restarted before a deposit was confirmed.

@hieblmi hieblmi self-assigned this Dec 9, 2024
@hieblmi hieblmi force-pushed the fix-deposit-detection branch from b5cba1f to d8953be Compare December 9, 2024 13:02
@hieblmi hieblmi force-pushed the fix-deposit-detection branch from d8953be to 7b6e602 Compare December 9, 2024 13:32
@@ -18,7 +18,8 @@ var (
type Store interface {
// CreateStaticAddress inserts a new static address with its parameters
// into the store.
CreateStaticAddress(ctx context.Context, addrParams *Parameters) error
CreateStaticAddress(ctx context.Context, addrParams *Parameters,
currentHeight int32) error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why a separate argument currentHeight is needed? addrParams has new field InitiationHeight.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed currentHeight and use the InitiationHeight.

@hieblmi hieblmi force-pushed the fix-deposit-detection branch from 7b6e602 to 23cc7ca Compare December 9, 2024 13:42
@hieblmi hieblmi requested review from starius and bhandras December 9, 2024 13:51
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM, nice catch! 🎉

Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM! 🏆

I propose to add a test reproducing the bug being fixed.

@@ -147,6 +171,7 @@ func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,
ProtocolVersion: version.AddressProtocolVersion(
protocolVersion,
),
InitiationHeight: m.currentHeight,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can currentHeight be uninitialized (0) at this point? IMHO we should either return an error here if currentHeight is 0 (if we are sure that this won't happen) or wait for its initialization (e.g. using a cond var).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For now I've added a check on entry of NewAddress.

@@ -97,7 +97,7 @@ func TestManager(t *testing.T) {
// Start the manager.
go func() {
err := testContext.manager.Run(ctxb)
require.NoError(t, err)
require.ErrorContains(t, err, "context canceled")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: require.ErrorIs(t, err, context.Canceled)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

@hieblmi hieblmi force-pushed the fix-deposit-detection branch from 23cc7ca to b1c19e8 Compare December 9, 2024 15:15
@hieblmi hieblmi merged commit 73c2f22 into lightninglabs:static-addr-staging Dec 9, 2024
4 checks passed
@hieblmi hieblmi deleted the fix-deposit-detection branch December 9, 2024 16:30
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.

3 participants