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 2 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
225 changes: 225 additions & 0 deletions docs/architecture/adr-030-rosetta-api-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# ADR 033: Rosetta API support
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

## Context

Rosetta API, an open-source specification and set of tools developed by Coinbase, makes integration with blockchains simpler, faster, and more reliable by establishing a standard API for integrating blockchain applications.

By using a common interface that standardizes the process of how a user interacts with a blockchain, both the work of exchanges to integrate with new blockchains and also of the developers to build cross-blockchain applications such as block explorers, wallets and dApps is considerably reduced.

We think that providing Rosetta support to the Cosmos SDK will add value to all the developers and Cosmos SDK based chains in the ecosystem.

## Decision


The service is structured in a way that:

1. It becomes easy to inject different implementations for different types of SDK. For this abstraction we have used the term Adapter.
2. Due to the nature of versioning that has been done with Cosmos SDK so far it becomes very difficult to have different SDK versions included in the same repo, for that we created a generic shared code that includes the Service and the Adapter interface.
3. It is easy to inject and instantiate wherever is needed in the different applications.


## Architecture


### Service

The Service is just an struct that is started and listens to the port specified in the options. This is commonly used for all the SDK versions supported.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

To construct one we can call the constructor:
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

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

It accepts an options struct that only holds the port to listen to:
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

```
type Options struct {
Port uint32
}
```

And a Network struct. This struct is the one that is specific to every SDK version, or even a network specific that the generic SDK does not cover all their needs.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

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

The properties struct is needed in order to run the Service, these are options that are mandatory and are related to Rosetta specific properties.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

```
type NetworkProperties struct {
// Mandatory properties
Blockchain string
Network string
AddrPrefix string
SupportedOperations []string
}
```

The `Blockchain` and `Network` are the ones that Rosetta uses to label the networks that the API supports, for example, if we were implementing a Bitcoin API Rosetta blockchain would be "Bitcoin" and network could be "mainnet", etc.
alessio marked this conversation as resolved.
Show resolved Hide resolved

The `AddrPrefix` is specific to the nature of cosmos type addresses. Because a network can have a different type of address we need to provide it, for example for IOV it would be "star" and for cosmos hub would be "cosmos".
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

And the `SupportedOperations` is related to Rosetta, these are the operations the API supports. An operation can be a `Transfer`, `Delegation`, etc. For now we only support one type of operation, `Transfer`.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

The other important thing that the Network holds is the Adapter interface. This interface is the specific implementation for every cosmos version.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

And adapter must satisfy the interface:

alessio marked this conversation as resolved.
Show resolved Hide resolved
```
type Adapter interface {
DataAPI
ConstructionAPI
}

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

type ConstructionAPI interface {
server.ConstructionAPIServicer
}

````

### How to use it in the Cosmos SDK.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

The best way to do it would be that every Cosmos SDK version holds the implementation of the Network struct, this can be an example located in the Cosmos SDK Launchpad version.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

```
// NewLaunchpadNetwork returns a configured network to work in a Launchpad version.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
func NewLaunchpadNetwork(options Options) service.Network {
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
cosmosClient := cosmos.NewClient(fmt.Sprintf("http://%s", options.CosmosEndpoint))
tendermintClient := tendermint.NewClient(fmt.Sprintf("http://%s", options.TendermintEndpoint))

return service.Network{
Properties: rosetta.NetworkProperties{
Blockchain: options.Blockchain,
Network: options.Network,
SupportedOperations: []string{OperationTransfer},
},
Adapter: newAdapter(
cosmosClient,
tendermintClient,
properties{
Blockchain: options.Blockchain,
Network: options.Network,
AddrPrefix: options.AddrPrefix,
OfflineMode: options.OfflineMode,
},
),
}
}
```

As we see we hold not only the instantiation of a Launchpad specific network but the adapter implementation too. As the way to talk to different rpc endpoint change between different versions (Launchpad, Stargate, etc), makes sense to keep it in their respective branches.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

In this way we could have two options (yet to decide) that we can expose rosetta in the cosmos SDK.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In this way we could have two options (yet to decide) that we can expose rosetta in the cosmos SDK.

#### Embedding it in the Start command.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved

This will look more like the approach the API in cosmos works: [link](https://github.com/cosmos/cosmos-sdk/blob/ca7b31dd5d23b10a919de1a60bbac90e89c5bf78/server/start.go#L248).
Copy link
Contributor

Choose a reason for hiding this comment

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

Rosetta API service could run within the same execution process of the application; new configuration option and command line flag would be provided:


So we can add something like:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
So we can add something like:


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

h, err := service.New(
service.Options{Port: uint32(*flagPort)},
launchpad.NewLaunchpadNetwork(launchpad.Options{
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
CosmosEndpoint: *flagAppRPC,
TendermintEndpoint: *flagTendermintRPC,
Blockchain: *flagBlockchain,
Network: *flagNetworkID,
AddrPrefix: *flagAddrPrefix,
OfflineMode: *flagOfflineMode,
}),
)
if err != nil {
}

...

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

```

#### The cobra command approach

This means providing a new command in order to run the service, an example can look something like:

```
func NewRosettaServiceCmd() *cobra.Command {

...
cmd := &cobra.Command{
Use: "vote [proposal-id] [option]",
....

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

h, err := service.New(
service.Options{Port: uint32(*flagPort)},
launchpad.NewLaunchpadNetwork(launchpad.Options{
CosmosEndpoint: *flagAppRPC,
TendermintEndpoint: *flagTendermintRPC,
Blockchain: *flagBlockchain,
Network: *flagNetworkID,
AddrPrefix: *flagAddrPrefix,
OfflineMode: *flagOfflineMode,
}),
)
if err != nil {
}

...

h.Start()
}
}
...

}
```

This is closer to the Standalone approach. Right now in the current implementation we have a main.go that can be run as a Standalone, this probably will be removed once we migrate the code from Tendermint repo an embed it in Cosmos SDK.


### The external Library

Because apart from the Network struct and Adapter implemention there is a lot of code that would be shared across versions, we can provide a repo for the Rosetta Service that will hold only the Service, the Interfaces and the types. This includes all that is not specific to a single version. (Still to decide if we keep an external shared dependency or not.)


## Status

Accepted

## Consequences

### Positive

- Provide out-of-the-box Rosetta interface just by using the Cosmos SDK.
- Contribute to the standarization of blockchain interfaces.

## References

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