-
Notifications
You must be signed in to change notification settings - Fork 122
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
staticaddr/withdraw/manager.go
Outdated
@@ -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!", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
}()
}
There was a problem hiding this comment.
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.
I pushed another commit |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the fix!
This is needed for neutrino.
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.
Rebased and pushed another commit with logging fix "staticaddr: fix error formatting in the log". |
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
release_notes.md
if your PR contains major features, breaking changes or bugfixes