Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 50 additions & 10 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,69 @@ on:

env:
GO_VERSION: 1.17
FLOW_GO_CRYPTO_VERSION: v0.25.0

jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: flow-rosetta

- name: Check out FlowGo
uses: actions/checkout@v2
with:
repository: onflow/flow-go
ref: ${{ env.FLOW_GO_CRYPTO_VERSION }}
path: flow-go

- name: Format
run: go fmt -l -d ./... && git status && git --no-pager diff && git diff-index --quiet HEAD --
run: |
cd flow-rosetta
go fmt ./... && git status && git --no-pager diff && git diff-index --quiet HEAD --

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: flow-rosetta

- name: Check out FlowGo
uses: actions/checkout@v2
with:
repository: onflow/flow-go
ref: ${{ env.FLOW_GO_CRYPTO_VERSION }}
path: flow-go

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3.1.0
with:
args: -v -E golint,misspell,gocyclo,gocritic,whitespace,goconst,bodyclose,unconvert,lll
version: v1.29
version: v1.30
working-directory: flow-rosetta

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: flow-rosetta

- name: Check out FlowGo
uses: actions/checkout@v2
with:
repository: onflow/flow-go
ref: c0afa789365eb7a22713ed76b8de1e3efaf3a70a
ref: ${{ env.FLOW_GO_CRYPTO_VERSION }}
path: flow-go

- name: Set up Go
Expand All @@ -61,6 +90,7 @@ jobs:
# https://grpc.io/docs/protoc-installation/#install-pre-compiled-binaries-any-os
- name: Install Protobuf compiler
run: |
cd flow-rosetta
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.17.3/protoc-3.17.3-linux-x86_64.zip
unzip protoc-3.17.3-linux-x86_64.zip -d $HOME/.local
Expand Down Expand Up @@ -91,30 +121,38 @@ jobs:
# This check makes sure that the `go.mod` and `go.sum` files for Go
# modules are always up-to-date.
- name: Verify Go modules
run: go mod tidy && git status && git --no-pager diff && git diff-index --quiet HEAD --
run: |
cd flow-rosetta
go mod tidy && git status && git --no-pager diff && git diff-index --quiet HEAD --

# This check makes sure that the generated protocol buffer files in Go
# have been updated in case there was a change in the definitions.
- name: Verify generated files
run: go generate ./... && git status && git --no-pager diff && git diff-index --quiet HEAD --
run: |
cd flow-rosetta
go generate ./... && git status && git --no-pager diff && git diff-index --quiet HEAD --

# This check makes sure that we can compile the binary as a pure Go binary
# without CGO support.
- name: Verify compilation
run: go build -tags relic ./...
run: |
cd flow-rosetta
go build -tags relic ./...

test:
name: Test/Coverage
needs: [ format, lint, build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: flow-rosetta

- name: Check out FlowGo
uses: actions/checkout@v2
with:
repository: onflow/flow-go
ref: c0afa789365eb7a22713ed76b8de1e3efaf3a70a
ref: ${{ env.FLOW_GO_CRYPTO_VERSION }}
path: flow-go

- name: Set up Go
Expand Down Expand Up @@ -144,10 +182,12 @@ jobs:
go generate .

- name: Check Coverage
run: make coverage
run: |
cd flow-rosetta
make coverage

- name: Upload Coverage HTMl artifact
uses: actions/upload-artifact@v2
with:
name: coverage-report
path: ./coverage/coverage.html
path: ./flow-rosetta/coverage/coverage.html
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/cmd/flow-rosetta-server/flow-rosetta-server
*.cdc
*.checkpoint
*.log
flow-go/
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.17 as builder
WORKDIR /app
COPY . .
RUN go build -o flow-rosetta ./cmd/flow-rosetta-server/main.go

FROM alpine
COPY --from=builder /app/flow-rosetta /app/flow-rosetta

RUN chmod +x /app/flow-rosetta
WORKDIR /app

EXPOSE 8080

CMD ["./rosetta-flow", "-c", "access-001.mainnet16.nodes.onflow.org:9000", "-p", "8080"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LINT_SETTINGS=golint,misspell,gocyclo,gocritic,whitespace,goconst,bodyclose,unco
all: lint format build

format:
gofmt -s -w -l .
gofmt -s -w .
goimports -w .

lint:
Expand Down
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In order to build the live binary, the following extra steps and dependencies ar

* [`CMake`](https://cmake.org/install/)

Please note that the flow-go repository should be cloned into this projects directory with its default name, so that the Go module replace statement works as intended: `replace github.com/onflow/flow-go/crypto => ./flow-go/crypto`.
Please note that the flow-go repository should be cloned into this projects parent directory with its default name, so that the Go module replace statement works as intended: `replace github.com/onflow/flow-go/crypto => ../flow-go/crypto`.

* `git clone git@github.com:onflow/flow-go.git`
* `cd flow-go/crypto`
Expand Down Expand Up @@ -48,16 +48,30 @@ The following command can be executed to validate the Data API for that spork:
rosetta-cli check:data --configuration-file flow.json
```

For VSCode add this to `.vscode/settings.json`
```json
{
"gopls": {
"env": {
"GOFLAGS": "-tags=relic,integration"
},
},
}
```

## Usage

```sh
Usage of flow-rosetta-server:
-a, --api string host URL for GRPC API endpoint (default "127.0.0.1:5005")
-e, --cache uint maximum cache size for register reads in bytes (default 1073741824)
-l, --level string log output level (default "info")
-p, --port uint16 port to host Rosetta API on (default 8080)
-t, --transaction-limit int maximum amount of transactions to include in a block response (default 200)
--smart-status-codes enable smart non-500 HTTP status codes for Rosetta API errors
-c, --access-api string host address for Flow network\'s Access API endpoint (default "access.mainnet.nodes.onflow.org:9000")
-e, --cache uint maximum cache size for register reads in bytes (default 1000000000)
-a, --dps-api string host address for GRPC API endpoint (default "127.0.0.1:5005")
--dump-requests print out full request and responses
-l, --level string log output level (default "info")
-p, --port uint16 port to host Rosetta API on (default 8080)
--smart-status-codes enable smart non-500 HTTP status codes for Rosetta API errors
-t, --transaction-limit uint maximum amount of transactions to include in a block response (default 200)
-w, --wait-for-index wait for index to be available instead of quitting right away, useful when DPS Live index bootstraps
```

## Example
Expand All @@ -69,6 +83,14 @@ It uses a local instance of the Flow DPS Server for access to the execution stat
./flow-rosetta-server -a "127.0.0.1:5005" -p 8080
```

## Running without DPS Example

Some features can be used without the dps so you only need an access node for the mainnet you wish to run. Mainnet 16 example:

```sh
./flow-rosetta-server -c "access-001.mainnet16.nodes.onflow.org:9000" -p 8080
```

## Architecture

The Rosetta API needs its own documentation because of the amount of components it has that interact with each other.
Expand Down
3 changes: 2 additions & 1 deletion api/rosetta/balance_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import (
"github.com/optakt/flow-rosetta/rosetta/request"
//"github.com/optakt/flow-rosetta/rosetta/response"
)

// FIXME
/**
/**
func TestAPI_Balance(t *testing.T) {

db := setupDB(t)
Expand Down
2 changes: 1 addition & 1 deletion api/rosetta/data_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func setupAPI(t *testing.T, db *badger.DB) *rosetta.Data {

params := dps.FlowParams[dps.FlowLocalnet]
config := configuration.New(params.ChainID)
validate := validator.New(params, index, config)
validate := validator.New(params, index, nil, config)
generate := scripts.NewGenerator(params)
invoke, err := invoker.New(index)
require.NoError(t, err)
Expand Down
54 changes: 36 additions & 18 deletions cmd/flow-rosetta-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import (
"github.com/ziflex/lecho/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

"github.com/onflow/flow-go-sdk/client"
"github.com/onflow/flow-go/model/flow"

api "github.com/optakt/flow-dps/api/dps"
"github.com/optakt/flow-dps/codec/zbor"
Expand All @@ -42,8 +44,9 @@ import (
"github.com/optakt/flow-rosetta/rosetta/converter"
"github.com/optakt/flow-rosetta/rosetta/retriever"
"github.com/optakt/flow-rosetta/rosetta/scripts"
"github.com/optakt/flow-rosetta/rosetta/submitter"
"github.com/optakt/flow-rosetta/rosetta/transactor"

//"github.com/optakt/flow-rosetta/rosetta/submitter"
//"github.com/optakt/flow-rosetta/rosetta/transactor"
"github.com/optakt/flow-rosetta/rosetta/validator"
)

Expand Down Expand Up @@ -76,7 +79,7 @@ func run() int {
)

pflag.StringVarP(&flagDPS, "dps-api", "a", "127.0.0.1:5005", "host address for GRPC API endpoint")
pflag.StringVarP(&flagAccess, "access-api", "c", "access.canary.nodes.onflow.org:9000", "host address for Flow network's Access API endpoint")
pflag.StringVarP(&flagAccess, "access-api", "c", "access.mainnet.nodes.onflow.org:9000", "host address for Flow network's Access API endpoint")
pflag.Uint64VarP(&flagCache, "cache", "e", 1_000_000_000, "maximum cache size for register reads in bytes")
pflag.StringVarP(&flagLevel, "level", "l", "info", "log output level")
pflag.Uint16VarP(&flagPort, "port", "p", 8080, "port to host Rosetta API on")
Expand All @@ -98,6 +101,15 @@ func run() int {
log = log.Level(level)
elog := lecho.From(log)

// Tracer initialization.
tracer.Start(
// tracer.WithEnv(), TODO
tracer.WithService("flow-rosetta"),
tracer.WithGlobalTag("protocol", "flow"),
tracer.WithServiceVersion("v0.0.1"),
)
defer tracer.Stop()

// Initialize codec.
codec := zbor.NewCodec()

Expand All @@ -111,8 +123,9 @@ func run() int {
dpsAPI := api.NewAPIClient(conn)
index := api.IndexFromAPI(dpsAPI, codec)

wait:
// wait:
// Deduce chain ID from DPS API to configure parameters for script exec.
/** FIXME
first, err := index.First()
if err != nil {
log.Error().Err(err).Msg("could not get first height from DPS API")
Expand All @@ -122,14 +135,19 @@ wait:
}
return failure
}

root, err := index.Header(first)

if err != nil {
log.Error().Uint64("first", first).Err(err).Msg("could not get root header from DPS API")
return failure
}
params, ok := dps.FlowParams[root.ChainID]
**/

params, ok := dps.FlowParams[flow.Mainnet] // params, ok := dps.FlowParams[root.ChainID]
if !ok {
log.Error().Str("chain", root.ChainID.String()).Msg("invalid chain ID for params")
// log.Error().Str("chain", root.ChainID.String()).Msg("invalid chain ID for params")
log.Error().Str("chain", flow.Mainnet.String()).Msg("invalid chain ID for params")
return failure
}

Expand All @@ -154,7 +172,7 @@ wait:

// Rosetta API initialization.
config := configuration.New(params.ChainID)
validate := validator.New(params, index, config)
validate := validator.New(params, index, accessAPI, config)
generate := scripts.NewGenerator(params)
invoke, err := invoker.New(index, invoker.WithCacheSize(flagCache))
if err != nil {
Expand All @@ -168,14 +186,14 @@ wait:
return failure
}

retrieve := retriever.New(params, index, validate, generate, invoke, convert,
retrieve := retriever.New(params, index, accessAPI, validate, generate, invoke, convert,
retriever.WithTransactionLimit(flagTransactions),
)
dataCtrl := rosetta.NewData(config, retrieve, validate)

submit := submitter.New(accessAPI)
transact := transactor.New(validate, generate, invoke, submit)
constructCtrl := rosetta.NewConstruction(config, transact, retrieve, validate)
//submit := submitter.New(accessAPI)
//transact := transactor.New(validate, generate, invoke, submit)
//constructCtrl := rosetta.NewConstruction(config, transact, retrieve, validate)

server := echo.New()
server.HideBanner = true
Expand Down Expand Up @@ -207,13 +225,13 @@ wait:
server.POST("/block/transaction", dataCtrl.Transaction)

// This group contains all of the Rosetta Construction API endpoints.
server.POST("/construction/preprocess", constructCtrl.Preprocess)
server.POST("/construction/metadata", constructCtrl.Metadata)
server.POST("/construction/payloads", constructCtrl.Payloads)
server.POST("/construction/parse", constructCtrl.Parse)
server.POST("/construction/combine", constructCtrl.Combine)
server.POST("/construction/hash", constructCtrl.Hash)
server.POST("/construction/submit", constructCtrl.Submit)
// server.POST("/construction/preprocess", constructCtrl.Preprocess)
// server.POST("/construction/metadata", constructCtrl.Metadata)
// server.POST("/construction/payloads", constructCtrl.Payloads)
// server.POST("/construction/parse", constructCtrl.Parse)
// server.POST("/construction/combine", constructCtrl.Combine)
// server.POST("/construction/hash", constructCtrl.Hash)
// server.POST("/construction/submit", constructCtrl.Submit)

// This section launches the main executing components in their own
// goroutine, so they can run concurrently. Afterwards, we wait for an
Expand Down
Loading