mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 13:51:21 +00:00
panic on marshal/unmarshal failures for genesisDoc
This commit is contained in:
17
node/node.go
17
node/node.go
@ -143,10 +143,7 @@ func NewNode(config *cfg.Config,
|
||||
}
|
||||
// save genesis doc to prevent a certain class of user errors (e.g. when it
|
||||
// was changed, accidentally or not). Also good for audit trail.
|
||||
err = saveGenesisDoc(stateDB, genDoc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to save genesis doc: %v", err)
|
||||
}
|
||||
saveGenesisDoc(stateDB, genDoc)
|
||||
}
|
||||
|
||||
state := sm.LoadState(stateDB)
|
||||
@ -552,6 +549,7 @@ var (
|
||||
genesisDocKey = []byte("genesisDoc")
|
||||
)
|
||||
|
||||
// panics if failed to unmarshal bytes
|
||||
func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) {
|
||||
bytes := db.Get(genesisDocKey)
|
||||
if len(bytes) == 0 {
|
||||
@ -559,15 +557,18 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) {
|
||||
} else {
|
||||
var genDoc *types.GenesisDoc
|
||||
err := json.Unmarshal(bytes, &genDoc)
|
||||
return genDoc, err
|
||||
if err != nil {
|
||||
cmn.PanicCrisis(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, bytes))
|
||||
}
|
||||
return genDoc, nil
|
||||
}
|
||||
}
|
||||
|
||||
func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) error {
|
||||
// panics if failed to marshal the given genesis document
|
||||
func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) {
|
||||
bytes, err := json.Marshal(genDoc)
|
||||
if err != nil {
|
||||
return err
|
||||
cmn.PanicCrisis(fmt.Sprintf("Failed to save genesis doc due to marshaling error: %v", err))
|
||||
}
|
||||
db.SetSync(genesisDocKey, bytes)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user