Browse Source

Delay starting node until Genesis time (#2389)

pull/2370/merge
Zarko Milosevic 6 years ago
committed by Anton Kaliaev
parent
commit
2fbf810cd8
3 changed files with 26 additions and 0 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +9
    -0
      node/node.go
  3. +16
    -0
      node/node_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -24,3 +24,4 @@ IMPROVEMENTS:
- [metrics] `consensus.block_interval_metrics` is now gauge, not histogram (you will be able to see spikes, if any)
BUG FIXES:
- [node] \#2294 Delay starting node until Genesis time

+ 9
- 0
node/node.go View File

@ -7,6 +7,7 @@ import (
"fmt"
"net"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -37,6 +38,7 @@ import (
"github.com/tendermint/tendermint/state/txindex/kv"
"github.com/tendermint/tendermint/state/txindex/null"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
"github.com/tendermint/tendermint/version"
_ "net/http/pprof"
@ -427,6 +429,13 @@ func NewNode(config *cfg.Config,
// OnStart starts the Node. It implements cmn.Service.
func (n *Node) OnStart() error {
now := tmtime.Now()
genTime := n.genesisDoc.GenesisTime
if genTime.After(now) {
n.Logger.Info("Genesis time is in the future. Sleeping until then...", "genTime", genTime)
time.Sleep(genTime.Sub(now))
}
err := n.eventBus.Start()
if err != nil {
return err


+ 16
- 0
node/node_test.go View File

@ -14,6 +14,8 @@ import (
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
func TestNodeStartStop(t *testing.T) {
@ -75,3 +77,17 @@ func TestSplitAndTrimEmpty(t *testing.T) {
assert.Equal(t, tc.expected, splitAndTrimEmpty(tc.s, tc.sep, tc.cutset), "%s", tc.s)
}
}
func TestNodeDelayedStop(t *testing.T) {
config := cfg.ResetTestRoot("node_delayed_node_test")
now := tmtime.Now()
// create & start node
n, err := DefaultNewNode(config, log.TestingLogger())
n.GenesisDoc().GenesisTime = now.Add(5 * time.Second)
assert.NoError(t, err)
n.Start()
startTime := tmtime.Now()
assert.Equal(t, true, startTime.After(n.GenesisDoc().GenesisTime))
}

Loading…
Cancel
Save