Skip to content

Commit

Permalink
snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
klim0v committed Dec 14, 2021
1 parent 4731d2f commit 30e723b
Show file tree
Hide file tree
Showing 18 changed files with 1,980 additions and 82 deletions.
19 changes: 17 additions & 2 deletions cmd/minter/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"context"
"fmt"

"github.com/cosmos/cosmos-sdk/snapshots"
"io"
"net/http"
_ "net/http/pprof" // nolint: gosec // securely exposed on separate, optional port
Expand Down Expand Up @@ -88,10 +88,25 @@ func runNode(cmd *cobra.Command) error {
if err != nil {
return err
}
app := minter.NewMinterBlockchain(storages, cfg, cmd.Context(), 720, 0)
app := minter.NewMinterBlockchain(storages, cfg, cmd.Context(), 720, 0, logger.With("module", "node"))

if cfg.SnapshotInterval > 0 {
snapshotDB, err := storages.InitSnapshotLevelDB("data/snapshots/metadata", minter.GetDbOpts(cfg.StateMemAvailable))
if err != nil {
return err
}

snapshotStore, err := snapshots.NewStore(snapshotDB, storages.GetMinterHome()+"/data/snapshots")
if err != nil {
panic(err)
}

app.SetSnapshotStore(snapshotStore, cfg.SnapshotInterval, cfg.SnapshotKeepRecent)
}

// start TM node
node := startTendermintNode(app, tmConfig, logger, storages.GetMinterHome())

client := app.RpcClient()

if !cfg.ValidatorMode {
Expand Down
12 changes: 11 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Storage struct {
minterConfig string
eventDB db.DB
stateDB db.DB
snapshotDB db.DB
}

func (s *Storage) SetMinterConfig(minterConfig string) {
Expand All @@ -31,7 +32,16 @@ func (s *Storage) StateDB() db.DB {
}

func NewStorage(home string, config string) *Storage {
return &Storage{eventDB: db.NewMemDB(), stateDB: db.NewMemDB(), minterConfig: config, minterHome: home}
return &Storage{eventDB: db.NewMemDB(), stateDB: db.NewMemDB(), snapshotDB: db.NewMemDB(), minterConfig: config, minterHome: home}
}

func (s *Storage) InitSnapshotLevelDB(name string, opts *opt.Options) (db.DB, error) {
levelDB, err := db.NewGoLevelDBWithOpts(name, s.GetMinterHome(), opts)
if err != nil {
return nil, err
}
s.snapshotDB = levelDB
return s.snapshotDB, nil
}

func (s *Storage) InitEventLevelDB(name string, opts *opt.Options) (db.DB, error) {
Expand Down
31 changes: 16 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type Config struct {
BaseConfig `mapstructure:",squash"`

// Options for services
StateSync *tmConfig.StateSyncConfig `mapstructure:"statesync"`
RPC *tmConfig.RPCConfig `mapstructure:"rpc"`
P2P *tmConfig.P2PConfig `mapstructure:"p2p"`
Mempool *tmConfig.MempoolConfig `mapstructure:"mempool"`
Expand All @@ -110,6 +111,7 @@ type Config struct {
func defaultConfig() *Config {
return &Config{
BaseConfig: DefaultBaseConfig(),
StateSync: tmConfig.DefaultStateSyncConfig(),
RPC: tmConfig.DefaultRPCConfig(),
P2P: tmConfig.DefaultP2PConfig(),
Mempool: tmConfig.DefaultMempoolConfig(),
Expand Down Expand Up @@ -149,19 +151,10 @@ func GetTmConfig(cfg *Config) *tmConfig.Config {
ABCI: cfg.ABCI,
FilterPeers: cfg.FilterPeers,
},
RPC: cfg.RPC,
P2P: cfg.P2P,
Mempool: cfg.Mempool,
// StateSync: &tmConfig.StateSyncConfig{
// Enable: true,
// TempDir: "",
// RPCServers: []string{}, // todo
// TrustPeriod: 168 * time.Hour,
// TrustHeight: 0,
// TrustHash: "",
// DiscoveryTime: 15 * time.Second,
// },
StateSync: tmConfig.DefaultStateSyncConfig(),
RPC: cfg.RPC,
P2P: cfg.P2P,
Mempool: cfg.Mempool,
StateSync: cfg.StateSync,
FastSync: tmConfig.DefaultFastSyncConfig(),
Consensus: cfg.Consensus,
TxIndex: cfg.TxIndex,
Expand Down Expand Up @@ -262,6 +255,11 @@ type BaseConfig struct {
StateMemAvailable int `mapstructure:"state_mem_available"`

HaltHeight int `mapstructure:"halt_height"`

// State sync snapshot interval
SnapshotInterval int `mapstructure:"snapshot_interval"`
// State sync snapshot to keep
SnapshotKeepRecent int `mapstructure:"snapshot_keep_recent"`
}

// DefaultBaseConfig returns a default base configuration for a Tendermint node
Expand All @@ -286,11 +284,14 @@ func DefaultBaseConfig() BaseConfig {
WSConnectionDuration: time.Minute,
ValidatorMode: false,
KeepLastStates: 120,
StateCacheSize: 1000000,
StateMemAvailable: 1024,
APISimultaneousRequests: 100,
LogPath: "stdout",
LogFormat: LogFormatPlain,
StateCacheSize: 1000000,
StateMemAvailable: 1024,
HaltHeight: 0,
SnapshotInterval: 0,
SnapshotKeepRecent: 2,
}
}

Expand Down
17 changes: 17 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ api_simultaneous_requests = {{ .BaseConfig.APISimultaneousRequests }}
# and verifying their commits
fast_sync = {{ .BaseConfig.FastSync }}
# State sync snapshot interval
snapshot_interval = {{ .BaseConfig.SnapshotInterval }}
# State sync snapshot to keep
snapshot_keep_recent = {{ .BaseConfig.SnapshotKeepRecent }}
# Database backend: leveldb | memdb
db_backend = "{{ .BaseConfig.DBBackend }}"
Expand Down Expand Up @@ -132,6 +137,18 @@ prof_laddr = "{{ .BaseConfig.ProfListenAddress }}"
##### advanced configuration options #####
[statesync]
enable = {{ .StateSync.Enable }}
# At least 2 available RPC servers.
rpc_servers = "{{ .StateSync.RPCServers }}"
# A trusted height
trust_height = {{ .StateSync.TrustHeight }}
# The block ID hash of the trusted height
trust_hash = "{{ .StateSync.TrustHash }}"
trust_period = "{{ .StateSync.TrustPeriod }}"
##### rpc server configuration options #####
[rpc]
Expand Down
Loading

0 comments on commit 30e723b

Please sign in to comment.