Skip to content

Commit 812bf19

Browse files
authored
Embed json files in binary (#182)
* Embed ceremony.json in binary * Embed retroactive_peers.json in binary
1 parent 022e94b commit 812bf19

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed
File renamed without changes.

node/crypto/kzg/kzg.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kzg
22

33
import (
4+
_ "embed"
45
"encoding/binary"
56
"encoding/hex"
67
"encoding/json"
@@ -292,13 +293,11 @@ func TestInit(file string) {
292293
}
293294
}
294295

296+
//go:embed ceremony.json
297+
var csBytes []byte
298+
295299
func Init() {
296300
// start with phase 1 ceremony:
297-
csBytes, err := os.ReadFile("./ceremony.json")
298-
if err != nil {
299-
panic(err)
300-
}
301-
302301
bls48581.Init()
303302

304303
cs := &CeremonyState{}

node/crypto/kzg/kzg_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
func TestMain(m *testing.M) {
20-
csBytes, err := os.ReadFile("../../ceremony.json")
20+
csBytes, err := os.ReadFile("./ceremony.json")
2121
if err != nil {
2222
panic(err)
2323
}

node/crypto/kzg_inclusion_prover_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestKZGVerifyFrame(t *testing.T) {
18-
kzg.TestInit("../ceremony.json")
18+
kzg.TestInit("./kzg/ceremony.json")
1919
data := make([]byte, 1024)
2020
rand.Read(data)
2121

node/execution/intrinsics/ceremony/ceremony_execution_engine.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"bytes"
55
"crypto"
66
"crypto/rand"
7+
_ "embed"
78
"encoding/base64"
89
"encoding/binary"
910
"encoding/hex"
1011
"encoding/json"
1112
"fmt"
12-
"os"
1313
"strings"
1414
"sync"
1515

@@ -206,6 +206,11 @@ func (
206206
}
207207
}
208208

209+
// 2024-01-03: 1.2.0
210+
//
211+
//go:embed retroactive_peers.json
212+
var retroactivePeersJsonBinary []byte
213+
209214
// Creates a genesis state for the intrinsic
210215
func CreateGenesisState(
211216
logger *zap.Logger,
@@ -324,12 +329,6 @@ func CreateGenesisState(
324329
rewardTrie.Add(addrBytes, 0, 50)
325330
}
326331

327-
// 2024-01-03: 1.2.0
328-
d, err := os.ReadFile("./retroactive_peers.json")
329-
if err != nil {
330-
panic(err)
331-
}
332-
333332
type peerData struct {
334333
PeerId string `json:"peer_id"`
335334
TokenBalance uint64 `json:"token_balance"`
@@ -339,7 +338,7 @@ func CreateGenesisState(
339338
}
340339

341340
retroEntries := &rewards{}
342-
err = json.Unmarshal(d, retroEntries)
341+
err = json.Unmarshal(retroactivePeersJsonBinary, retroEntries)
343342
if err != nil {
344343
panic(err)
345344
}

0 commit comments

Comments
 (0)