diff --git a/.changelog/2786.bugfix.md b/.changelog/2786.bugfix.md new file mode 100644 index 00000000000..f0c4dcaba85 --- /dev/null +++ b/.changelog/2786.bugfix.md @@ -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. diff --git a/go/consensus/tendermint/abci/mux.go b/go/consensus/tendermint/abci/mux.go index d70846a8669..c939430fef2 100644 --- a/go/consensus/tendermint/abci/mux.go +++ b/go/consensus/tendermint/abci/mux.go @@ -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) { diff --git a/go/consensus/tendermint/tendermint.go b/go/consensus/tendermint/tendermint.go index f3e4488f7db..cea1c381935 100644 --- a/go/consensus/tendermint/tendermint.go +++ b/go/consensus/tendermint/tendermint.go @@ -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) }