Skip to content

Commit

Permalink
Merge pull request #1 from rarimo/feature/gist-relays
Browse files Browse the repository at this point in the history
Feature: Relay on request and GIST relayes
  • Loading branch information
olegfomenko authored Nov 24, 2023
2 parents ae0b7c4 + dca0627 commit d9dff69
Show file tree
Hide file tree
Showing 66 changed files with 6,901 additions and 962 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Rarimo Identity Relayer service docker image
on:
workflow_dispatch:

jobs:
converge:
name: Converge
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install werf
uses: werf/actions/install@v1.2

- name: Log in to registry
# This is where you will update the personal access token to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Run echo
run: |
werf version
docker version
echo $GITHUB_REPOSITORY
echo $GITHUB_SHA
- name: Run Build
run: |
. $(werf ci-env github --as-file)
werf export service --tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA
37 changes: 37 additions & 0 deletions .github/workflows/actions_onlymain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Rarimo Identity Relayer service docker image
on:
push:
branches:
- 'main'
- 'master'
- 'chains/mainnet'
- 'chains/mainnet-beta'

jobs:
converge:
name: Converge
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install werf
uses: werf/actions/install@v1.2

- name: Log in to registry
# This is where you will update the personal access token to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Run echo
run: |
werf version
docker version
echo $GITHUB_REPOSITORY
echo $GITHUB_SHA
- name: Run Build
run: |
. $(werf ci-env github --as-file)
werf export service --tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_SHA
34 changes: 34 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build Rarimo Identity Relayer service docker image
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
converge:
name: Converge
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install werf
uses: werf/actions/install@v1.2

- name: Log in to registry
# This is where you will update the personal access token to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Run echo
run: |
werf version
docker version
echo $GITHUB_REPOSITORY
echo $GITHUB_REF_NAME
- name: Run Build
run: |
. $(werf ci-env github --as-file)
werf export service --tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_REF_NAME
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
config.local.yaml
node_modules
dump.rdb
relayer-svc
relayer-svc
vendor
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ FROM golang:1.19-alpine as buildbase

RUN apk add git build-base

WORKDIR /go/src/gitlab.com/rarimo/relayer-svc
WORKDIR /go/src/github.com/rarimo/identity-relayer-svc
COPY vendor .
COPY . .

ENV GO111MODULE="on"
ENV CGO_ENABLED=1
ENV GOOS="linux"

RUN GOOS=linux go build -o /usr/local/bin/relayer-svc /go/src/gitlab.com/rarimo/relayer-svc
RUN GOOS=linux go build -o /usr/local/bin/relayer-svc /go/src/github.com/rarimo/identity-relayer-svc


FROM alpine:3.9
Expand Down
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2023 Zero Block Global Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
150 changes: 147 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,149 @@
# relayer-svc
# identity-relayer-svc

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

The Relayer service as a part of Rarimo cross-chain system designed to finalize transferring flow by submitting final
transaction to the target chain.

The goal of identity relayer is to observe and fetch information about new signatures for
`IDENTITY_STATE_TRANSFER` and `IDENTITY_GIST_TRANSFER` operations and after submit the state transit transactions to
configured EVM chain by request.

For more information about how the PolygonID identity transfer works
visit: [rarimo-core docs](https://rarimo.github.io/rarimo-core/docs/common/bridging/002-identity.html).

----

## Build

You can use the image from GitHub registry or build the executable by yourself.

Build command:

```
go build .
```

Also, you can use the Dockerfile inside the repository.

----

## Configuration

Service configuration consists of two parts:

### Environment

```shell
export KV_VIPER_FILE=/config.yaml
```

### Config file

```yaml
log:
disable_sentry: true
level: debug

# The port to run on
listener:
addr: :8000

# PostgreSQL DB connect
db:
url: "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"

# Rarimo core RPCs
core:
addr: tcp://validator:26657

cosmos:
addr: validator:9090

evm:
chains:
- name: "Ethereum"
## Address of the modified state contract on target chain
contract_address: ""
## Private key HEX (without leading 0x) that will pay the tx fee
submitter_private_key: ""
## RPC address. Example https://mainnet.infura.io/v3/11111
rpc:
## Target chain id
chain_id: 1

relay:
# Flag the indicates should service iterate over all existing transfer operation and fill the database
catchup_disabled: true
```
----
## Run
Use the `relayer-svc migrate up && relayer-svc run all` command to perform database migrations and run the service.

Explore the simple docker-compose file to run described services:

```yaml
version: "3.7"
services:
relayer-db:
image: postgres:13
restart: unless-stopped
environment:
- POSTGRES_USER=relayer
- POSTGRES_PASSWORD=relayer
- POSTGRES_DB=relayer
- PGDATA=/pgdata
volumes:
- relayer-data:/pgdata
relayer:
image: path/to/image:hash
restart: on-failure
ports:
- "8000:8000"
depends_on:
- relayer-db
volumes:
- ./config/relayer.yaml:/config.yaml
environment:
- KV_VIPER_FILE=/config.yaml
entrypoint: sh -c "relayer-svc migrate up && relayer-svc run all"
volumes:
relayer-data:
```

----

## Using service

1. Execute the POST `/integrations/relayer/state/relay` request with the following body to perform state publishing:

```json
{
"chain": "The name of chain submit to according to the service configuration",
"hash": "The state hash (the same as on state contract) in 0x... hex format"
}
```

2. Execute the POST `/integrations/relayer/gist/relay` request with the following body to perform gist publishing:

```json
{
"chain": "The name of chain submit to according to the service configuration",
"hash": "The GIST hash (the same as on state contract) in 0x... hex format"
}
```

The response will be:

* Code 200, successful relay, tx hash in body.
* Code 404, state is not transferred yet, wait a little and repeat request.
* Code 400, state has be relayed before.

The service monitors the locking transactions in Rarimo Core and relay the messages to the target chain if the user has submitted a sufficient fee.

[Design doc](https://docs.google.com/document/d/1kCo4yP_EE5joThgauTQMgeUr09OCawdABMy02jY2Qzw/edit?usp=sharing)
18 changes: 6 additions & 12 deletions config-example.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
log:
level: info
disable_sentry: true

listener:
addr: :8000

cop:
disabled: true
endpoint: "http://..."
upstream: "http://..."
service_name: relayer-svc
service_port: 80

redis:
addr: localhost:6379
db:
url: "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"

core:
addr: tcp://127.0.0.1:26657
Expand All @@ -28,6 +22,6 @@ evm:
rpc: https://goerli.infura.io/v3/2a6a01d5162c45939a09d96bea88d358

relay:
target_chain: "Goerli"
insta_submit_enabled: false
insta_submit_conf: ""
catchup_disabled: true
issuer_id: [ '', '' ]
disable_filtration: true
38 changes: 38 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package docs

import (
"embed"
httptemplate "html/template"
"net/http"
)

const (
apiFile = "/static/service.swagger.json"
indexFile = "template/index.tpl"
)

//go:embed static
var Docs embed.FS

//go:embed template
var template embed.FS

func RegisterOpenAPIService(appName string, rtr *http.ServeMux) {
rtr.Handle(apiFile, http.FileServer(http.FS(Docs)))
rtr.HandleFunc("/swagger", handler(appName))
}

// handler returns an http handler that servers OpenAPI console for an OpenAPI spec at specURL.
func handler(title string) http.HandlerFunc {
t, _ := httptemplate.ParseFS(template, indexFile)

return func(w http.ResponseWriter, req *http.Request) {
t.Execute(w, struct {
Title string
URL string
}{
title,
apiFile,
})
}
}
Loading

0 comments on commit d9dff69

Please sign in to comment.