Skip to content

Commit

Permalink
lock put instead of skip
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Aug 25, 2023
1 parent 4b5dabc commit ff9e25a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions share/eds/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ type Store struct {
// lastGCResult is only stored on the store for testing purposes.
lastGCResult atomic.Pointer[dagstore.GCResult]

// skip is used to skip parallel operations
skip sync.Map
// lock is used to lock parallel operations
lock sync.Map

metrics *metrics
}
Expand Down Expand Up @@ -201,11 +201,11 @@ func (s *Store) Put(ctx context.Context, root share.DataHash, square *rsmt2d.Ext
}

func (s *Store) put(ctx context.Context, root share.DataHash, square *rsmt2d.ExtendedDataSquare) (err error) {
if _, exists := s.skip.LoadOrStore(root.String(), 1); exists {
// no need to do any work, another routine is putting eds for the same root
return nil
}
defer s.skip.Delete(root.String())
m, _ := s.lock.LoadOrStore(root.String(), sync.Mutex{})
lock := m.(sync.Mutex)
lock.Lock()
defer lock.Unlock()
defer s.lock.Delete(root.String())

// if root already exists, short-circuit
if has, _ := s.Has(ctx, root); has {
Expand Down

0 comments on commit ff9e25a

Please sign in to comment.