-
Notifications
You must be signed in to change notification settings - Fork 16
/
tracer.go
53 lines (41 loc) · 1.48 KB
/
tracer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package consensus
import (
"github.com/tendermint/tendermint/config"
tmtDb "github.com/tendermint/tendermint/libs/db"
tmtState "github.com/tendermint/tendermint/state"
"github.com/lightstreams-network/lightchain/network"
stdtracer "github.com/lightstreams-network/lightchain/tracer"
)
type tracer interface {
assertPersistedInitStateDb(tmtCfg *config.Config, ntw network.Network)
}
type consensusTracer struct {
stdtracer.Tracer
}
func newTracer(cfg stdtracer.Config) (tracer, error) {
trc, err := stdtracer.NewTracer(cfg)
if err != nil {
return nil, err
}
if cfg.ShouldTrace {
return consensusTracer{trc}, nil
}
return consensusNullTracer{trc}, nil
}
func (trc consensusTracer) assertPersistedInitStateDb(tmtCfg *config.Config, ntw network.Network) {
trc.Logger.Infow("Tracing whether Tendermint StateDB wrote a valid initial state...", "statedb", tmtCfg.DBPath)
stateDB := tmtDb.NewDB("state", tmtDb.DBBackendType(tmtCfg.DBBackend), tmtCfg.DBDir())
defer stateDB.Close()
persistStateDb := tmtState.LoadState(stateDB)
protocolVersion, err := ntw.ConsensusProtocolBlockVersion()
if err != nil {
trc.Logger.Error(err.Error())
}
if persistStateDb.Version.Consensus.Block != protocolVersion {
trc.Logger.Errorw("Invalid protocol block version persist",
"expected", protocolVersion,
"persist", persistStateDb.Version.Consensus.Block)
}
trc.Logger.Infow("Protocol block version was persisted correctly",
"block_version", persistStateDb.Version.Consensus.Block)
}