github.com/lino-network/lino@v0.6.11/cmd/lino/main.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  
     7  	"github.com/cosmos/cosmos-sdk/baseapp"
     8  	"github.com/cosmos/cosmos-sdk/server"
     9  	storetypes "github.com/cosmos/cosmos-sdk/store/types"
    10  	"github.com/spf13/cobra"
    11  	abci "github.com/tendermint/tendermint/abci/types"
    12  	"github.com/tendermint/tendermint/libs/cli"
    13  	"github.com/tendermint/tendermint/libs/log"
    14  	tmtypes "github.com/tendermint/tendermint/types"
    15  	dbm "github.com/tendermint/tm-db"
    16  
    17  	"github.com/lino-network/lino/app"
    18  	"github.com/lino-network/lino/types"
    19  )
    20  
    21  // generate Lino application
    22  func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
    23  	app := app.NewLinoBlockchain(
    24  		logger,
    25  		db,
    26  		traceStore,
    27  		// XXX(yumin): previously we use
    28  		// "syncable": PruneSyncable = NewPruningOptions(100, 10000)
    29  		// which means every (10000 * block_time) seconds, a state is kept.
    30  		// If block_time is around 3 seconds, then every ~8.33 hours, a state
    31  		// is kept. When height is 4M, there are about 400 copies in db. Even if
    32  		// it's an immutable iavl, an early state may be just a full copy of the state, as
    33  		// it may be totally different from current and following kepted states.
    34  		// Plus state-sync is not supported for now, we set it to 400000 here.
    35  		baseapp.SetPruning(storetypes.NewPruningOptions(100, 400000)),
    36  	)
    37  	return app
    38  }
    39  
    40  func main() {
    41  	cobra.EnableCommandSorting = false
    42  
    43  	types.ConfigAndSealCosmosSDKAddress()
    44  
    45  	cdc := app.MakeCodec()
    46  	ctx := server.NewDefaultContext()
    47  
    48  	rootCmd := &cobra.Command{
    49  		Use:               "lino",
    50  		Short:             "Lino Blockchain (server)",
    51  		PersistentPreRunE: server.PersistentPreRunEFn(ctx),
    52  	}
    53  
    54  	rootCmd.AddCommand(app.VersionCmd())
    55  
    56  	rootCmd.AddCommand(app.InitCmd(ctx, cdc))
    57  
    58  	server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
    59  
    60  	executor := cli.PrepareBaseCmd(rootCmd, "BC", app.DefaultNodeHome)
    61  	err := executor.Execute()
    62  	if err != nil {
    63  		panic(err)
    64  	}
    65  }
    66  
    67  func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, traceStore io.Writer,
    68  	_ int64, _ bool, _ []string) (json.RawMessage, []tmtypes.GenesisValidator, error) {
    69  	lb := app.NewLinoBlockchain(logger, db, traceStore)
    70  	return lb.ExportAppStateAndValidators()
    71  }