Skip to content

Commit

Permalink
refactor(share): use sync.Once instead of mutex for init (#3625)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Aug 5, 2024
1 parent 6c5cf7d commit 62190ac
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions share/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ func EmptyBlockShares() []Share {
}

var (
emptyMu sync.Mutex
emptyOnce sync.Once
emptyBlockRoot *Root
emptyBlockEDS *rsmt2d.ExtendedDataSquare
emptyBlockShares []Share
)

// initEmpty enables lazy initialization for constant empty block data.
func initEmpty() {
emptyMu.Lock()
defer emptyMu.Unlock()
if emptyBlockRoot != nil {
return
}
emptyOnce.Do(computeEmpty)
}

func computeEmpty() {
// compute empty block EDS and DAH for it
result := shares.TailPaddingShares(appconsts.MinShareCount)
emptyBlockShares = shares.ToBytes(result)
Expand Down

0 comments on commit 62190ac

Please sign in to comment.