Skip to content

Commit

Permalink
Fix possible deadloop in beacon (#6451)
Browse files Browse the repository at this point in the history
## Motivation

I found a problem in the beacon protocol where if the node wakes up from sleep or syncs its clock via NTP at the wrong moment the go routine running the beacon protocol might end up in a deadloop without ever recovering.
  • Loading branch information
fasmat committed Nov 13, 2024
1 parent fbca87d commit d332ba0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ See [RELEASE](./RELEASE.md) for workflow instructions.

### Improvements

* [#6431](https://github.com/spacemeshos/go-spacemesh/pull/6431) Fix db-allow-schema-drift handling
* [#6408](https://github.com/spacemeshos/go-spacemesh/pull/6408) Prevent empty DB connection pool by freeing connections
upon errors during DB operations. This mostly fixes issues when a node is under heavy load from the API.

Expand All @@ -16,6 +15,10 @@ See [RELEASE](./RELEASE.md) for workflow instructions.
* [#6422](https://github.com/spacemeshos/go-spacemesh/pull/6422) Further improved performance of the proposal building
process to avoid late proposals.

* [#6431](https://github.com/spacemeshos/go-spacemesh/pull/6431) Fix db-allow-schema-drift handling

* [#6451](https://github.com/spacemeshos/go-spacemesh/pull/6451) Fix a possible deadloop in the beacon protocol.

## v1.7.6

### Upgrade information
Expand Down
3 changes: 2 additions & 1 deletion api/grpcserver/v2alpha1/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func TestNodeService_Status(t *testing.T) {
timesync.WithLayerDuration(layerDuration),
timesync.WithTickInterval(1*time.Second),
timesync.WithGenesisTime(time.Now()),
timesync.WithLogger(zaptest.NewLogger(t)))
timesync.WithLogger(zaptest.NewLogger(t)),
)
require.NoError(t, err)
defer clock.Close()

Expand Down
6 changes: 3 additions & 3 deletions beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,16 @@ func (pd *ProtocolDriver) listenEpochs(ctx context.Context) {
pd.logger.Debug("time sync detected, realigning Beacon")
continue
}
epoch := current.GetEpoch()
layer = epoch.Add(1).FirstLayer()
if !current.FirstInEpoch() {
continue
}
epoch := current.GetEpoch()
layer = epoch.Add(1).FirstLayer()

pd.setProposalTimeForNextEpoch()
pd.logger.Info("processing epoch", zap.Uint32("epoch", epoch.Uint32()))
pd.eg.Go(func() error {
_ = pd.onNewEpoch(ctx, epoch)
pd.onNewEpoch(ctx, epoch)
return nil
})
}
Expand Down

0 comments on commit d332ba0

Please sign in to comment.