From 2b39c4c4167ec4e7a5f5cd87208305402ac39ca9 Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 30 Jul 2025 22:16:32 +0800 Subject: [PATCH 1/2] fix: debug_traceTrasaction fail with block height mismatch Closes: #383 Solution: - the context height is set to be request height minus one to get the context of block beginning. --- x/vm/keeper/grpc_query.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/vm/keeper/grpc_query.go b/x/vm/keeper/grpc_query.go index c269f0e62..a3df2f378 100644 --- a/x/vm/keeper/grpc_query.go +++ b/x/vm/keeper/grpc_query.go @@ -469,7 +469,8 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ } ctx := sdk.UnwrapSDKContext(c) - if requestedHeight > ctx.BlockHeight() { + // `ContextHeight` is set to `requestedHeight - 1`, so we can get the context of block beginning + if requestedHeight > ctx.BlockHeight()+1 { return nil, status.Errorf(codes.FailedPrecondition, "requested height [%d] must be less than or equal to current height [%d]", requestedHeight, ctx.BlockHeight()) } // TODO: ideally, this query should validate that the block hash, predecessor transactions, and main trace tx actually existed in the block requested. From 5c391d4a93a8e4c23734ddf80796b4d01aadc299 Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 30 Jul 2025 22:27:02 +0800 Subject: [PATCH 2/2] Update x/vm/keeper/grpc_query.go --- x/vm/keeper/grpc_query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/vm/keeper/grpc_query.go b/x/vm/keeper/grpc_query.go index a3df2f378..01520637b 100644 --- a/x/vm/keeper/grpc_query.go +++ b/x/vm/keeper/grpc_query.go @@ -469,7 +469,7 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ } ctx := sdk.UnwrapSDKContext(c) - // `ContextHeight` is set to `requestedHeight - 1`, so we can get the context of block beginning + // the caller sets the `ctx.BlockHeight()` to be `requestedHeight - 1`, so we can get the context of block beginning if requestedHeight > ctx.BlockHeight()+1 { return nil, status.Errorf(codes.FailedPrecondition, "requested height [%d] must be less than or equal to current height [%d]", requestedHeight, ctx.BlockHeight()) }