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

feat: cosmwasm consumer queries #381

Merged
merged 57 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1e6cb64
uncomment fp related tests
gusin13 Jun 13, 2024
8e7bf7c
move types to file
gusin13 Jun 13, 2024
fbbf7c0
put dels
gusin13 Jun 13, 2024
33f7b0d
test for fp power
gusin13 Jun 13, 2024
fd488fe
uncomment lines
gusin13 Jun 13, 2024
27e7b78
commit pub rand
gusin13 Jun 13, 2024
576fe2a
send finality sig
gusin13 Jun 13, 2024
9db7e81
fix
gusin13 Jun 14, 2024
a5e43b4
fix comments
gusin13 Jun 14, 2024
9b35b3b
fix comments
gusin13 Jun 14, 2024
b7b7bfd
restruct files
gusin13 Jun 14, 2024
3cf13d0
add tags
gusin13 Jun 14, 2024
0d714db
fix fp app
gusin13 Jun 14, 2024
ee377c8
fix
gusin13 Jun 17, 2024
9c57bdf
fix test
gusin13 Jun 17, 2024
30d7598
Merge remote-tracking branch 'origin/base/consumer-chain-support' int…
gusin13 Jun 17, 2024
e61fd96
fix bytecode
gusin13 Jun 17, 2024
8b706bf
fix cfg
gusin13 Jun 17, 2024
226e689
fix types
gusin13 Jun 17, 2024
6b987e1
move files
gusin13 Jun 18, 2024
0750afe
batch msg
gusin13 Jun 18, 2024
ac6ec9f
fix client
gusin13 Jun 18, 2024
24d246f
fill queries
gusin13 Jun 18, 2024
6cf28b3
fix lint
gusin13 Jun 18, 2024
8376aa6
fix addr
gusin13 Jun 18, 2024
c9b40c8
no need to set addr now
gusin13 Jun 18, 2024
062e839
remove unused test
gusin13 Jun 18, 2024
02c1243
fix err
gusin13 Jun 18, 2024
d3451e5
fix lint
gusin13 Jun 18, 2024
46b32e3
improve exec call
gusin13 Jun 18, 2024
20f12d5
implement pub rand later
gusin13 Jun 18, 2024
e27b8ee
pr comment: mapstruct to long
gusin13 Jun 18, 2024
b2219b3
Merge remote-tracking branch 'origin/base/consumer-chain-support' int…
gusin13 Jun 19, 2024
733404d
fix events
gusin13 Jun 19, 2024
cbc9a8e
fix client
gusin13 Jun 19, 2024
5bfdaa7
remove unused code
gusin13 Jun 19, 2024
75cb8bf
fix config
gusin13 Jun 19, 2024
a262b31
move msg types under clientcontroller/
gusin13 Jun 19, 2024
1e6f3c8
remove dup types
gusin13 Jun 19, 2024
e190bf1
convert proof
gusin13 Jun 19, 2024
e67c1f2
add todo
gusin13 Jun 19, 2024
0845419
change to fppowerresponse
gusin13 Jun 19, 2024
36e3207
fix naming
gusin13 Jun 19, 2024
1542c8e
remove unused code
gusin13 Jun 20, 2024
b4db9bd
remove redundant checks
gusin13 Jun 20, 2024
b2ec9ae
made query structs
gusin13 Jun 20, 2024
90d7130
query msg fix
gusin13 Jun 20, 2024
0ee800f
Fix naming
gusin13 Jun 20, 2024
a07c802
rename
gusin13 Jun 20, 2024
75839ce
convert to struct
gusin13 Jun 20, 2024
bcdbb67
change to execmsg
gusin13 Jun 20, 2024
187531f
msg bytes
gusin13 Jun 20, 2024
9db1881
fix msg structs
gusin13 Jun 20, 2024
c77e712
fix lint
gusin13 Jun 20, 2024
84fd6d7
rename to cw client
gusin13 Jun 20, 2024
f414967
improve responses
gusin13 Jun 20, 2024
c0189af
pr 388: remove babylon contract address
gusin13 Jun 20, 2024
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
526 changes: 432 additions & 94 deletions clientcontroller/cosmwasm/consumer.go

Large diffs are not rendered by default.

220 changes: 220 additions & 0 deletions clientcontroller/cosmwasm/msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package cosmwasm

type ConsumerFpsResponse struct {
Fps []SingleConsumerFpResponse `json:"fps"`
}

// SingleConsumerFpResponse represents the finality provider data returned by the contract query.
// For more details, refer to the following links:
// https://github.com/babylonchain/babylon-contract/blob/v0.5.3/packages/apis/src/btc_staking_api.rs
// https://github.com/babylonchain/babylon-contract/blob/v0.5.3/contracts/btc-staking/src/msg.rs
// https://github.com/babylonchain/babylon-contract/blob/v0.5.3/contracts/btc-staking/schema/btc-staking.json
type SingleConsumerFpResponse struct {
BtcPkHex string `json:"btc_pk_hex"`
SlashedBabylonHeight uint64 `json:"slashed_babylon_height"`
SlashedBtcHeight uint64 `json:"slashed_btc_height"`
ConsumerId string `json:"consumer_id"`
}

type ConsumerDelegationsResponse struct {
Delegations []SingleConsumerDelegationResponse `json:"delegations"`
}

type SingleConsumerDelegationResponse struct {
BtcPkHex string `json:"btc_pk_hex"`
FpBtcPkList []string `json:"fp_btc_pk_list"`
StartHeight uint64 `json:"start_height"`
EndHeight uint64 `json:"end_height"`
TotalSat uint64 `json:"total_sat"`
StakingTx []byte `json:"staking_tx"`
SlashingTx []byte `json:"slashing_tx"`
DelegatorSlashingSig []byte `json:"delegator_slashing_sig"`
CovenantSigs []CovenantAdaptorSignatures `json:"covenant_sigs"`
StakingOutputIdx uint32 `json:"staking_output_idx"`
UnbondingTime uint32 `json:"unbonding_time"`
UndelegationInfo *BtcUndelegationInfo `json:"undelegation_info"`
ParamsVersion uint32 `json:"params_version"`
}

type ConsumerFpInfoResponse struct {
BtcPkHex string `json:"btc_pk_hex"`
Power uint64 `json:"power"`
}

type ConsumerFpsByPowerResponse struct {
Fps []ConsumerFpInfoResponse `json:"fps"`
}

type FinalitySignatureResponse struct {
Signature []byte `json:"signature"`
}

type BlocksResponse struct {
Blocks []IndexedBlock `json:"blocks"`
}

type IndexedBlock struct {
Height uint64 `json:"height"`
AppHash []byte `json:"app_hash"`
Finalized bool `json:"finalized"`
}

type NewFinalityProvider struct {
Description *FinalityProviderDescription `json:"description,omitempty"`
Commission string `json:"commission"`
BabylonPK *PubKey `json:"babylon_pk,omitempty"`
BTCPKHex string `json:"btc_pk_hex"`
Pop *ProofOfPossession `json:"pop,omitempty"`
ConsumerID string `json:"consumer_id"`
}

type FinalityProviderDescription struct {
Moniker string `json:"moniker"`
Identity string `json:"identity"`
Website string `json:"website"`
SecurityContact string `json:"security_contact"`
Details string `json:"details"`
}

type PubKey struct {
Key string `json:"key"`
}

type ProofOfPossession struct {
BTCSigType int32 `json:"btc_sig_type"`
BabylonSig string `json:"babylon_sig"`
BTCSig string `json:"btc_sig"`
}

type CovenantAdaptorSignatures struct {
CovPK string `json:"cov_pk"`
AdaptorSigs []string `json:"adaptor_sigs"`
}

type SignatureInfo struct {
PK string `json:"pk"`
Sig string `json:"sig"`
}

type BtcUndelegationInfo struct {
UnbondingTx string `json:"unbonding_tx"`
DelegatorUnbondingSig string `json:"delegator_unbonding_sig"`
CovenantUnbondingSigs []SignatureInfo `json:"covenant_unbonding_sig_list"`
SlashingTx string `json:"slashing_tx"`
DelegatorSlashingSig string `json:"delegator_slashing_sig"`
CovenantSlashingSigs []CovenantAdaptorSignatures `json:"covenant_slashing_sigs"`
}

type ActiveBtcDelegation struct {
BTCPkHex string `json:"btc_pk_hex"`
FpBtcPkList []string `json:"fp_btc_pk_list"`
StartHeight uint64 `json:"start_height"`
EndHeight uint64 `json:"end_height"`
TotalSat uint64 `json:"total_sat"`
StakingTx string `json:"staking_tx"`
SlashingTx string `json:"slashing_tx"`
DelegatorSlashingSig string `json:"delegator_slashing_sig"`
CovenantSigs []CovenantAdaptorSignatures `json:"covenant_sigs"`
StakingOutputIdx uint32 `json:"staking_output_idx"`
UnbondingTime uint32 `json:"unbonding_time"`
UndelegationInfo BtcUndelegationInfo `json:"undelegation_info"`
ParamsVersion uint32 `json:"params_version"`
}

type SlashedBtcDelegation struct {
// Define fields as needed
}

type UnbondedBtcDelegation struct {
// Define fields as needed
}

type BtcStaking struct {
NewFP []NewFinalityProvider `json:"new_fp"`
ActiveDel []ActiveBtcDelegation `json:"active_del"`
SlashedDel []SlashedBtcDelegation `json:"slashed_del"`
UnbondedDel []UnbondedBtcDelegation `json:"unbonded_del"`
}

type CommitPublicRandomness struct {
FPPubKeyHex string `json:"fp_pubkey_hex"`
StartHeight uint64 `json:"start_height"`
NumPubRand uint64 `json:"num_pub_rand"`
Commitment string `json:"commitment"`
Signature string `json:"signature"`
}

type SubmitFinalitySignature struct {
FpPubkeyHex string `json:"fp_pubkey_hex"`
Height uint64 `json:"height"`
PubRand string `json:"pub_rand"` // base64 encoded
Proof Proof `json:"proof"` // nested struct
BlockHash string `json:"block_hash"` // base64 encoded
Signature string `json:"signature"` // base64 encoded
}

type Proof struct {
Total uint64 `json:"total"`
Index uint64 `json:"index"`
LeafHash string `json:"leaf_hash"`
Aunts []string `json:"aunts"`
}

type ExecMsg struct {
SubmitFinalitySignature *SubmitFinalitySignature `json:"submit_finality_signature,omitempty"`
BtcStaking *BtcStaking `json:"btc_staking,omitempty"`
CommitPublicRandomness *CommitPublicRandomness `json:"commit_public_randomness,omitempty"`
}

type FinalityProviderInfo struct {
BtcPkHex string `json:"btc_pk_hex"`
Height uint64 `json:"height"`
}

type QueryMsgFinalityProviderInfo struct {
FinalityProviderInfo FinalityProviderInfo `json:"finality_provider_info"`
}

type BlockQuery struct {
Height uint64 `json:"height"`
}

type QueryMsgBlock struct {
Block BlockQuery `json:"block"`
}

type QueryMsgBlocks struct {
Blocks BlocksQuery `json:"blocks"`
}

type BlocksQuery struct {
StartAfter *uint64 `json:"start_after,omitempty"`
Limit *uint64 `json:"limit,omitempty"`
Finalized *bool `json:"finalized,omitempty"`
Reverse *bool `json:"reverse,omitempty"`
}

type QueryMsgActivatedHeight struct {
ActivatedHeight struct{} `json:"activated_height"`
}

type QueryMsgFinalitySignature struct {
FinalitySignature FinalitySignatureQuery `json:"finality_signature"`
}

type FinalitySignatureQuery struct {
BtcPkHex string `json:"btc_pk_hex"`
Height uint64 `json:"height"`
}

type QueryMsgFinalityProviders struct {
FinalityProviders struct{} `json:"finality_providers"`
}

type QueryMsgDelegations struct {
Delegations struct{} `json:"delegations"`
}

gusin13 marked this conversation as resolved.
Show resolved Hide resolved
type QueryMsgFinalityProvidersByPower struct {
FinalityProvidersByPower struct{} `json:"finality_providers_by_power"`
}
40 changes: 3 additions & 37 deletions cosmwasmclient/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package config
import (
"fmt"
"net/url"
"os"
"path/filepath"
"time"

"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
Expand All @@ -28,19 +26,21 @@ type CosmwasmConfig struct {
OutputFormat string `mapstructure:"output-format"`
SignModeStr string `mapstructure:"sign-mode"`
SubmitterAddress string `mapstructure:"submitter-address"`
// TODO: add contract address so fp can query the contract
}

func (cfg *CosmwasmConfig) Validate() error {
if _, err := url.Parse(cfg.RPCAddr); err != nil {
return fmt.Errorf("rpc-addr is not correctly formatted: %w", err)
}

if cfg.Timeout <= 0 {
return fmt.Errorf("timeout must be positive")
}

if cfg.BlockTimeout < 0 {
return fmt.Errorf("block-timeout can't be negative")
}

return nil
}

Expand All @@ -61,37 +61,3 @@ func (cfg *CosmwasmConfig) ToCosmosProviderConfig() cosmos.CosmosProviderConfig
SignModeStr: cfg.SignModeStr,
}
}

func DefaultWasmConfig() CosmwasmConfig {
return CosmwasmConfig{
Key: "node0",
ChainID: "chain-test",
// see https://docs.cosmos.network/master/core/grpc_rest.html for default ports
// TODO: configure HTTPS for Babylon's RPC server
// TODO: how to use Cosmos SDK's RPC server (port 1317) rather than Tendermint's RPC server (port 26657)?
RPCAddr: "http://localhost:26657",
// TODO: how to support GRPC in the Babylon client?
GRPCAddr: "https://localhost:9090",
AccountPrefix: "bbn",
KeyringBackend: "test",
GasAdjustment: 1.2,
GasPrices: "0.01ubbn",
KeyDirectory: defaultWasmHome(),
Debug: true,
Timeout: 20 * time.Second,
OutputFormat: "json",
SignModeStr: "direct",
SubmitterAddress: "bbn1v6k7k9s8md3k29cu9runasstq5zaa0lpznk27w", // this is currently a placeholder, will not recognized by Babylon
}
}

// defaultWasmHome returns the default cosmoswasm enabled cosmos sdk chain node directory, which is $HOME/.babylond
// copied from https://github.com/babylonchain/babylon/blob/648b804bc492ded2cb826ba261d7164b4614d78a/app/app.go#L205-L210
func defaultWasmHome() string {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}

return filepath.Join(userHomeDir, ".wasmd")
}
Loading