From 842609ddcb42fa5024bed0002e0446862a85e316 Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Thu, 27 Apr 2017 19:39:06 +0200 Subject: [PATCH] Send InitChain message from ABCI to Core on Genesis InitChain is send from the ABCI to the Core node when the ABCI app has no blocks stored. --- consensus/replay.go | 6 ++++++ types/protobuf.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/consensus/replay.go b/consensus/replay.go index 5bc0c2611..0335ad153 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -257,6 +257,12 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p stateBlockHeight := h.state.LastBlockHeight log.Notice("ABCI Replay Blocks", "appHeight", appBlockHeight, "storeHeight", storeBlockHeight, "stateHeight", stateBlockHeight) + // If appBlockHeight == 0 it means that we are at genesis and hence should send InitChain + if appBlockHeight == 0 { + validators := types.TM2PB.Validators(h.state.Validators) + proxyApp.Consensus().InitChainSync(validators) + } + // First handle edge cases and constraints on the storeBlockHeight if storeBlockHeight == 0 { return appHash, h.checkAppHash(appHash) diff --git a/types/protobuf.go b/types/protobuf.go index 41b4c54bb..59994fea7 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -42,3 +42,11 @@ func (tm2pb) Validator(val *Validator) *types.Validator { Power: uint64(val.VotingPower), } } + +func (tm2pb) Validators(vals *ValidatorSet) []*types.Validator { + validators := make([]*types.Validator, len(vals.Validators)) + for i, val := range vals.Validators { + validators[i] = TM2PB.Validator(val) + } + return validators +}