Skip to content

Commit

Permalink
go/consensus/tendermint: Fix BlockHeight in InitChain
Browse files Browse the repository at this point in the history
Previously when ctx.BlockHeight() was called from InitChain it always returned
the zero height which was incorrect. Make sure to return one height less than
the initial height in this case.
  • Loading branch information
kostko committed Oct 30, 2020
1 parent fdffa08 commit 7848257
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion go/consensus/tendermint/abci/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ func (s *applicationState) NewContext(mode api.ContextMode, now time.Time) *api.

var blockCtx *api.BlockContext
var state mkvs.Tree
blockHeight := int64(s.stateRoot.Version)
switch mode {
case api.ContextInitChain:
state = s.deliverTxTree
// Configure block height so that current height will be correctly computed.
blockHeight = int64(s.initialHeight) - 1
case api.ContextCheckTx:
state = s.checkTxTree
case api.ContextDeliverTx, api.ContextBeginBlock, api.ContextEndBlock:
Expand All @@ -103,7 +106,7 @@ func (s *applicationState) NewContext(mode api.ContextMode, now time.Time) *api.
api.NewNopGasAccountant(),
s,
state,
int64(s.stateRoot.Version),
blockHeight,
blockCtx,
int64(s.initialHeight),
)
Expand Down

0 comments on commit 7848257

Please sign in to comment.