Skip to content

Commit

Permalink
chore: update to 0.52.0-rc.1 (#180)
Browse files Browse the repository at this point in the history
* update: sdk 0.52.0-rc.1

* fix: ci & tests

* lint :)

* CHANGELOG

* fix: remove arm arch
  • Loading branch information
JulianToledano authored Jan 9, 2025
1 parent a17f92b commit a10cbc6
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 558 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-arch: ["amd64", "arm", "arm64"]
go-arch: ["amd64", "arm64"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23.4"
check-latest: true
- uses: technote-space/[email protected]
id: git_diff
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23.4"
check-latest: true
- uses: technote-space/[email protected]
id: git_diff
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rosetta-cli-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '^1.22'
go-version: '^1.23.4'
- name: Run make test-rosetta-ci
run:
COSMOS_SDK_VERSION=v0.50.3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23.4"
check-latest: true
cache: true
cache-dependency-path: go.sum
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Improvements

* [180](https://github.com/cosmos/rosetta/pull/180) Update to cosmos-sdk v0.52.0-rc.1.
* [180](https://github.com/cosmos/rosetta/pull/180) Added bech32 prefix flag.

## [v0.50.11](https://github.com/cosmos/rosetta/releases/tag/v0.50.11) 2024-12-19

### Improvements
Expand Down
21 changes: 15 additions & 6 deletions client_online.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import (
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"

bank "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/codec/address"
sdk "github.com/cosmos/cosmos-sdk/types"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"

crgerrs "github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
Expand All @@ -35,7 +37,6 @@ var _ crgtypes.Client = (*Client)(nil)

const (
defaultNodeTimeout = time.Minute
tmWebsocketPath = "/websocket"
)

// Client implements a single network client to interact with cosmos based chains
Expand All @@ -61,8 +62,16 @@ func NewClient(cfg *Config) (*Client, error) {
if v == "" {
v = "unknown"
}
ac, err := address.NewCachedBech32Codec(cfg.Bech32Prefix, address.CachedCodecOptions{})
if err != nil {
return nil, err
}
vc, err := address.NewCachedBech32Codec(sdk.GetBech32PrefixValAddr(cfg.Bech32Prefix), address.CachedCodecOptions{})
if err != nil {
return nil, err
}

txConfig := authtx.NewTxConfig(cfg.Codec, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cfg.Codec, ac, vc, authtx.DefaultSignModes)

var supportedOperations []string
for _, ii := range cfg.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) {
Expand Down Expand Up @@ -101,7 +110,7 @@ func (c *Client) Bootstrap() error {
return crgerrs.WrapError(crgerrs.ErrOnlineClient, fmt.Sprintf("dialing grpc endpoint %s", err.Error()))
}

tmRPC, err := http.New(c.config.TendermintRPC, tmWebsocketPath)
tmRPC, err := http.New(c.config.TendermintRPC)
if err != nil {
return crgerrs.WrapError(crgerrs.ErrOnlineClient, fmt.Sprintf("getting rpc path %s", err.Error()))
}
Expand Down Expand Up @@ -488,7 +497,7 @@ func (c *Client) blockTxs(ctx context.Context, height *int64) (crgtypes.BlockTra
return crgtypes.BlockTransactionsResponse{}, crgerrs.WrapError(crgerrs.ErrOnlineClient, fmt.Sprintf("getting rpc block results %s", err.Error()))
}

if len(blockResults.TxsResults) != len(blockInfo.Block.Txs) {
if len(blockResults.TxResults) != len(blockInfo.Block.Txs) {
return crgtypes.BlockTransactionsResponse{}, crgerrs.WrapError(crgerrs.ErrOnlineClient, "block results transactions do now match block transactions")
}
// process begin and end block txs
Expand All @@ -503,7 +512,7 @@ func (c *Client) blockTxs(ctx context.Context, height *int64) (crgtypes.BlockTra
deliverTx := make([]*rosettatypes.Transaction, len(blockInfo.Block.Txs))
// process normal txs
for i, tx := range blockInfo.Block.Txs {
rosTx, err := c.converter.ToRosetta().Tx(tx, blockResults.TxsResults[i])
rosTx, err := c.converter.ToRosetta().Tx(tx, blockResults.TxResults[i])
if err != nil {
return crgtypes.BlockTransactionsResponse{}, crgerrs.WrapError(crgerrs.ErrOnlineClient, fmt.Sprintf("getting rosetta tx %s", err.Error()))
}
Expand Down
2 changes: 1 addition & 1 deletion codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rosetta
import (
"github.com/cosmos/gogoproto/proto"

bankcodec "cosmossdk.io/x/bank/types"
"cosmossdk.io/x/tx/signing"

"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -12,7 +13,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/types"
bankcodec "github.com/cosmos/cosmos-sdk/x/bank/types"
)

// MakeCodec generates the codec required to interact
Expand Down
9 changes: 9 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
FlagDenomToSuggest = "denom-to-suggest"
FlagPricesToSuggest = "prices-to-suggest"
FlagPlugin = "plugin"
FlagBech32Prefix = "bech32-prefix"
)

// Config defines the configuration of the rosetta server
Expand Down Expand Up @@ -102,6 +103,8 @@ type Config struct {
Codec *codec.ProtoCodec
// InterfaceRegistry overrides the default data and construction api interface registry
InterfaceRegistry codectypes.InterfaceRegistry
// Bech32Prefix defines the prefix used for bech32 addresses in the network.
Bech32Prefix string
}

// NetworkIdentifier returns the network identifier given the configuration
Expand Down Expand Up @@ -234,6 +237,10 @@ func FromFlags(flags *pflag.FlagSet) (*Config, error) {
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrConfig, fmt.Sprintf("while getting denomToSuggest flag %s", err.Error()))
}
bech32Prefix, err := flags.GetString(FlagBech32Prefix)
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrConfig, fmt.Sprintf("while getting bech32Prefix flag %s", err.Error()))
}

var prices sdk.DecCoins
if enableDefaultFeeSuggestion {
Expand All @@ -259,6 +266,7 @@ func FromFlags(flags *pflag.FlagSet) (*Config, error) {
GasToSuggest: gasToSuggest,
DenomToSuggest: denomToSuggest,
GasPrices: prices,
Bech32Prefix: bech32Prefix,
}
err = conf.validate()
if err != nil {
Expand Down Expand Up @@ -305,4 +313,5 @@ func SetFlags(flags *pflag.FlagSet) {
flags.String(FlagDenomToSuggest, DenomToSuggest, "default denom for fee suggestion")
flags.String(FlagPricesToSuggest, DefaultPrices, "default prices for fee suggestion")
flags.String(FlagPlugin, "", "plugin folder name")
flags.String(FlagBech32Prefix, "cosmos", "address bech32 prefix")
}
6 changes: 3 additions & 3 deletions converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
sdkmath "cosmossdk.io/math"
banktypes "cosmossdk.io/x/bank/types"

sdkclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -26,7 +27,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

crgerrs "github.com/cosmos/rosetta/lib/errors"
crgtypes "github.com/cosmos/rosetta/lib/types"
Expand Down Expand Up @@ -161,7 +161,7 @@ func (c converter) UnsignedTx(ops []*rosettatypes.Operation) (tx authsigning.Tx,
return nil, crgerrs.WrapError(crgerrs.ErrCodec, err.Error())
}

signers, _, err := c.cdc.GetMsgV1Signers(msg)
signers, _, err := c.cdc.GetMsgSigners(msg)
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrConverter, fmt.Sprintf("while getting msg signers %s", err.Error()))
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func (c converter) Ops(status string, msg sdk.Msg) ([]*rosettatypes.Operation, e
return nil, crgerrs.WrapError(crgerrs.ErrConverter, fmt.Sprintf("while getting meta from message %s", err.Error()))
}

signers, _, err := c.cdc.GetMsgV1Signers(msg)
signers, _, err := c.cdc.GetMsgSigners(msg)
if err != nil {
return nil, crgerrs.WrapError(crgerrs.ErrConverter, fmt.Sprintf("while getting msg signers in Ops %s", err.Error()))
}
Expand Down
22 changes: 13 additions & 9 deletions converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
"github.com/stretchr/testify/suite"

bank "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/cosmos/rosetta"
crgerrs "github.com/cosmos/rosetta/lib/errors"
Expand All @@ -41,7 +43,7 @@ func (s *ConverterTestSuite) SetupTest() {
s.unsignedTxBytes = unsignedTxBytes
// instantiate converter
cdc, ir := rosetta.MakeCodec()
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
txConfig := authtx.NewTxConfig(cdc, address.NewBech32Codec("cosmos"), address.NewBech32Codec("cosmosvaloper"), authtx.DefaultSignModes)
s.c = rosetta.NewConverter(cdc, ir, txConfig)
// add utils
s.ir = ir
Expand Down Expand Up @@ -132,7 +134,7 @@ func (s *ConverterTestSuite) TestMsgToMetaMetaToMsg() {
func (s *ConverterTestSuite) TestSignedTx() {
s.Run("success", func() {
const payloadsJSON = `[{"hex_bytes":"82ccce81a3e4a7272249f0e25c3037a316ee2acce76eb0c25db00ef6634a4d57303b2420edfdb4c9a635ad8851fe5c7a9379b7bc2baadc7d74f7e76ac97459b5","signing_payload":{"address":"cosmos147klh7th5jkjy3aajsj2rqvhtvh9mfde37wq5g","hex_bytes":"ed574d84b095250280de38bf8c254e4a1f8755e5bd300b1f6ca2671688136ecc","account_identifier":{"address":"cosmos147klh7th5jkjy3aajsj2rqvhtvh9mfde37wq5g"},"signature_type":"ecdsa"},"public_key":{"hex_bytes":"034c92046950c876f4a5cb6c7797d6eeb9ef80d67ced4d45fb62b1e859240ba9ad","curve_type":"secp256k1"},"signature_type":"ecdsa"}]`
const expectedSignedTxHex = "0a8e010a8b010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126b0a2d636f736d6f733134376b6c68377468356a6b6a793361616a736a3272717668747668396d666465333777713567122d636f736d6f73316d6e7670386c786b616679346c787777617175356561653764787630647a36687767797436331a0b0a057374616b651202313612620a4e0a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21034c92046950c876f4a5cb6c7797d6eeb9ef80d67ced4d45fb62b1e859240ba9ad12040a02087f12100a0a0a057374616b651201311090a10f1a4082ccce81a3e4a7272249f0e25c3037a316ee2acce76eb0c25db00ef6634a4d57303b2420edfdb4c9a635ad8851fe5c7a9379b7bc2baadc7d74f7e76ac97459b5"
const expectedSignedTxHex = "0a9b010a8b010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126b0a2d636f736d6f733134376b6c68377468356a6b6a793361616a736a3272717668747668396d666465333777713567122d636f736d6f73316d6e7670386c786b616679346c787777617175356561653764787630647a36687767797436331a0b0a057374616b65120231362a0b088092b8c398feffffff011291010a4e0a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21034c92046950c876f4a5cb6c7797d6eeb9ef80d67ced4d45fb62b1e859240ba9ad12040a02087f123f0a0a0a057374616b651201311090a10f1a2d636f736d6f733134376b6c68377468356a6b6a793361616a736a3272717668747668396d6664653337777135671a4082ccce81a3e4a7272249f0e25c3037a316ee2acce76eb0c25db00ef6634a4d57303b2420edfdb4c9a635ad8851fe5c7a9379b7bc2baadc7d74f7e76ac97459b5"

var payloads []*rosettatypes.Signature
s.Require().NoError(json.Unmarshal([]byte(payloadsJSON), &payloads))
Expand Down Expand Up @@ -288,14 +290,16 @@ func (s *ConverterTestSuite) TestBalanceOps() {

// TODO - Investigate / fix sdk update discrepancies
s.Run("multiple balance ops from 2 multicoins event", func() {
subBalanceOp := bank.NewCoinSpentEvent(
sdk.AccAddress("test"),
sdk.NewCoins(sdk.NewInt64Coin("test", 10), sdk.NewInt64Coin("utxo", 10)),
subBalanceOp := sdk.NewEvent(
bank.EventTypeCoinSpent,
sdk.NewAttribute(bank.AttributeKeySpender, sdk.AccAddress("test").String()), // TODO remove string address
sdk.NewAttribute(sdk.AttributeKeyAmount, sdk.NewCoins(sdk.NewInt64Coin("test", 10), sdk.NewInt64Coin("utxo", 10)).String()),
)

addBalanceOp := bank.NewCoinReceivedEvent(
sdk.AccAddress("test"),
sdk.NewCoins(sdk.NewInt64Coin("test", 10), sdk.NewInt64Coin("utxo", 10)),
addBalanceOp := sdk.NewEvent(
bank.EventTypeCoinReceived,
sdk.NewAttribute(bank.AttributeKeyReceiver, sdk.AccAddress("test").String()), // TODO: remove string address
sdk.NewAttribute(sdk.AttributeKeyAmount, sdk.NewCoins(sdk.NewInt64Coin("test", 10), sdk.NewInt64Coin("utxo", 10)).String()),
)

ops := s.c.ToRosetta().BalanceOps("", []abci.Event{(abci.Event)(subBalanceOp), (abci.Event)(addBalanceOp)})
Expand Down
Loading

0 comments on commit a10cbc6

Please sign in to comment.