Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zoneconcierge: API for querying headers in a given epoch #261

Merged

Conversation

SebastianElvis
Copy link
Member

Fixes BM-401

Context: #254

This PR implements the API for querying headers in a given epoch.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Couple suggestions:

@@ -38,6 +38,10 @@ service Query {
rpc ListHeaders(QueryListHeadersRequest) returns (QueryListHeadersResponse) {
option (google.api.http).get = "/babylon/zoneconcierge/v1/headers/{chain_id}";
}
// ListEpochHeaders queries the headers of a chain timestamped in a given epoch of Babylon, with pagination support
rpc ListEpochHeaders(QueryListEpochHeadersRequest) returns (QueryListEpochHeadersResponse) {
option (google.api.http).get = "/babylon/zoneconcierge/v1/epochs/{epoch_num}/headers/{chain_id}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I suggest the link be /headers/{chain_id}/epoch/{epoch_num} as the epoch is a more specific part of a headers query.

// QueryListEpochHeadersResponse is response type for the Query/ListEpochHeaders RPC method.
message QueryListEpochHeadersResponse {
// headers is the list of headers
repeated babylon.zoneconcierge.v1.IndexedHeader headers = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we have pagination here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also considering pagination for this API. The problem is that this neither is straightforward nor gives us performance improvements due to the KVStore structure.

We are querying a segment in the KVStore and the keys in this KVStore is not consecutive. The non-consecutiveness requires us to find the start header and the end header of this epoch, which is already O(epoch_interval) in the worst case.

For the sake of efficiency, maybe we can consider a slightly different API, which only returns a list of heights whose corresponding headers are timestamped in this given epoch. With the list of heights the explorer can query its interested indexed headers from ZoneConcierge individually.

I have marked a TODO here. Once we have a decision I will make corresponding changes in a subsequent API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I also encountered a similar issue with the MainChain query of the btclightclient module (ref). I think it is possible although it makes the code more complex so we should decide on the tradeoff.

// this implies that this epoch does not timestamp any header for this chain at all
// and the query should return empty
if epochChainInfo.LatestHeader.BabylonEpoch < epochNumber {
return nil, types.ErrEpochHeadersNotFound
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above you mention that the query should return empty, yet here you return an error. I'm happy with returning an empty set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel an error gives a more clear message to the function invoker. The comment in L34 is indeed inconsistent though so I deleted it.

require.Equal(t, len(expectedHeaders), len(headers))
for i := 0; i < len(expectedHeaders); i++ {
require.Equal(t, expectedHeaders[i].Header.LastCommitHash, headers[i].Hash)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with my comment on #260 (ref) not entirely sure whether we check all cases here.

Base automatically changed from zoneconcierge-api-query-historical-chain-info to dev January 5, 2023 23:58
@SebastianElvis SebastianElvis merged commit 84de8f6 into dev Jan 6, 2023
@SebastianElvis SebastianElvis deleted the zoneconcierge-api-query-timestamped-headers-in-epoch branch January 6, 2023 01:16
KonradStaniec added a commit that referenced this pull request Jan 12, 2023
* zoneconcierge: API for querying the chain info of a given epoch (#260)

* zoneconcierge: API for querying headers in a given epoch (#261)

* zoneconcierge API: adding total number of timestamped headers to chainInfo (#263)

* zoneconcierge API: find the BTC-finalised chain info before specific CZ height (#264)

* zoneconcierge API: find header and fork headers at a given height (#266)

* checkpointing API: add checkpoint lifecycle in `RawCheckpointWithMeta` (#267)

* chore: refactor `FinalizedChainInfo` API (#268)

* Add integration test for zoneconcierge checkpointing (#269)

* Add integration test checking info about
opposing cz chain

* Fix: Increase gas in e2e test (#270)

Increase gas

* fix: checkpointing: Do not make the `home` flag a required one and unmarshall PubKey (#271)

* Fix build

Co-authored-by: Runchao Han <me@runchao.rocks>
Co-authored-by: Vitalis Salis <VitSalis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants