forked from Kyuubi2709/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
empty.go
69 lines (58 loc) · 1.69 KB
/
empty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package share
import (
"bytes"
"fmt"
"sync"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/da"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/rsmt2d"
)
// EmptyRoot returns Root of the empty block EDS.
func EmptyRoot() *Root {
initEmpty()
return emptyBlockRoot
}
// EmptyExtendedDataSquare returns the EDS of the empty block data square.
func EmptyExtendedDataSquare() *rsmt2d.ExtendedDataSquare {
initEmpty()
return emptyBlockEDS
}
// EmptyBlockShares returns the shares of the empty block.
func EmptyBlockShares() []Share {
initEmpty()
return emptyBlockShares
}
var (
emptyMu sync.Mutex
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
}
// compute empty block EDS and DAH for it
result := shares.TailPaddingShares(appconsts.MinShareCount)
emptyBlockShares = shares.ToBytes(result)
eds, err := da.ExtendShares(emptyBlockShares)
if err != nil {
panic(fmt.Errorf("failed to create empty EDS: %w", err))
}
emptyBlockEDS = eds
emptyBlockRoot, err = NewRoot(eds)
if err != nil {
panic(fmt.Errorf("failed to create empty DAH: %w", err))
}
minDAH := da.MinDataAvailabilityHeader()
if !bytes.Equal(minDAH.Hash(), emptyBlockRoot.Hash()) {
panic(fmt.Sprintf("mismatch in calculated minimum DAH and minimum DAH from celestia-app, "+
"expected %s, got %s", minDAH.String(), emptyBlockRoot.String()))
}
// precompute Hash, so it's cached internally to avoid potential races
emptyBlockRoot.Hash()
}