Skip to content

staticaddr: neutrino fixes #967

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

starius
Copy link
Collaborator

@starius starius commented Jun 23, 2025

Recovered withdrawal transactions are now published in parallel to speed-up starting Loop.
Also increased the timeout given for this startup (including the withdrawals' recovery) from 10s to 1m.

Also added logging and removed an unused method in an interface.

Pull Request Checklist

  • Update release_notes.md if your PR contains major features, breaking changes or bugfixes

@starius starius requested a review from hieblmi June 23, 2025 04:06
@starius starius self-assigned this Jun 23, 2025
@starius starius marked this pull request as ready for review June 23, 2025 04:23
Copy link
Collaborator

@hieblmi hieblmi left a comment

Choose a reason for hiding this comment

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

Thanks for the improvement. Only see one issue, otherwise looks good to go.

@@ -577,7 +580,7 @@ func (m *Manager) publishFinalizedWithdrawalTx(ctx context.Context,
return false, nil
}
} else {
log.Debugf("published deposit withdrawal with txid: %v",
log.Debugf("Published deposit withdrawal with txid: %v!",
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: when copying the txid from the log the ... and ! might be copied too, not sure if we want that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed ! and added a space before ....

@@ -922,10 +922,15 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
}
}()

// We need a higher timeout here, because withdrawalManager
// publishes transactions and each PublishTransaction call can
// wait for getting inv messages from a peer (neutrino).
Copy link
Collaborator

Choose a reason for hiding this comment

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

🙏

return err
}
for tx, deposits := range depositsByWithdrawalTx {
eg.Go(func() error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should pass in tx and deposits to the goroutine to make sure each goroutine operates on the right variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't pass additional arguments to Go. Modern Go has loopvar always enabled, so this should work as expected.

Copy link
Collaborator

@hieblmi hieblmi Jun 23, 2025

Choose a reason for hiding this comment

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

I think we then should capture txid and deposits as suggested here: https://go.dev/doc/faq#closures_and_goroutines, like

for _, v := range values {
        v := v // create a new 'v'.
        go func() {
            fmt.Println(v)
            done <- true
        }()
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is no longer needed. See the end of that section:

This behavior of the language, not defining a new variable for each iteration, was considered a mistake in retrospect, and has been addressed in Go 1.22, which does indeed create a new variable for each iteration, eliminating this issue.

@starius
Copy link
Collaborator Author

starius commented Jun 23, 2025

I pushed another commit staticaddr: use tx hash not *wire.MsgTx as a key. Noticed that recoverWithdrawals relies on GetActiveDepositsInState reusing the same *wire.MsgTx pointer for a unique transaction. Reworked this using txid to remove this assumption.

@starius starius requested review from hieblmi and bhandras June 23, 2025 13:05
@@ -227,15 +227,18 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error {
}

// Group the deposits by their finalized withdrawal transaction.
depositsByWithdrawalTx := make(map[*wire.MsgTx][]*deposit.Deposit)
depositsByWithdrawalTx := make(map[chainhash.Hash][]*deposit.Deposit)
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for the fix!

starius added 6 commits June 24, 2025 01:44
Use errgroup to publish each transaction in a separate goroutine.
Publishing a transaction can take a while in neutrino mode.
Do not rely on GetActiveDepositsInState reusing the same *wire.MsgTx
pointer for a unique transaction.
@starius
Copy link
Collaborator Author

starius commented Jun 24, 2025

Rebased and pushed another commit with logging fix "staticaddr: fix error formatting in the log".

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.

2 participants