diff --git a/clientcontroller/api/interface.go b/clientcontroller/api/interface.go index bf0919f4..df905826 100644 --- a/clientcontroller/api/interface.go +++ b/clientcontroller/api/interface.go @@ -8,10 +8,6 @@ import ( "github.com/babylonlabs-io/finality-provider/types" ) -const ( - babylonConsumerChainName = "babylon" -) - type ClientController interface { // RegisterFinalityProvider registers a finality provider to the consumer chain // it returns tx hash and error. The address of the finality provider will be diff --git a/clientcontroller/cosmwasm/consumer.go b/clientcontroller/cosmwasm/consumer.go index f64c60f1..f3bdb92b 100644 --- a/clientcontroller/cosmwasm/consumer.go +++ b/clientcontroller/cosmwasm/consumer.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "sort" + "strings" sdkErr "cosmossdk.io/errors" wasmdparams "github.com/CosmWasm/wasmd/app/params" @@ -298,29 +299,22 @@ func (wc *CosmwasmConsumerController) QueryLastPublicRandCommit(fpPk *btcec.Publ return nil, fmt.Errorf("failed to query smart contract state: %w", err) } - if len(dataFromContract.Data) == 0 { + if dataFromContract == nil || dataFromContract.Data == nil || len(dataFromContract.Data.Bytes()) == 0 || strings.Contains(string(dataFromContract.Data), "null") { // expected when there is no PR commit at all return nil, nil } // Define a response struct - var commitResp PubRandCommitResponse - err = json.Unmarshal(dataFromContract.Data, &commitResp) + var commit fptypes.PubRandCommit + err = json.Unmarshal(dataFromContract.Data.Bytes(), &commit) if err != nil { return nil, fmt.Errorf("failed to unmarshal response: %w", err) } - - commit := &fptypes.PubRandCommit{ - StartHeight: commitResp.StartHeight, - NumPubRand: commitResp.NumPubRand, - Commitment: commitResp.Commitment, - } - if err := commit.Validate(); err != nil { return nil, err } - return commit, nil + return &commit, nil } func (wc *CosmwasmConsumerController) QueryIsBlockFinalized(height uint64) (bool, error) { diff --git a/clientcontroller/cosmwasm/msg.go b/clientcontroller/cosmwasm/msg.go index ad6912ce..c4228f83 100644 --- a/clientcontroller/cosmwasm/msg.go +++ b/clientcontroller/cosmwasm/msg.go @@ -219,11 +219,5 @@ type QueryMsgLastPubRandCommit struct { } type LastPubRandCommitQuery struct { - BtcPkHex string `json:"btc_pk_hex"` - Limit *uint64 `json:"limit,omitempty"` -} -type PubRandCommitResponse struct { - StartHeight uint64 `json:"start_height"` - NumPubRand uint64 `json:"num_pub_rand"` - Commitment []byte `json:"commitment"` + BtcPkHex string `json:"btc_pk_hex"` } diff --git a/clientcontroller/opstackl2/consumer.go b/clientcontroller/opstackl2/consumer.go index a9c6de82..cd2a15d0 100644 --- a/clientcontroller/opstackl2/consumer.go +++ b/clientcontroller/opstackl2/consumer.go @@ -30,7 +30,7 @@ import ( ) const ( - BabylonChainName = "Babylon" + BABYLON_CHAIN_NAME = "Babylon" ) var _ api.ConsumerController = &OPStackL2ConsumerController{} @@ -87,7 +87,7 @@ func NewCwClient(cwConfig *cwconfig.CosmwasmConfig, logger *zap.Logger) (*cwclie cwClient, err := cwclient.New( cwConfig, - BabylonChainName, + BABYLON_CHAIN_NAME, cwEncodingCfg, logger, ) diff --git a/finality-provider/service/fp_instance.go b/finality-provider/service/fp_instance.go index 8b36e77f..a7b8b711 100644 --- a/finality-provider/service/fp_instance.go +++ b/finality-provider/service/fp_instance.go @@ -1020,7 +1020,7 @@ func (fp *FinalityProviderInstance) lastCommittedPublicRandWithRetry() (*types.P return nil }, RtyAtt, RtyDel, RtyErr, retry.OnRetry(func(n uint, err error) { fp.logger.Debug( - "failed to query babylon for the last committed public randomness", + "failed to query the last committed public randomness", zap.Uint("attempt", n+1), zap.Uint("max_attempts", RtyAttNum), zap.Error(err), diff --git a/go.mod b/go.mod index 47b3e732..d70c9a31 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/CosmWasm/wasmd v0.52.0 github.com/avast/retry-go/v4 v4.5.1 github.com/babylonlabs-io/babylon v0.9.0 - github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240802071655-9fd2ddd5158b + github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240813062800-00e11abf5338 github.com/babylonlabs-io/finality-gadget v0.1.1-0.20240813005904-2fa76c30cb74 github.com/btcsuite/btcd v0.24.2 github.com/btcsuite/btcd/btcec/v2 v2.3.2 @@ -46,7 +46,7 @@ require ( require ( github.com/BurntSushi/toml v1.4.0 // indirect - github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240802071655-9fd2ddd5158b // indirect + github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240813062800-00e11abf5338 // indirect github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect github.com/cosmos/ibc-go/modules/apps/callbacks v0.2.1-0.20231113120333-342c00b0f8bd // indirect diff --git a/go.sum b/go.sum index 8cb86235..4a444750 100644 --- a/go.sum +++ b/go.sum @@ -298,14 +298,10 @@ github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8 github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/babylonlabs-io/babylon-private v0.9.0-rc.3.0.20240801001431-74a24c962ce2 h1:sFsAJkrYe1eIkKzWTn4sj7G6QrPQ3IK33/UlOVgeA5M= github.com/babylonlabs-io/babylon-private v0.9.0-rc.3.0.20240801001431-74a24c962ce2/go.mod h1:pyFZgF85gUhfiCJKbYjnxo5+9prDkti48tW4FDEu9js= -github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240802071655-9fd2ddd5158b h1:RctaFr4Svn/gbTa6FkPi78Jkm81J/NFFtp2V2ogMyl0= -github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240802071655-9fd2ddd5158b/go.mod h1:8t6U0E4bCQlRQQSKIXNTpTOjACVihJd5wdMLxL55jFE= -github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240802071655-9fd2ddd5158b h1:DeP6CzLozsd1MFSOf/Xo3FoBqROW6YZ8fq5ayR3KPwM= -github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240802071655-9fd2ddd5158b/go.mod h1:fCwb573m5JgCpuAZ+MK3Kx4WIV+q60TaPRu/m8fCcr0= -github.com/babylonlabs-io/finality-gadget v0.0.0-20240810191700-9ddea258bce5 h1:PgJJS7ae2fFJKRRmb5epXabwuVl0SYIDIRz4n+NUNG0= -github.com/babylonlabs-io/finality-gadget v0.0.0-20240810191700-9ddea258bce5/go.mod h1:+BICJA7mUJpfYOSYds1G5w6nLO0gKVe9XwdmpIUiXmk= -github.com/babylonlabs-io/finality-gadget v0.1.0 h1:7Hytq+StGQgFPBbqQ/8ONlXyS21YTS+IEha5zFLAAH8= -github.com/babylonlabs-io/finality-gadget v0.1.0/go.mod h1:aVEXVcozo62wRXJM639Dnp4u69u5Wjb3rUr1our7YTU= +github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240813062800-00e11abf5338 h1:a45+o47CqEksgeyX1IBbWoxPojIVLOIARxH9uBsHe70= +github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240813062800-00e11abf5338/go.mod h1:QqEn1sL4RPG7DJ94XFYvuvEELml64s5XwPQpTayXJss= +github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240813062800-00e11abf5338 h1:48YwlQpQELyuVb7D/r2NMh7Op8K9WYMcnKUpeH3a+5c= +github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240813062800-00e11abf5338/go.mod h1:WJlZy0RYCtyBFeO1mr0Tlo02csrlCAQgzmp4+NVX14g= github.com/babylonlabs-io/finality-gadget v0.1.1-0.20240813005904-2fa76c30cb74 h1:PrkYtnJyYs4eTEbR5yaEJk6yV6UPuAWiDZQBAMEsvL8= github.com/babylonlabs-io/finality-gadget v0.1.1-0.20240813005904-2fa76c30cb74/go.mod h1:+BICJA7mUJpfYOSYds1G5w6nLO0gKVe9XwdmpIUiXmk= github.com/babylonlabs-io/optimism v1.8.1-0.20240808190817-3279057d5250 h1:3FNsa55pbil/Ff7NICtaZzcdLwRs9HsCXJNmW7hDzPs= diff --git a/itest/bytecode/babylon_contract.wasm b/itest/bytecode/babylon_contract.wasm index fe731019..5d8ccfb9 100644 Binary files a/itest/bytecode/babylon_contract.wasm and b/itest/bytecode/babylon_contract.wasm differ diff --git a/itest/bytecode/btc_staking.wasm b/itest/bytecode/btc_staking.wasm index 5edf88f4..5d069ccb 100644 Binary files a/itest/bytecode/btc_staking.wasm and b/itest/bytecode/btc_staking.wasm differ diff --git a/tools/go.mod b/tools/go.mod index f666dc25..349ee3df 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -7,7 +7,7 @@ toolchain go1.21.4 require ( github.com/CosmWasm/wasmd v0.52.0 github.com/babylonlabs-io/babylon v0.9.0 - github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240802071655-9fd2ddd5158b + github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240813062800-00e11abf5338 ) require ( @@ -39,7 +39,7 @@ require ( github.com/DataDog/zstd v1.5.5 // indirect github.com/aead/siphash v1.0.1 // indirect github.com/aws/aws-sdk-go v1.44.312 // indirect - github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240802071655-9fd2ddd5158b // indirect + github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240813062800-00e11abf5338 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect diff --git a/tools/go.sum b/tools/go.sum index 9186cd9a..ac67aba2 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -268,10 +268,10 @@ github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8 github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/babylonlabs-io/babylon-private v0.9.0-rc.3.0.20240801001431-74a24c962ce2 h1:sFsAJkrYe1eIkKzWTn4sj7G6QrPQ3IK33/UlOVgeA5M= github.com/babylonlabs-io/babylon-private v0.9.0-rc.3.0.20240801001431-74a24c962ce2/go.mod h1:pyFZgF85gUhfiCJKbYjnxo5+9prDkti48tW4FDEu9js= -github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240802071655-9fd2ddd5158b h1:RctaFr4Svn/gbTa6FkPi78Jkm81J/NFFtp2V2ogMyl0= -github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240802071655-9fd2ddd5158b/go.mod h1:8t6U0E4bCQlRQQSKIXNTpTOjACVihJd5wdMLxL55jFE= -github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240802071655-9fd2ddd5158b h1:DeP6CzLozsd1MFSOf/Xo3FoBqROW6YZ8fq5ayR3KPwM= -github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240802071655-9fd2ddd5158b/go.mod h1:fCwb573m5JgCpuAZ+MK3Kx4WIV+q60TaPRu/m8fCcr0= +github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240813062800-00e11abf5338 h1:a45+o47CqEksgeyX1IBbWoxPojIVLOIARxH9uBsHe70= +github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20240813062800-00e11abf5338/go.mod h1:QqEn1sL4RPG7DJ94XFYvuvEELml64s5XwPQpTayXJss= +github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240813062800-00e11abf5338 h1:48YwlQpQELyuVb7D/r2NMh7Op8K9WYMcnKUpeH3a+5c= +github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20240813062800-00e11abf5338/go.mod h1:WJlZy0RYCtyBFeO1mr0Tlo02csrlCAQgzmp4+NVX14g= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=