Skip to content

Commit

Permalink
vochain: add StateSync* and SnapshotInterval flags
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Jan 9, 2024
1 parent b9beb0f commit 6fc2b8f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ func loadConfig() *config.Config {
"do not wait for Vochain to synchronize (for testing only)")
flag.Int("vochainMempoolSize", 20000,
"vochain mempool size")
flag.Int("vochainSnapshotInterval", 0,
"create state snapshot every N blocks (0 to disable)")
flag.Bool("vochainStateSyncEnabled", false,
"during startup, let cometBFT ask peers for available snapshots and use them to bootstrap the state")
flag.StringSlice("vochainStateSyncRPCServers", []string{},
"list of RPC servers to fetch snapshots from (minimum 2)")
flag.String("vochainStateSyncTrustHash", "",
"hash of the trusted block")
flag.Int64("vochainStateSyncTrustHeight", 0,
"height of the trusted block")

flag.Int("vochainMinerTargetBlockTimeSeconds", 10,
"vochain consensus block time target (in seconds)")
Expand Down
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ type VochainCfg struct {
IsSeedNode bool
// OffChainDataDownload specifies if the node is configured to download off-chain data
OffChainDataDownload bool
// SnapshotInterval enables creating a state snapshot every N blocks (0 to disable)
SnapshotInterval int
// StateSyncEnabled allows cometBFT during startup, to ask peers for available snapshots
// and use them to bootstrap the state
StateSyncEnabled bool
// StateSyncRPCServers to fetch the snapshots from (minimum 2 needed)
StateSyncRPCServers []string
// StateSyncTrustHeight and TrustHash must both be provided to force the trusting of a
// particular header.
StateSyncTrustHeight int64
// StateSyncTrustHeight and TrustHash must both be provided to force the trusting of a
// particular header.
StateSyncTrustHash string
}

// IndexerCfg handles the configuration options of the indexer
Expand Down
10 changes: 8 additions & 2 deletions vochain/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type BaseApplication struct {
// blockTime is the target block time that miners use
blockTime time.Duration

// snapshotInterval create state snapshot every N blocks (0 to disable)
snapshotInterval int

// endBlockTimestamp is the last block end timestamp calculated from local time.
endBlockTimestamp atomic.Int64
// startBlockTimestamp is the current block timestamp from tendermint's
Expand Down Expand Up @@ -154,6 +157,7 @@ func NewBaseApplication(vochainCfg *config.VochainCfg) (*BaseApplication, error)
TransactionHandler: transactionHandler,
blockCache: blockCache,
dataDir: vochainCfg.DataDir,
snapshotInterval: vochainCfg.SnapshotInterval,
genesisInfo: &comettypes.GenesisDoc{},
}, nil
}
Expand Down Expand Up @@ -205,8 +209,10 @@ func (app *BaseApplication) CommitState() ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("cannot save state: %w", err)
}
// perform state snapshot (DISABLED)
if false && app.Height()%50000 == 0 && !app.IsSynchronizing() { // DISABLED
// perform state snapshot
if app.snapshotInterval > 0 &&
app.Height()%uint32(app.snapshotInterval) == 0 &&
!app.IsSynchronizing() {
startTime := time.Now()
log.Infof("performing a state snapshot on block %d", app.Height())
if _, err := app.State.Snapshot(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions vochain/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ func newTendermint(app *BaseApplication,
tconfig.Mempool.MaxTxsBytes = int64(tconfig.Mempool.Size * tconfig.Mempool.MaxTxBytes)
tconfig.Mempool.CacheSize = 100000
tconfig.Mempool.Broadcast = true
tconfig.StateSync.Enable = localConfig.StateSyncEnabled
tconfig.StateSync.RPCServers = localConfig.StateSyncRPCServers
tconfig.StateSync.TrustHeight = localConfig.StateSyncTrustHeight
tconfig.StateSync.TrustHash = localConfig.StateSyncTrustHash

log.Debugf("mempool config: %+v", tconfig.Mempool)
// tmdbBackend defaults to goleveldb, but switches to cleveldb if
Expand Down

0 comments on commit 6fc2b8f

Please sign in to comment.