Git Product home page Git Product logo

rosetta's Introduction

Rosetta

The rosetta project implements Coinbase's Rosetta API. This document provides instructions on how to use the Rosetta API integration. For information about the motivation and design choices, refer to ADR 035.

Installing Rosetta

The Rosetta API server is a stand-alone server that connects to a node of a chain developed with Cosmos SDK.

Rosetta can be added to any cosmos chain node. standalone or natively.

Standalone

Rosetta can be executed as a standalone service, it connects to the node endpoints and expose the required endpoints.

Install Rosetta standalone server with the following command:

go install github.com/cosmos/rosetta

Alternatively, for building from source, simply run make build. The binary will be located in the root folder.

Native - As a node command

To enable Native Rosetta API support, it's required to add the RosettaCommand to your application's root command file (e.g. simd/cmd/root.go).

Import the rosettaCmd package:

import "github.com/cosmos/rosetta/cmd"

Find the following line:

initRootCmd(rootCmd, encodingConfig)

After that line, add the following:

rootCmd.AddCommand(
  rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec)
)

The RosettaCommand function builds the rosetta root command and is defined in the rosettaCmd package (github.com/cosmos/rosetta/cmd).

Since we’ve updated the Cosmos SDK to work with the Rosetta API, updating the application's root command file is all you need to do.

An implementation example can be found in simapp package.

Use Rosetta Command

To run Rosetta in your application CLI, use the following command:

Note: if using the native approach, add your node name before any rosetta comand.

rosetta --help

To test and run Rosetta API endpoints for applications that are running and exposed, use the following command:

rosetta
     --blockchain "your application name (ex: gaia)"
     --network "your chain identifier (ex: testnet-1)"
     --tendermint "tendermint endpoint (ex: localhost:26657)"
     --grpc "gRPC endpoint (ex: localhost:9090)"
     --addr "rosetta binding address (ex: :8080)"
     --grpc-types-server (optional) "gRPC endpoint for message descriptor types"

Plugins - Multi chain connections

Rosetta will try to reflect the node types trough reflection over the node gRPC endpoints, there may be cases were this approach is not enough. It is possible to extend or implement the required types easily trough plugins.

To use Rosetta over any chain, it is required to set up prefixes and registering zone specific interfaces through plugins.

Each plugin is a minimalist implementation of InitZone and RegisterInterfaces which allow Rosetta to parse chain specific data. There is an example for cosmos-hub chain under plugins/cosmos-hun/ folder

  • InitZone: An empty method that is executed first and defines prefixes, parameters and other settings.
  • RegisterInterfaces: This method receives an interface registry which is were the zone specific types and interfaces will be loaded

In order to add a new plugin:

  1. Create a folder over plugins folder with the name of the desired zone
  2. Add a main.go file with the mentioned methods above.
  3. Build the code binary through go build -buildmode=plugin -o main.so main.go

The plugin folder is selected through the cli --plugin flag and loaded into the Rosetta server.

Extensions

There are two ways in which you can customize and extend the implementation with your custom settings.

Message extension

In order to make an sdk.Msg understandable by rosetta the only thing which is required is adding the methods to your messages that satisfy the rosetta.Msg interface. Examples on how to do so can be found in the staking types such as MsgDelegate, or in bank types such as MsgSend.

Client interface override

In case more customization is required, it's possible to embed the Client type and override the methods which require customizations.

Example:

package custom_client
import (

"context"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/cosmos/rosetta/lib"
)

// CustomClient embeds the standard cosmos client
// which means that it implements the cosmos-rosetta-gateway Client
// interface while at the same time allowing to customize certain methods
type CustomClient struct {
    *rosetta.Client
}

func (c *CustomClient) ConstructionPayload(_ context.Context, request *types.ConstructionPayloadsRequest) (resp *types.ConstructionPayloadsResponse, err error) {
    // provide custom signature bytes
    panic("implement me")
}

NOTE: when using a customized client, the command cannot be used as the constructors required may differ, so it's required to create a new one. We intend to provide a way to init a customized client without writing extra code in the future.

Error extension

Since rosetta requires to provide 'returned' errors to network options. In order to declare a new rosetta error, we use the errors package in cosmos-rosetta-gateway.

Example:

package custom_errors
import crgerrs "github.com/cosmos/rosetta/lib/errors"

var customErrRetriable = true
var CustomError = crgerrs.RegisterError(100, "custom message", customErrRetriable, "description")

Note: errors must be registered before cosmos-rosetta-gateway's Server.Start method is called. Otherwise the registration will be ignored. Errors with same code will be ignored too.

rosetta's People

Contributors

bizk avatar dependabot[bot] avatar juliantoledano avatar lucaslopezf avatar tac0turtle avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rosetta's Issues

[Feature]: Improve error handling

Summary

Improve erorr messages and add missing error handling

Problem Definition

The repository error handling is not standardized, and it can be improved in some areas as on converter.go.

[Feature]: Improve CI-Tests

Summary

Add tests using the rosetta-cli against a running node like simapp.

Problem Definition

The repository is lacking CI tests against a sample node, this improves the quality of life of the code, reducing risk of failure on new features/updates

[Bug]: Builds fail due to dependency conflict with cosmossdk.io/core v0.11.0 -> v0.12.0 comet.BlockInfo -> comet.Info symbol rename

Summary of Bug

Applications which link in Cosmos SDK 0.50.3 with Rosetta 0.50.3 fail to build due to comet.BlockInfo -> comet.Info symbol rename in cosmossdk.io/core package.

# github.com/cosmos/cosmos-sdk/types
../types/context.go:65:29: undefined: comet.BlockInfo
../types/context.go:92:36: undefined: comet.BlockInfo
../types/context.go:300:48: undefined: comet.BlockInfo
make: *** [build] Error 1

Cosmos SDK in both 0.50.2 and 0.50.3 both link against cosmossdk.io/core v0.11.0 while Rosetta 0.50.3 links against github.com/cosmos/cosmos-sdk v0.53.0 and cosmossdk.io/core v0.12.0.

Version

0.50.2 and 0.50.3

Steps to Reproduce

Create any app which links both Cosmos SDK 0.50.3 and Rosetta 0.50.3 and attempt to build it.

Work around is to force a replace rule downgrading to v0.11.0 in go.mod like:

replace cosmossdk.io/core => cosmossdk.io/core v0.11.0

[Bug]: /block request ends with error

Summary of Bug

A request to block endpoint results in the following error:

{
  "code": 171,
  "message": "error on online client operation",
  "description": "returned when there is an error with the client",
  "retriable": false,
  "details": {
    "info": "getting block transactions by height rosetta: (171) error on online client operation"
  }
}

Version

main

Steps to Reproduce

curl localhost:8080/block -d '{ "network_identifier":{"network":"network","blockchain": "app"}, "block_identifier":{"index":$BLOCK}}' | jq

[Feature]: Docker image

Summary

It is beneficial for the project to have a docker image that can be used by the users and developers. Making it easy to deploy and lowering the adoption bar.

Problem Definition

The following reasons to use a docker container:

  • Isolation: Docker containers provide a controlled environment for applications. The image ensures that all required dependencies and tools are packaged together, reducing compatibility issues.
  • Portability: Docker images are portable across different environments. Making it easier to deploy and run the Rosetta service consistently on various platforms without worrying about misconfiguration or dependency issues.

Problems addressed:

  • Ease of Deployment: Having a container makes setting up and using Rosetta easier across all platforms.
  • E2E and integration testing: It allows us to make better and meaningful E2E/integration tests.

Benefits for the SDK:

  • Simplified Setup: Anyone who desires to use Rosetta can use it as a plug and play through docker.

Proposal

Create a docker image that builds rosetta and it's default plugin. And add a the respective github workflow

[Bug]: can't connect to a node over https

Summary of Bug

When setting up rosetta agains cometbft using https the following error happens:

  • ERR [Rosetta]- Client is not ready. Retrying ... error="rosetta: (171) error on online client operation" module=rosetta

While debugging the complete request response is:

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>cloudflare</center>
</body>
</html>

Version

main

Steps to Reproduce

./rosetta --tendermint https://cosmos-testnet-rpc.polkachu.com:443 --grpc cosmos-testnet-grpc.polkachu.com:14990

[Feature]: Update cosmos-sdk to v0.50 release

Summary

Update cosmos-sdk dependency and usage to v0.50 release

Problem Definition

In order to stay up to date with the latest updates and features of cosmos ecosystem, rosetta should follow the release cycle.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.