privval: return error on getpubkey (#4534)

closes #3602

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
This commit is contained in:
Marko
2020-03-12 08:10:36 +01:00
committed by GitHub
parent 038aff1fdb
commit 48f073d796
30 changed files with 501 additions and 216 deletions

View File

@@ -309,12 +309,12 @@ func logNodeStartupInfo(state sm.State, pubKey crypto.PubKey, logger, consensusL
}
}
func onlyValidatorIsUs(state sm.State, privVal types.PrivValidator) bool {
func onlyValidatorIsUs(state sm.State, pubKey crypto.PubKey) bool {
if state.Validators.Size() > 1 {
return false
}
addr, _ := state.Validators.GetByIndex(0)
return bytes.Equal(privVal.GetPubKey().Address(), addr)
return bytes.Equal(pubKey.Address(), addr)
}
func createMempoolAndMempoolReactor(config *cfg.Config, proxyApp proxy.AppConns,
@@ -613,17 +613,16 @@ func NewNode(config *cfg.Config,
}
}
pubKey := privValidator.GetPubKey()
if pubKey == nil {
// TODO: GetPubKey should return errors - https://github.com/tendermint/tendermint/issues/3602
return nil, errors.New("could not retrieve public key from private validator")
pubKey, err := privValidator.GetPubKey()
if err != nil {
return nil, errors.Wrap(err, "can't get pubkey")
}
logNodeStartupInfo(state, pubKey, logger, consensusLogger)
// Decide whether to fast-sync or not
// We don't fast-sync when the only validator is us.
fastSync := config.FastSyncMode && !onlyValidatorIsUs(state, privValidator)
fastSync := config.FastSyncMode && !onlyValidatorIsUs(state, pubKey)
csMetrics, p2pMetrics, memplMetrics, smMetrics := metricsProvider(genDoc.ChainID)
@@ -856,7 +855,10 @@ func (n *Node) ConfigureRPC() {
rpccore.SetEvidencePool(n.evidencePool)
rpccore.SetP2PPeers(n.sw)
rpccore.SetP2PTransport(n)
pubKey := n.privValidator.GetPubKey()
pubKey, err := n.privValidator.GetPubKey()
if err != nil {
panic(err)
}
rpccore.SetPubKey(pubKey)
rpccore.SetGenesisDoc(n.genesisDoc)
rpccore.SetProxyAppQuery(n.proxyApp.Query())