Skip to content

Conversation

@starius
Copy link
Collaborator

@starius starius commented Feb 26, 2025

Pull Request Checklist

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

@starius starius force-pushed the unit-race branch 5 times, most recently from d38ac11 to c69d9e4 Compare March 11, 2025 03:26
@starius starius changed the title [WIP] ci: run unit tests with -race multi: fix race conditions and run unit tests with -race Mar 11, 2025
@starius starius marked this pull request as ready for review March 11, 2025 03:41
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 🎉

select {
case currentHeight := <-newBlockChan:
m.currentHeight = currentHeight
m.currentHeight.Store(currentHeight)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also initialize the current height by querying best height at the start on Run.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Run already does this as soon as possible. Actually this is the only thing Run does - keeping currentHeight up-to-date.


// Ensure that we have that we have a sane current block height.
if m.currentHeight == 0 {
if m.currentHeight.Load() == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This check could be removed if current height is correctly initialized.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Run runs in background, so the caller doesn't know when Run has initialized currentHeight.
Additionally, it is better to double check even if it was initialized before, to detect a wrong order of methods called.

@starius starius force-pushed the unit-race branch 3 times, most recently from a123bc5 to 257b3db Compare March 14, 2025 17:41
// NewManager creates a new address manager.
func NewManager(cfg *ManagerConfig) *Manager {
return &Manager{
func NewManager(cfg *ManagerConfig, currentHeight int32) *Manager {
Copy link
Member

Choose a reason for hiding this comment

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

Nice, thanks!

Copy link
Member

@sputn1ck sputn1ck 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 fix!

@starius
Copy link
Collaborator Author

starius commented Mar 17, 2025

Rebased

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.

LGTM!

starius added 8 commits March 19, 2025 15:00
github.com/coreos/bbolt has race conditions:
golang/go#54690
Make the current height an atomic variable in staticaddr/address/manager.go and
in staticaddr/withdraw/manager.go.
Removed the initiation height from staticaddr/deposit/manager.go (not needed).
The function used to call the method swapKit.swapInfo() which accessed many
fields of the swapKit which may change in parallel by handlePaymentResult called
by executeSwap (payInvoiceAsync is called in a goroutine). The fields are: cost,
state, and update time.
If Run sets the current height field, it is technically a race between Run and
other methods reading the field. Setting in New is a safer option.

Removed a check that height is not 0 from static address manager.
@hieblmi hieblmi force-pushed the unit-race branch 14 times, most recently from 7cc50fe to 2f2c5a3 Compare March 20, 2025 13:59
@starius starius merged commit 75ad9b4 into lightninglabs:master Mar 20, 2025
4 checks passed
@starius starius deleted the unit-race branch March 20, 2025 14:20
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.

4 participants