Skip to content

Commit

Permalink
allow multi-unit genesis processing
Browse files Browse the repository at this point in the history
  • Loading branch information
uprendis committed Aug 19, 2022
1 parent 7cba87c commit 7422d9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
18 changes: 12 additions & 6 deletions opera/genesisstore/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"strings"
"time"

"github.com/Fantom-foundation/lachesis-base/common/bigendian"
Expand Down Expand Up @@ -133,14 +134,19 @@ func OpenGenesisStore(rawReader ReadAtSeekerCloser) (*Store, genesis.Hashes, err
// wrap with a logger
// human-readable name
name := unit.UnitName
if unit.UnitName == BlocksSection {
name = "blocks"
scanfName := strings.ReplaceAll(name, "-", "")
if scanfName[len(scanfName)-1] < '0' || scanfName[len(scanfName)-1] > '9' {
scanfName += "0"
}
if unit.UnitName == EpochsSection {
name = "epochs"
var part int
if _, err := fmt.Sscanf(scanfName, "brs%d", &part); err == nil {
name = fmt.Sprintf("blocks unit %d", part)
}
if unit.UnitName == EvmSection {
name = "EVM data"
if _, err := fmt.Sscanf(scanfName, "ers%d", &part); err == nil {
name = fmt.Sprintf("epochs unit %d", part)
}
if _, err := fmt.Sscanf(scanfName, "evm%d", &part); err == nil {
name = fmt.Sprintf("EVM unit %d", part)
}
loggedReader := filelog.Wrap(gzipReader, name, uncompressedSize, time.Minute)

Expand Down
14 changes: 7 additions & 7 deletions opera/genesisstore/store_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getSectionName(base string, i int) string {
if i == 0 {
return base
}
return fmt.Sprintf("%s-%d", BlocksSection, i)
return fmt.Sprintf("%s-%d", base, i)
}

func (s Store) Header() genesis.Header {
Expand All @@ -50,10 +50,10 @@ func (s *Store) Blocks() genesis.Blocks {
}

func (s Blocks) ForEach(fn func(ibr.LlrIdxFullBlockRecord) bool) {
for i := 0; ; i++ {
for i := 1000; i >= 0; i-- {
f, err := s.fMap(getSectionName(BlocksSection, i))
if err != nil {
return
continue
}
stream := rlp.NewStream(f, 0)
for {
Expand All @@ -77,10 +77,10 @@ func (s *Store) Epochs() genesis.Epochs {
}

func (s Epochs) ForEach(fn func(ier.LlrIdxFullEpochRecord) bool) {
for i := 0; ; i++ {
for i := 1000; i >= 0; i-- {
f, err := s.fMap(getSectionName(EpochsSection, i))
if err != nil {
return
continue
}
stream := rlp.NewStream(f, 0)
for {
Expand All @@ -104,10 +104,10 @@ func (s *Store) RawEvmItems() genesis.EvmItems {
}

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

0 comments on commit 7422d9f

Please sign in to comment.