Skip to content

Commit 22b24e2

Browse files
committed
go/consensus/cometbft/full: Ensure all queries use the same height
1 parent 0f9f997 commit 22b24e2

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

go/consensus/cometbft/full/common.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,18 @@ func (n *commonNode) GetTransactions(ctx context.Context, height int64) ([][]byt
677677

678678
// Implements consensusAPI.Backend.
679679
func (n *commonNode) GetTransactionsWithResults(ctx context.Context, height int64) (*consensusAPI.TransactionsWithResults, error) {
680-
txs, err := n.GetTransactions(ctx, height)
680+
// Ensure all queries use the same height if the specified height is the latest.
681+
tmHeight, err := n.heightToCometBFTHeight(height)
681682
if err != nil {
682683
return nil, err
683684
}
684685

685-
blockResults, err := n.GetCometBFTBlockResults(ctx, height)
686+
txs, err := n.GetTransactions(ctx, tmHeight)
687+
if err != nil {
688+
return nil, err
689+
}
690+
691+
blockResults, err := n.GetCometBFTBlockResults(ctx, tmHeight)
686692
if err != nil {
687693
return nil, err
688694
}
@@ -700,7 +706,7 @@ func (n *commonNode) GetTransactionsWithResults(ctx context.Context, height int6
700706
}
701707

702708
// Transaction staking events.
703-
stakingEvents, err := tmstaking.EventsFromCometBFT(txs[idx], height, rs.Events)
709+
stakingEvents, err := tmstaking.EventsFromCometBFT(txs[idx], tmHeight, rs.Events)
704710
if err != nil {
705711
return nil, err
706712
}
@@ -709,7 +715,7 @@ func (n *commonNode) GetTransactionsWithResults(ctx context.Context, height int6
709715
}
710716

711717
// Transaction registry events.
712-
registryEvents, _, err := tmregistry.EventsFromCometBFT(txs[idx], height, rs.Events)
718+
registryEvents, _, err := tmregistry.EventsFromCometBFT(txs[idx], tmHeight, rs.Events)
713719
if err != nil {
714720
return nil, err
715721
}
@@ -718,7 +724,7 @@ func (n *commonNode) GetTransactionsWithResults(ctx context.Context, height int6
718724
}
719725

720726
// Transaction roothash events.
721-
roothashEvents, err := tmroothash.EventsFromCometBFT(txs[idx], height, rs.Events)
727+
roothashEvents, err := tmroothash.EventsFromCometBFT(txs[idx], tmHeight, rs.Events)
722728
if err != nil {
723729
return nil, err
724730
}
@@ -727,7 +733,7 @@ func (n *commonNode) GetTransactionsWithResults(ctx context.Context, height int6
727733
}
728734

729735
// Transaction governance events.
730-
governanceEvents, err := tmgovernance.EventsFromCometBFT(txs[idx], height, rs.Events)
736+
governanceEvents, err := tmgovernance.EventsFromCometBFT(txs[idx], tmHeight, rs.Events)
731737
if err != nil {
732738
return nil, err
733739
}
@@ -781,6 +787,7 @@ func (n *commonNode) GetParameters(ctx context.Context, height int64) (*consensu
781787
return nil, err
782788
}
783789

790+
// Ensure all queries use the same height if the specified height is the latest.
784791
tmHeight, err := n.heightToCometBFTHeight(height)
785792
if err != nil {
786793
return nil, err
@@ -798,7 +805,7 @@ func (n *commonNode) GetParameters(ctx context.Context, height int64) (*consensu
798805
return nil, fmt.Errorf("cometbft: failed to marshal consensus params: %w", err)
799806
}
800807

801-
q, err := n.querier.QueryAt(ctx, height)
808+
q, err := n.querier.QueryAt(ctx, tmHeight)
802809
if err != nil {
803810
return nil, fmt.Errorf("cometbft: failed to create consensus query: %w", err)
804811
}

0 commit comments

Comments
 (0)