@@ -3,28 +3,35 @@ package genesis
3
3
import (
4
4
"fmt"
5
5
"github.com/Fantom-foundation/go-opera/cmd/sonictool/db"
6
- "github.com/Fantom-foundation/go-opera/config/flags"
7
6
"github.com/Fantom-foundation/go-opera/opera/genesis"
8
7
"github.com/Fantom-foundation/go-opera/opera/genesisstore"
9
8
"github.com/Fantom-foundation/lachesis-base/abft"
10
9
"github.com/Fantom-foundation/lachesis-base/inter/idx"
11
10
"github.com/Fantom-foundation/lachesis-base/kvdb"
12
11
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
13
12
"github.com/ethereum/go-ethereum/log"
14
- "gopkg.in/urfave/cli.v1"
15
13
"path/filepath"
16
14
)
17
15
18
- func ImportGenesisStore (ctx * cli.Context , genesisStore * genesisstore.Store , dataDir string , validatorMode bool , cacheRatio cachescale.Func ) error {
19
- if err := db .AssertDatabaseNotInitialized (dataDir ); err != nil {
16
+ // ImportParams are parameters for ImportGenesisStore func.
17
+ type ImportParams struct {
18
+ GenesisStore * genesisstore.Store
19
+ DataDir string
20
+ ValidatorMode bool
21
+ CacheRatio cachescale.Func
22
+ LiveDbCache , ArchiveCache int64 // in bytes
23
+ }
24
+
25
+ func ImportGenesisStore (params ImportParams ) error {
26
+ if err := db .AssertDatabaseNotInitialized (params .DataDir ); err != nil {
20
27
return fmt .Errorf ("database in datadir is already initialized: %w" , err )
21
28
}
22
- if err := db .RemoveDatabase (dataDir ); err != nil {
29
+ if err := db .RemoveDatabase (params . DataDir ); err != nil {
23
30
return fmt .Errorf ("failed to remove existing data from the datadir: %w" , err )
24
31
}
25
32
26
- chaindataDir := filepath .Join (dataDir , "chaindata" )
27
- dbs , err := db .MakeDbProducer (chaindataDir , cacheRatio )
33
+ chaindataDir := filepath .Join (params . DataDir , "chaindata" )
34
+ dbs , err := db .MakeDbProducer (chaindataDir , params . CacheRatio )
28
35
if err != nil {
29
36
return err
30
37
}
@@ -33,18 +40,18 @@ func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, data
33
40
34
41
gdb , err := db .MakeGossipDb (db.GossipDbParameters {
35
42
Dbs : dbs ,
36
- DataDir : dataDir ,
37
- ValidatorMode : validatorMode ,
38
- CacheRatio : cacheRatio ,
39
- LiveDbCache : ctx . Int64 ( flags . LiveDbCacheFlag . Name ) ,
40
- ArchiveCache : ctx . Int64 ( flags . ArchiveCacheFlag . Name ) ,
43
+ DataDir : params . DataDir ,
44
+ ValidatorMode : params . ValidatorMode ,
45
+ CacheRatio : params . CacheRatio ,
46
+ LiveDbCache : params . LiveDbCache ,
47
+ ArchiveCache : params . ArchiveCache ,
41
48
})
42
49
if err != nil {
43
50
return err
44
51
}
45
52
defer gdb .Close ()
46
53
47
- err = gdb .ApplyGenesis (genesisStore .Genesis ())
54
+ err = gdb .ApplyGenesis (params . GenesisStore .Genesis ())
48
55
if err != nil {
49
56
return fmt .Errorf ("failed to write Gossip genesis state: %v" , err )
50
57
}
@@ -63,7 +70,7 @@ func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, data
63
70
abftCrit := func (err error ) {
64
71
panic (fmt .Errorf ("lachesis store error: %w" , err ))
65
72
}
66
- cdb := abft .NewStore (cMainDb , cGetEpochDB , abftCrit , abft .DefaultStoreConfig (cacheRatio ))
73
+ cdb := abft .NewStore (cMainDb , cGetEpochDB , abftCrit , abft .DefaultStoreConfig (params . CacheRatio ))
67
74
defer cdb .Close ()
68
75
69
76
err = cdb .ApplyGenesis (& abft.Genesis {
0 commit comments