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

ADR 35: Rosetta API Support #7492

Merged
merged 95 commits into from
Nov 6, 2020
Merged
Changes from 82 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
b21ce41
adr rosetta support
jgimeno Oct 9, 2020
969c4c9
Use ADR 33.
jgimeno Oct 9, 2020
a46fbeb
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
1ee3307
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
95eabea
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
52493b6
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
ebe39fb
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
30380bf
Merge branch 'master' into jonathan/rosetta-adr
jgimeno Oct 9, 2020
5afa87e
Update docs/architecture/adr-030-rosetta-api-support.md
Oct 9, 2020
b6f3885
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
dc35d65
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
3f38486
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
52c5ed9
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
b4f6d63
Update docs/architecture/adr-030-rosetta-api-support.md
Oct 9, 2020
8943388
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
a879351
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
2c5241e
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
6b8d899
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
2d34cb7
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
818c5bf
Update docs/architecture/adr-030-rosetta-api-support.md
jgimeno Oct 9, 2020
b94d785
Rename ADR num.
jgimeno Oct 9, 2020
b61dafb
Merge branch 'master' into jonathan/rosetta-adr
Oct 9, 2020
7921d5c
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 9, 2020
2f4836c
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 9, 2020
33b35bd
Move points.
jgimeno Oct 9, 2020
d784100
Merge branch 'jonathan/rosetta-adr' of github.com:cosmos/cosmos-sdk i…
jgimeno Oct 9, 2020
987addc
Merge branch 'master' into jonathan/rosetta-adr
Oct 9, 2020
a0562d2
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 9, 2020
26e3e67
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 9, 2020
91602d6
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 10, 2020
4cef432
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 10, 2020
1eff674
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 10, 2020
244150f
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 10, 2020
be43346
Merge branch 'master' into jonathan/rosetta-adr
Oct 10, 2020
2cb2ef5
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 10, 2020
436aeb8
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 10, 2020
e86321e
Merge branch 'master' into jonathan/rosetta-adr
jgimeno Oct 11, 2020
6316058
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
45c5f8e
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
b50eec1
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
9e0c956
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
16239c4
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
f9a362d
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
d95157c
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
2bc1c4f
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
60ed224
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
bb874b4
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
1b86983
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
cb9062e
Merge branch 'master' into jonathan/rosetta-adr
Oct 12, 2020
942daf0
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
e73bb03
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 12, 2020
8e06e7c
Update docs/architecture/adr-035-rosetta-api-support.md
jgimeno Oct 14, 2020
39e5178
Update docs/architecture/adr-035-rosetta-api-support.md
jgimeno Oct 14, 2020
bc244fc
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 14, 2020
e52a693
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 14, 2020
609aab3
Update ADR.
jgimeno Oct 16, 2020
91e7199
Merge branch 'master' into jonathan/rosetta-adr
Oct 16, 2020
ce2e7e9
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 16, 2020
3e4674a
Update docs/architecture/adr-035-rosetta-api-support.md
jgimeno Oct 16, 2020
eca8545
Apply suggestions from code review
Oct 16, 2020
8b9371e
Update docs/architecture/adr-035-rosetta-api-support.md
jgimeno Oct 19, 2020
e94e337
Update docs/architecture/adr-035-rosetta-api-support.md
jgimeno Oct 19, 2020
7f01ec0
Update AddrPrefix to Bech32Prefix.
jgimeno Oct 19, 2020
79786dc
Merge branch 'jonathan/rosetta-adr' of github.com:cosmos/cosmos-sdk i…
jgimeno Oct 19, 2020
ac49826
Add why to interfaces section.
jgimeno Oct 19, 2020
772ef08
Update docs/architecture/adr-035-rosetta-api-support.md
jgimeno Oct 20, 2020
ca2b7d3
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 23, 2020
31a7e1a
Remove unneeded Bech32 prefix.
jgimeno Oct 26, 2020
2816b06
Merge branch 'jonathan/rosetta-adr' of github.com:cosmos/cosmos-sdk i…
jgimeno Oct 26, 2020
387a0bd
Change status.
jgimeno Oct 27, 2020
3ab45fd
update adr
jgimeno Oct 27, 2020
af5ae37
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 28, 2020
f992a96
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 28, 2020
64cce9d
Update docs/architecture/adr-035-rosetta-api-support.md
Oct 28, 2020
ccf5385
Update ADR.
jgimeno Oct 28, 2020
8e3ffa4
Merge branch 'jonathan/rosetta-adr' of github.com:cosmos/cosmos-sdk i…
jgimeno Oct 28, 2020
231530f
Merge branch 'master' into jonathan/rosetta-adr
Oct 29, 2020
5407ba3
Merge branch 'master' into jonathan/rosetta-adr
jgimeno Oct 30, 2020
b63c6e9
Merge branch 'master' into jonathan/rosetta-adr
Oct 30, 2020
7802404
Merge branch 'master' into jonathan/rosetta-adr
Oct 30, 2020
d663270
Merge branch 'master' into jonathan/rosetta-adr
Nov 4, 2020
d207329
Merge branch 'master' into jonathan/rosetta-adr
Nov 5, 2020
a9c0de7
Update docs/architecture/adr-035-rosetta-api-support.md
Nov 5, 2020
0bc99ed
Update docs/architecture/adr-035-rosetta-api-support.md
Nov 5, 2020
573b3c3
pseudo code for adapter interface
jgimeno Nov 5, 2020
22efc7e
update pseudo code
jgimeno Nov 5, 2020
3ea1a2a
remove changes go mod
jgimeno Nov 5, 2020
82c632d
remove changes go mod
jgimeno Nov 5, 2020
9cd9af0
Add golang.
jgimeno Nov 5, 2020
40ba26b
Merge branch 'master' into jonathan/rosetta-adr
Nov 5, 2020
eb5cbf4
Merge branch 'master' into jonathan/rosetta-adr
Nov 6, 2020
6d986a3
update README.md
Nov 6, 2020
db073c4
Merge branch 'master' into jonathan/rosetta-adr
Nov 6, 2020
73793ef
Update docs/architecture/adr-035-rosetta-api-support.md
Nov 6, 2020
e961cab
Update docs/architecture/adr-035-rosetta-api-support.md
Nov 6, 2020
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
238 changes: 238 additions & 0 deletions docs/architecture/adr-035-rosetta-api-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# ADR 035: Rosetta API Support

alessio marked this conversation as resolved.
Show resolved Hide resolved
## Context

[Rosetta API](https://www.rosetta-api.org/) is an open-source specification and set of tools developed by Coinbase to
standardise blockchain interactions.

Through the use of a standard API for integrating blockchain applications it will

* Be easier for a user to interact with a given blockchain
* Allow exchanges to integrate new blockchains quickly and easily
* Enable application developers to build cross-blockchain applications such as block explorers, wallets and dApps at
considerably lower cost and effort.

## Decision

It is clear that adding Rosetta API support to the Cosmos SDK will bring value to all the developers and
Cosmos SDK based chains in the ecosystem. How it is implemented is key.

The driving principles of the proposed design are:

1. **Extensibility:** it must be as riskless and painless as possible for application developers to set-up network
configurations to expose Rosetta API-compliant services.
2. **Long term support:** This proposal aims to provide support for all the supported Cosmos SDK release series.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
3. **Cost-efficiency:** Backporting changes to Rosetta API specifications from `master` to the various stable
branches of Cosmos SDK is a cost that needs to be reduced.

We will achieve these delivering on these principles by the following:

1. There will be an external repo called [cosmos-rosetta-gateway](https://github.com/tendermint/cosmos-rosetta-gateway)
for the implementation of the core Rosetta API features, particularly:
a. The types and interfaces. This separates design from implementation detail.
b. Some core implementations: specifically, the `Service` functionality as this is independent of the Cosmos SDK version.
2. Due to differences between the Cosmos release series, each series will have its own specific API implementations of `Network` struct and `Adapter` interface.
3. There will be two options for starting an API service in applications:
a. API shares the application process
b. API-specific process.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved


## Architecture

### The External Repo

As section will describe the proposed external library, including the service implementation, plus the defined types and interfaces.

#### Service

`Service` is a simple `struct` that is started and listens to the port specified in the options. This is meant to be used across all the Cosmos SDK versions that are actively supported.

The constructor follows:

`func New(options Options, network Network) (*Service, error)`

#### Types

`Service` accepts an `Options` `struct` that holds service configuration values, such as the port the service would be listening to:

```golang
type Options struct {
ListenAddress string
}
```

The `Network` type holds network-specific properties (i.e. configuration values) and adapters. Pre-configured concrete types will be available for each Cosmos SDK release. Applications can also create their own custom types.

```golang
type Network struct {
Properties rosetta.NetworkProperties
Adapter rosetta.Adapter
}
```

A `NetworkProperties` `struct` comprises basic values that are required by a Rosetta API `Service`:

```golang
type NetworkProperties struct {
// Mandatory properties
Blockchain string
Network string
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
SupportedOperations []string
}
```

Rosetta API services use `Blockchain` and `Network` as identifiers, e.g. the developers of _gaia_, the application that powers the Cosmos Hub, may want to set those to `Cosmos Hub` and `cosmos-hub-3` respectively.

`SupportedOperations` contains the transaction types that are supported by the library. At the present time,
only `cosmos-sdk/MsgSend` is supported in Launchpad. Additional operations will be added in due time.

For Launchpad we will map the amino type name to the operation supported, in Stargate we will use the protoc one.

#### Interfaces

Every SDK version uses a different format to connect (rpc, gRpc, etc), we have abstracted this in what is called the
Adapter. This is an interface that defines the methods an adapter implementation must provide in order to be used
in the `Network` interface.

Each Cosmos SDK release series will have their own Adapter implementations.
Developers can implement their own custom adapters as required.

```golang
type Adapter interface {
DataAPI
ConstructionAPI
}

type DataAPI interface {
server.NetworkAPIServicer
server.AccountAPIServicer
server.MempoolAPIServicer
server.BlockAPIServicer
server.ConstructionAPIServicer
}

type ConstructionAPI interface {
server.ConstructionAPIServicer
alessio marked this conversation as resolved.
Show resolved Hide resolved
}
```

alessio marked this conversation as resolved.
Show resolved Hide resolved
### 2. Cosmos SDK Implementation

As described, each Cosmos SDK release series will have version specific implementations of `Network` and `Adapter`, as
well as a `NewNetwork` constructor.

Due to separation of interface and implementation, application developers have the option to override as needed,
using this code as reference.

```golang
// NewNetwork returns the default application configuration.

alessio marked this conversation as resolved.
Show resolved Hide resolved
func NewNetwork(options Options) service.Network {
cosmosClient := cosmos.NewClient(fmt.Sprintf("http://%s", options.CosmosEndpoint))
tendermintClient := tendermint.NewClient(fmt.Sprintf("http://%s", options.TendermintEndpoint))

return service.Network{
Comment on lines +166 to +170
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diverges from the constructor defined above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgimeno bump

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronc True that, yet this is an example, i.e. the actual code would diverge slightly between 0.39 and 0.40 - as described in the comment above: each Cosmos SDK release series will have version specific implementations of Network and Adapter, as well as a NewNetwork constructor.

For instance, that's the signature of this very constructor for Stargate:

NewNetwork(cdc codec.BinaryMarshaler, options Options) service.Network

The constructor's signature for Launchpad follows:

NewNetwork(cdc *codec.Codec, options Options) service.Network

I hope this helps.

Properties: rosetta.NetworkProperties{
Blockchain: options.Blockchain,
Network: options.Network,
SupportedOperations: []string{OperationTransfer},
},
Adapter: newAdapter(
cosmosClient,
tendermintClient,
properties{
Blockchain: options.Blockchain,
Network: options.Network,
OfflineMode: options.OfflineMode,
},
),
Comment on lines +176 to +184
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an example of the adapter that should be linked to in this ADR for reference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgimeno bump

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the one for launchpad, but is in a branch and not merged yet. Is that ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, go ahead @jgimeno. Use a permalink

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func newAdapter(cdc *codec.Codec, cosmos SdkClient, tendermint TendermintClient, options properties) rosetta.Adapter {

This is the adapter constructor in the launchpad implementation, but the implementation itself is based in several files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The team is finalising the Stargate's Adapter implementation. I think we can show some simplified code example here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not have to be complete - this is an ADR after all, not a code walkthrough. Either some pseudo code or a code snippet should it.

}
}
```

### 3. API service invocation

As stated at the start, application developers will have two methods for invocation of the Rosetta API service:

1. Shared process for both application and API
2. Standalone API service

#### Shared Process (Only Stargate)

Rosetta API service could run within the same execution process as the application. New configuration option and
command line flags would be provided to support this:

```golang
if config.Rosetta.Enable {
....
get contecxt, flags, etc
...

h, err := service.New(
service.Options{ListenAddress: config.Rosetta.ListenAddress},
rosetta.NewNetwork(cdc, options),
)
if err != nil {
}

...

go func() {
if err := h.Start(config); err != nil {
errCh <- err
}
}()
}

```

#### Separate API service

Client application developers can write a new command to launch a Rosetta API server as a separate process too:

```golang
func RosettaCommand(cdc *codec.Codec) *cobra.Command {

...
cmd := &cobra.Command{
Use: "rosetta",
....

RunE: func(cmd *cobra.Command, args []string) error {
....
get contecxt, flags, etc
...

h, err := service.New(
service.Options{Endpoint: endpoint},
rosetta.NewNetwork(cdc, options),
)
if err != nil {
return err
}

...

h.Start()
}
}
...

}
```

## Status

Proposed

## Consequences

### Positive

- Out-of-the-box Rosetta API support within Cosmos SDK.
- Blockchain interface standardisation

## References

- https://www.rosetta-api.org/
- https://github.com/tendermint/cosmos-rosetta-gateway