Skip to content

Commit

Permalink
go/consensus/tendermint: Use our notion of latest height
Browse files Browse the repository at this point in the history
Do not let Tendermint determine the latest height as that completely ignores
ABCI processing so it can return a block for which local state does not yet
exist.
  • Loading branch information
kostko committed Mar 26, 2020
1 parent 504394e commit 6035f8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changelog/2786.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/consensus/tendermint: Use our notion of latest height

Do not let Tendermint determine the latest height as that completely ignores
ABCI processing so it can return a block for which local state does not yet
exist.
5 changes: 5 additions & 0 deletions go/consensus/tendermint/abci/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ func (a *ApplicationServer) EstimateGas(caller signature.PublicKey, tx *transact
return a.mux.EstimateGas(caller, tx)
}

// BlockHeight returns the last committed block height.
func (a *ApplicationServer) BlockHeight() int64 {
return a.mux.state.BlockHeight()
}

// NewApplicationServer returns a new ApplicationServer, using the provided
// directory to persist state.
func NewApplicationServer(ctx context.Context, upgrader upgrade.Backend, cfg *ApplicationConfig) (*ApplicationServer, error) {
Expand Down
11 changes: 7 additions & 4 deletions go/consensus/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,16 @@ func (t *tendermintService) GetTendermintBlock(ctx context.Context, height int64
return nil, ctx.Err()
}

var tmHeight *int64
var tmHeight int64
if height == consensusAPI.HeightLatest {
tmHeight = nil
// Do not let Tendermint determine the latest height (e.g., by passing nil here) as that
// completely ignores ABCI processing so it can return a block for which local state does
// not yet exist. Use our mux notion of latest height instead.
tmHeight = t.mux.BlockHeight()
} else {
tmHeight = &height
tmHeight = height
}
result, err := t.client.Block(tmHeight)
result, err := t.client.Block(&tmHeight)
if err != nil {
return nil, fmt.Errorf("tendermint: block query failed: %w", err)
}
Expand Down

0 comments on commit 6035f8e

Please sign in to comment.