all, state: unexpose GenesisDoc, ChainID fields make them accessor methods

Fixes #671

Unexpose GenesisDoc and ChainID fields to avoid them being
serialized to the DB on every block write/state.Save()

A GenesisDoc can now be alternatively written to the state's
database, by serializing its JSON as a value of key "genesis-doc".

There are now accessors and a setter for these attributes:
- state.GenesisDoc() (*types.GenesisDoc, error)
- state.ChainID() (string, error)
- state.SetGenesisDoc(*types.GenesisDoc)

This is a breaking change since it changes how the state's
serialization and requires that if loading the GenesisDoc entirely
from the database, you'll need to set its value in the database
as the GenesisDoc's JSON marshaled bytes.
This commit is contained in:
Emmanuel Odeke
2017-09-22 18:17:21 -06:00
committed by Anton Kaliaev
parent a1e0f0ba95
commit 7939d62ef0
7 changed files with 229 additions and 28 deletions

View File

@ -146,6 +146,10 @@ func NewNode(config *cfg.Config,
}
state.SetLogger(stateLogger)
genesisDoc, err := state.GenesisDoc()
if err != nil {
return nil, err
}
// Create the proxyApp, which manages connections (consensus, mempool, query)
// and sync tendermint and the app by replaying any necessary blocks
@ -286,7 +290,7 @@ func NewNode(config *cfg.Config,
node := &Node{
config: config,
genesisDoc: state.GenesisDoc,
genesisDoc: genesisDoc,
privValidator: privValidator,
privKey: privKey,
@ -485,11 +489,15 @@ func (n *Node) makeNodeInfo() *p2p.NodeInfo {
if _, ok := n.txIndexer.(*null.TxIndex); ok {
txIndexerStatus = "off"
}
chainID, err := n.consensusState.GetState().ChainID()
if err != nil {
cmn.PanicSanity(cmn.Fmt("failed ot get chainID: %v", err))
}
nodeInfo := &p2p.NodeInfo{
PubKey: n.privKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
Moniker: n.config.Moniker,
Network: n.consensusState.GetState().ChainID,
Network: chainID,
Version: version.Version,
Other: []string{
cmn.Fmt("wire_version=%v", wire.Version),