Skip to content

Commit ef17535

Browse files
russcossjulienrbrt
andauthored
refactor: use the built-in max to simplify the code (#2697)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> In Go 1.21, the standard library includes built-in [max/min](https://pkg.go.dev/[email protected]#max) function, which can greatly simplify the code. Signed-off-by: russcoss <[email protected]> Co-authored-by: julienrbrt <[email protected]>
1 parent ecb72a9 commit ef17535

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

block/internal/syncing/syncer.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ func (s *Syncer) initializeState() error {
196196
s.SetLastState(state)
197197

198198
// Set DA height
199-
daHeight := state.DAHeight
200-
if daHeight < s.config.DA.StartHeight {
201-
daHeight = s.config.DA.StartHeight
202-
}
199+
daHeight := max(state.DAHeight, s.config.DA.StartHeight)
203200
s.SetDAHeight(daHeight)
204201

205202
s.logger.Info().
@@ -342,10 +339,7 @@ func (s *Syncer) syncLoop() {
342339
}
343340
default:
344341
// Prevent busy-waiting when no events are available.
345-
waitTime := 10 * time.Millisecond
346-
if waitTime > s.config.Node.BlockTime.Duration {
347-
waitTime = s.config.Node.BlockTime.Duration
348-
}
342+
waitTime := min(10*time.Millisecond, s.config.Node.BlockTime.Duration)
349343

350344
time.Sleep(waitTime)
351345
}

0 commit comments

Comments
 (0)