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

chore: update response of queries to use BTCHeaderInfoResponse #521

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 65 additions & 79 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -515,26 +515,24 @@ paths:
header:
type: object
properties:
header:
header_hex:
type: string
format: byte
hash:
hash_hex:
type: string
format: byte
height:
type: string
format: uint64
work:
type: string
format: byte
description: Work is the sdkmath.Uint as string.
description: >-
BTCHeaderInfo is a structure that contains all relevant
information about a
BTCHeaderInfoResponse is a structure that contains all
relevant information about a

BTC header
- Full header bytes
- Header hash for easy retrieval
- Height of the header in the BTC chain
BTC header response
- Full header as string hex.
- Header hash for easy retrieval as string hex.
- Height of the header in the BTC chain.
- Total work spent on the header. This is the sum of the work corresponding
to the header Bits field
and the total work of the header.
Expand Down Expand Up @@ -856,26 +854,24 @@ paths:
items:
type: object
properties:
header:
header_hex:
type: string
format: byte
hash:
hash_hex:
type: string
format: byte
height:
type: string
format: uint64
work:
type: string
format: byte
description: Work is the sdkmath.Uint as string.
description: >-
BTCHeaderInfo is a structure that contains all relevant
information about a
BTCHeaderInfoResponse is a structure that contains all
relevant information about a

BTC header
- Full header bytes
- Header hash for easy retrieval
- Height of the header in the BTC chain
BTC header response
- Full header as string hex.
- Header hash for easy retrieval as string hex.
- Height of the header in the BTC chain.
- Total work spent on the header. This is the sum of the work corresponding
to the header Bits field
and the total work of the header.
Expand Down Expand Up @@ -1054,26 +1050,24 @@ paths:
header:
type: object
properties:
header:
header_hex:
type: string
format: byte
hash:
hash_hex:
type: string
format: byte
height:
type: string
format: uint64
work:
type: string
format: byte
description: Work is the sdkmath.Uint as string.
description: >-
BTCHeaderInfo is a structure that contains all relevant
information about a
BTCHeaderInfoResponse is a structure that contains all
relevant information about a

BTC header
- Full header bytes
- Header hash for easy retrieval
- Height of the header in the BTC chain
BTC header response
- Full header as string hex.
- Header hash for easy retrieval as string hex.
- Height of the header in the BTC chain.
- Total work spent on the header. This is the sum of the work corresponding
to the header Bits field
and the total work of the header.
Expand Down Expand Up @@ -10299,29 +10293,27 @@ definitions:
"@type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}
babylon.btclightclient.v1.BTCHeaderInfo:
babylon.btclightclient.v1.BTCHeaderInfoResponse:
type: object
properties:
header:
header_hex:
type: string
format: byte
hash:
hash_hex:
type: string
format: byte
height:
type: string
format: uint64
work:
type: string
format: byte
description: Work is the sdkmath.Uint as string.
description: >-
BTCHeaderInfo is a structure that contains all relevant information about
a
BTCHeaderInfoResponse is a structure that contains all relevant
information about a

BTC header
- Full header bytes
- Header hash for easy retrieval
- Height of the header in the BTC chain
BTC header response
- Full header as string hex.
- Header hash for easy retrieval as string hex.
- Height of the header in the BTC chain.
- Total work spent on the header. This is the sum of the work corresponding
to the header Bits field
and the total work of the header.
Expand All @@ -10344,26 +10336,24 @@ definitions:
header:
type: object
properties:
header:
header_hex:
type: string
format: byte
hash:
hash_hex:
type: string
format: byte
height:
type: string
format: uint64
work:
type: string
format: byte
description: Work is the sdkmath.Uint as string.
description: >-
BTCHeaderInfo is a structure that contains all relevant information
about a
BTCHeaderInfoResponse is a structure that contains all relevant
information about a

BTC header
- Full header bytes
- Header hash for easy retrieval
- Height of the header in the BTC chain
BTC header response
- Full header as string hex.
- Header hash for easy retrieval as string hex.
- Height of the header in the BTC chain.
- Total work spent on the header. This is the sum of the work corresponding
to the header Bits field
and the total work of the header.
Expand Down Expand Up @@ -10440,26 +10430,24 @@ definitions:
items:
type: object
properties:
header:
header_hex:
type: string
format: byte
hash:
hash_hex:
type: string
format: byte
height:
type: string
format: uint64
work:
type: string
format: byte
description: Work is the sdkmath.Uint as string.
description: >-
BTCHeaderInfo is a structure that contains all relevant information
about a
BTCHeaderInfoResponse is a structure that contains all relevant
information about a

BTC header
- Full header bytes
- Header hash for easy retrieval
- Height of the header in the BTC chain
BTC header response
- Full header as string hex.
- Header hash for easy retrieval as string hex.
- Height of the header in the BTC chain.
- Total work spent on the header. This is the sum of the work corresponding
to the header Bits field
and the total work of the header.
Expand Down Expand Up @@ -10515,26 +10503,24 @@ definitions:
header:
type: object
properties:
header:
header_hex:
type: string
format: byte
hash:
hash_hex:
type: string
format: byte
height:
type: string
format: uint64
work:
type: string
format: byte
description: Work is the sdkmath.Uint as string.
description: >-
BTCHeaderInfo is a structure that contains all relevant information
about a
BTCHeaderInfoResponse is a structure that contains all relevant
information about a

BTC header
- Full header bytes
- Header hash for easy retrieval
- Height of the header in the BTC chain
BTC header response
- Full header as string hex.
- Header hash for easy retrieval as string hex.
- Height of the header in the BTC chain.
- Total work spent on the header. This is the sum of the work corresponding
to the header Bits field
and the total work of the header.
Expand Down Expand Up @@ -14960,7 +14946,7 @@ definitions:

epoch have signed `app_hash` of the sealer header

- The epoch medatata is committed to the `app_hash` of the sealer header
- The epoch metadata is committed to the `app_hash` of the sealer header

- The validator set is committed to the `app_hash` of the sealer header
babylon.zoneconcierge.v1.ProofFinalizedChainInfo:
Expand Down
28 changes: 24 additions & 4 deletions proto/babylon/btclightclient/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ syntax = "proto3";
package babylon.btclightclient.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "babylon/btclightclient/v1/btclightclient.proto";
import "babylon/btclightclient/v1/params.proto";

option go_package = "github.com/babylonchain/babylon/x/btclightclient/types";
Expand Down Expand Up @@ -108,7 +108,7 @@ message QueryMainChainRequest {

// QueryMainChainResponse is response type for the Query/MainChain RPC method.
message QueryMainChainResponse {
repeated BTCHeaderInfo headers = 1;
repeated BTCHeaderInfoResponse headers = 1;

cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
Expand All @@ -117,15 +117,15 @@ message QueryMainChainResponse {
message QueryTipRequest {}

// QueryTipResponse is the response type for the Query/Tip RPC method.
message QueryTipResponse { BTCHeaderInfo header = 1; }
message QueryTipResponse { BTCHeaderInfoResponse header = 1; }

// QueryBaseHeaderRequest is the request type for the Query/BaseHeader RPC
// method.
message QueryBaseHeaderRequest {}

// QueryBaseHeaderResponse is the response type for the Query/BaseHeader RPC
// method.
message QueryBaseHeaderResponse { BTCHeaderInfo header = 1; }
message QueryBaseHeaderResponse { BTCHeaderInfoResponse header = 1; }

// QueryMainChainDepthRequest is the request type for the Query/MainChainDepth RPC
// it contains hex encoded hash of btc block header as parameter
Expand All @@ -134,3 +134,23 @@ message QueryHeaderDepthRequest { string hash = 1; }
// QueryMainChainDepthResponse is the response type for the Query/MainChainDepth RPC
// it contains depth of the block in main chain
message QueryHeaderDepthResponse { uint64 depth = 1; }

// BTCHeaderInfoResponse is a structure that contains all relevant information about a
// BTC header response
// - Full header as string hex.
// - Header hash for easy retrieval as string hex.
// - Height of the header in the BTC chain.
// - Total work spent on the header. This is the sum of the work corresponding
// to the header Bits field
// and the total work of the header.
message BTCHeaderInfoResponse {
string header_hex = 1;
string hash_hex = 2;
uint64 height = 3;
// Work is the sdkmath.Uint as string.
string work = 4 [
(cosmos_proto.scalar) = "cosmos.Uint",
(gogoproto.customtype) = "cosmossdk.io/math.Uint",
(gogoproto.nullable) = false
];
}
6 changes: 5 additions & 1 deletion test/e2e/btc_staking_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/babylonchain/babylon/crypto/eots"
"github.com/babylonchain/babylon/test/e2e/configurer"
"github.com/babylonchain/babylon/test/e2e/configurer/chain"
"github.com/babylonchain/babylon/test/e2e/initialization"
"github.com/babylonchain/babylon/testutil/datagen"
bbn "github.com/babylonchain/babylon/types"
Expand Down Expand Up @@ -140,8 +141,11 @@ func (s *BTCStakingTestSuite) Test1CreateFinalityProviderAndDelegation() {
s.NoError(err)

// submit staking tx to Bitcoin and get inclusion proof
currentBtcTip, err := nonValidatorNode.QueryTip()
currentBtcTipResp, err := nonValidatorNode.QueryTip()
s.NoError(err)
currentBtcTip, err := chain.ParseBTCHeaderInfoResponseToInfo(currentBtcTipResp)
s.NoError(err)

blockWithStakingTx := datagen.CreateBlockWithTransaction(r, currentBtcTip.Header.ToBlockHeader(), stakingMsgTx)
nonValidatorNode.InsertHeader(&blockWithStakingTx.HeaderBytes)
// make block k-deep
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/btc_timestamping_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *BTCTimestampingTestSuite) Test2BTCBaseHeader() {
s.NoError(err)
baseHeader, err := nonValidatorNode.QueryBtcBaseHeader()
s.NoError(err)
s.True(baseHeader.Hash.Eq(hardcodedHeader.Hash()))
s.Equal(baseHeader.HeaderHex, hardcodedHeader.MarshalHex())
s.Equal(hardcodedHeaderHeight, baseHeader.Height)
}

Expand All @@ -94,11 +94,11 @@ func (s *BTCTimestampingTestSuite) Test3SendTx() {
s.Equal(tip1.Height+1, tip2.Height)

// check that light client properly updates its state
tip1Depth, err := nonValidatorNode.QueryHeaderDepth(tip1.Hash.MarshalHex())
tip1Depth, err := nonValidatorNode.QueryHeaderDepth(tip1.HashHex)
s.NoError(err)
s.Equal(tip1Depth, uint64(1))

tip2Depth, err := nonValidatorNode.QueryHeaderDepth(tip2.Hash.MarshalHex())
tip2Depth, err := nonValidatorNode.QueryHeaderDepth(tip2.HashHex)
s.NoError(err)
// tip should have 0 depth
s.Equal(tip2Depth, uint64(0))
Expand Down
Loading