Skip to content

Commit 7422d9f

Browse files
committed
allow multi-unit genesis processing
1 parent 7cba87c commit 7422d9f

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

opera/genesisstore/disk.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"io"
9+
"strings"
910
"time"
1011

1112
"github.com/Fantom-foundation/lachesis-base/common/bigendian"
@@ -133,14 +134,19 @@ func OpenGenesisStore(rawReader ReadAtSeekerCloser) (*Store, genesis.Hashes, err
133134
// wrap with a logger
134135
// human-readable name
135136
name := unit.UnitName
136-
if unit.UnitName == BlocksSection {
137-
name = "blocks"
137+
scanfName := strings.ReplaceAll(name, "-", "")
138+
if scanfName[len(scanfName)-1] < '0' || scanfName[len(scanfName)-1] > '9' {
139+
scanfName += "0"
138140
}
139-
if unit.UnitName == EpochsSection {
140-
name = "epochs"
141+
var part int
142+
if _, err := fmt.Sscanf(scanfName, "brs%d", &part); err == nil {
143+
name = fmt.Sprintf("blocks unit %d", part)
141144
}
142-
if unit.UnitName == EvmSection {
143-
name = "EVM data"
145+
if _, err := fmt.Sscanf(scanfName, "ers%d", &part); err == nil {
146+
name = fmt.Sprintf("epochs unit %d", part)
147+
}
148+
if _, err := fmt.Sscanf(scanfName, "evm%d", &part); err == nil {
149+
name = fmt.Sprintf("EVM unit %d", part)
144150
}
145151
loggedReader := filelog.Wrap(gzipReader, name, uncompressedSize, time.Minute)
146152

opera/genesisstore/store_genesis.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func getSectionName(base string, i int) string {
3838
if i == 0 {
3939
return base
4040
}
41-
return fmt.Sprintf("%s-%d", BlocksSection, i)
41+
return fmt.Sprintf("%s-%d", base, i)
4242
}
4343

4444
func (s Store) Header() genesis.Header {
@@ -50,10 +50,10 @@ func (s *Store) Blocks() genesis.Blocks {
5050
}
5151

5252
func (s Blocks) ForEach(fn func(ibr.LlrIdxFullBlockRecord) bool) {
53-
for i := 0; ; i++ {
53+
for i := 1000; i >= 0; i-- {
5454
f, err := s.fMap(getSectionName(BlocksSection, i))
5555
if err != nil {
56-
return
56+
continue
5757
}
5858
stream := rlp.NewStream(f, 0)
5959
for {
@@ -77,10 +77,10 @@ func (s *Store) Epochs() genesis.Epochs {
7777
}
7878

7979
func (s Epochs) ForEach(fn func(ier.LlrIdxFullEpochRecord) bool) {
80-
for i := 0; ; i++ {
80+
for i := 1000; i >= 0; i-- {
8181
f, err := s.fMap(getSectionName(EpochsSection, i))
8282
if err != nil {
83-
return
83+
continue
8484
}
8585
stream := rlp.NewStream(f, 0)
8686
for {
@@ -104,10 +104,10 @@ func (s *Store) RawEvmItems() genesis.EvmItems {
104104
}
105105

106106
func (s RawEvmItems) ForEach(fn func(key, value []byte) bool) {
107-
for i := 0; ; i++ {
107+
for i := 1000; i >= 0; i-- {
108108
f, err := s.fMap(getSectionName(EvmSection, i))
109109
if err != nil {
110-
return
110+
continue
111111
}
112112
it := iodb.NewIterator(f)
113113
for it.Next() {

0 commit comments

Comments
 (0)