Skip to content

Commit

Permalink
core/tracker: unlock mutex (#2027)
Browse files Browse the repository at this point in the history
Unlock mutex before doing any i/o in core/tracker/incldelay.go.

category: bug
ticket: #2028
  • Loading branch information
dB2510 committed Apr 5, 2023
1 parent 3c76f51 commit 99c6f29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 4 additions & 2 deletions core/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ func (s *Scheduler) GetDutyDefinition(ctx context.Context, duty core.Duty) (core

epoch := duty.Slot / int64(slotsPerEpoch)
if !s.isEpochResolved(epoch) {
return nil, errors.New("epoch not resolved yet")
return nil, errors.New("epoch not resolved yet",
z.Str("duty", duty.String()), z.I64("epoch", epoch))
}
if s.isEpochTrimmed(epoch) {
return nil, errors.New("epoch already trimmed")
return nil, errors.New("epoch already trimmed",
z.Str("duty", duty.String()), z.I64("epoch", epoch))
}

defSet, ok := s.getDutyDefinitionSet(duty)
Expand Down
26 changes: 19 additions & 7 deletions core/tracker/incldelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,32 @@ func NewInclDelayFunc(eth2Cl eth2wrap.Client, dutiesFunc dutiesFunc) func(contex
// newInclDelayFunc extends NewInclDelayFunc with abstracted callback.
func newInclDelayFunc(eth2Cl eth2wrap.Client, dutiesFunc dutiesFunc, callback func([]int64)) func(context.Context, core.Slot) error {
// dutyStartSlot is the first slot we can instrument (since dutiesFunc will not have duties from older slots).
var dutyStartSlot int64
var dssMutex sync.Mutex
var (
dutyStartSlot int64
dssMutex sync.Mutex
)

return func(ctx context.Context, current core.Slot) error {
// getOrSetStartSlot returns a previously set duty start slot and true or it sets it and returns false.
getOrSetStartSlot := func(slot int64) (int64, bool) {
dssMutex.Lock()
defer dssMutex.Unlock()

if dutyStartSlot == 0 {
dutyStartSlot = slot
return 0, false
}

return dutyStartSlot, true
}

return func(ctx context.Context, current core.Slot) error {
// blockSlot the block we want to instrument.
blockSlot := current.Slot - inclDelayLag

if dutyStartSlot == 0 {
dutyStartSlot = current.Slot // Set start slot.
startSlot, ok := getOrSetStartSlot(current.Slot)
if !ok { // Set start slot.
return nil
} else if blockSlot < dutyStartSlot {
} else if blockSlot < startSlot {
return nil // Still need to wait
}

Expand All @@ -56,7 +68,7 @@ func newInclDelayFunc(eth2Cl eth2wrap.Client, dutiesFunc dutiesFunc, callback fu
var delays []int64
for _, att := range atts {
attSlot := att.Data.Slot
if int64(attSlot) < dutyStartSlot {
if int64(attSlot) < startSlot {
continue
}

Expand Down

0 comments on commit 99c6f29

Please sign in to comment.