-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rarimo/feature/gist-relays
Feature: Relay on request and GIST relayes
- Loading branch information
Showing
66 changed files
with
6,901 additions
and
962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
config.local.yaml | ||
node_modules | ||
dump.rdb | ||
relayer-svc | ||
relayer-svc | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} |
Oops, something went wrong.