2021-04-29 15:14:10 +00:00
package commands
import (
"fmt"
"os"
2022-01-19 03:49:07 +00:00
"github.com/ledgerwatch/erigon-lib/common"
2021-07-29 11:53:13 +00:00
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
2021-05-20 18:25:53 +00:00
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/common/paths"
"github.com/ledgerwatch/erigon/internal/debug"
2021-07-29 10:23:23 +00:00
"github.com/ledgerwatch/log/v3"
2021-04-29 15:14:10 +00:00
"github.com/spf13/cobra"
)
var (
consensusAddr string // Address of the consensus engine <host>:<port>
2022-06-07 04:00:37 +00:00
datadirCli string // Path to the working dir
2021-04-29 15:14:10 +00:00
config string // `file:<path>`` to specify config file in file system, `embed:<path>`` to use embedded file, `test` to register test interface and receive config from test driver
)
func init ( ) {
utils . CobraFlags ( rootCmd , append ( debug . Flags , utils . MetricFlags ... ) )
}
var rootCmd = & cobra . Command {
Use : "consensus" ,
Short : "consensus is Proof Of Concept for separare consensus engine" ,
PersistentPreRun : func ( cmd * cobra . Command , args [ ] string ) {
if err := debug . SetupCobra ( cmd ) ; err != nil {
panic ( err )
}
} ,
PersistentPostRun : func ( cmd * cobra . Command , args [ ] string ) {
debug . Exit ( )
} ,
}
func Execute ( ) {
2022-01-19 03:49:07 +00:00
ctx , _ := common . RootContext ( )
2021-04-29 15:14:10 +00:00
if err := rootCmd . ExecuteContext ( ctx ) ; err != nil {
fmt . Println ( err )
os . Exit ( 1 )
}
}
func must ( err error ) {
if err != nil {
panic ( err )
}
}
2022-02-22 17:39:48 +00:00
func withDataDir ( cmd * cobra . Command ) {
2022-06-07 04:00:37 +00:00
cmd . Flags ( ) . StringVar ( & datadirCli , "datadir" , paths . DefaultDataDir ( ) , "directory where databases and temporary files are kept" )
2021-04-29 15:14:10 +00:00
must ( cmd . MarkFlagDirname ( "datadir" ) )
}
func withApiAddr ( cmd * cobra . Command ) {
cmd . Flags ( ) . StringVar ( & consensusAddr , "consensus.api.addr" , "localhost:9093" , "address to listen to for consensus engine api <host>:<port>" )
}
func withConfig ( cmd * cobra . Command ) {
cmd . Flags ( ) . StringVar ( & config , "config" , "" , "`file:<path>` to specify config file in file system, `embed:<path>` to use embedded file, `test` to register test interface and receive config from test driver" )
}
2021-07-28 02:47:38 +00:00
func openDB ( path string , logger log . Logger ) kv . RwDB {
return mdbx . NewMDBX ( logger ) . Path ( path ) . MustOpen ( )
2021-04-29 15:14:10 +00:00
}