@@ -3,28 +3,34 @@ 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
+ type ImportParams struct {
17
+ GenesisStore * genesisstore.Store
18
+ DataDir string
19
+ ValidatorMode bool
20
+ CacheRatio cachescale.Func
21
+ LiveDbCache , ArchiveCache int64
22
+ }
23
+
24
+ func ImportGenesisStore (params ImportParams ) error {
25
+ if err := db .AssertDatabaseNotInitialized (params .DataDir ); err != nil {
20
26
return fmt .Errorf ("database in datadir is already initialized: %w" , err )
21
27
}
22
- if err := db .RemoveDatabase (dataDir ); err != nil {
28
+ if err := db .RemoveDatabase (params . DataDir ); err != nil {
23
29
return fmt .Errorf ("failed to remove existing data from the datadir: %w" , err )
24
30
}
25
31
26
- chaindataDir := filepath .Join (dataDir , "chaindata" )
27
- dbs , err := db .MakeDbProducer (chaindataDir , cacheRatio )
32
+ chaindataDir := filepath .Join (params . DataDir , "chaindata" )
33
+ dbs , err := db .MakeDbProducer (chaindataDir , params . CacheRatio )
28
34
if err != nil {
29
35
return err
30
36
}
@@ -33,18 +39,18 @@ func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, data
33
39
34
40
gdb , err := db .MakeGossipDb (db.GossipDbParameters {
35
41
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 ) ,
42
+ DataDir : params . DataDir ,
43
+ ValidatorMode : params . ValidatorMode ,
44
+ CacheRatio : params . CacheRatio ,
45
+ LiveDbCache : params . LiveDbCache ,
46
+ ArchiveCache : params . ArchiveCache ,
41
47
})
42
48
if err != nil {
43
49
return err
44
50
}
45
51
defer gdb .Close ()
46
52
47
- err = gdb .ApplyGenesis (genesisStore .Genesis ())
53
+ err = gdb .ApplyGenesis (params . GenesisStore .Genesis ())
48
54
if err != nil {
49
55
return fmt .Errorf ("failed to write Gossip genesis state: %v" , err )
50
56
}
@@ -63,7 +69,7 @@ func ImportGenesisStore(ctx *cli.Context, genesisStore *genesisstore.Store, data
63
69
abftCrit := func (err error ) {
64
70
panic (fmt .Errorf ("lachesis store error: %w" , err ))
65
71
}
66
- cdb := abft .NewStore (cMainDb , cGetEpochDB , abftCrit , abft .DefaultStoreConfig (cacheRatio ))
72
+ cdb := abft .NewStore (cMainDb , cGetEpochDB , abftCrit , abft .DefaultStoreConfig (params . CacheRatio ))
67
73
defer cdb .Close ()
68
74
69
75
err = cdb .ApplyGenesis (& abft.Genesis {
0 commit comments