Skip to content

Commit

Permalink
Merge branch 'token_vault_processing_fee_fix' of github.com:taikochai…
Browse files Browse the repository at this point in the history
…n/taiko-mono into token_vault_processing_fee_fix
  • Loading branch information
cyberhorsey committed Nov 18, 2022
2 parents 7ce2e74 + f7d9ce0 commit 905a2fd
Show file tree
Hide file tree
Showing 37 changed files with 887 additions and 343 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
working-directory: ./packages/relayer
args: --config=.golangci.yml

build:
test:
runs-on: ubuntu-latest
needs: lint
steps:
Expand All @@ -44,4 +44,10 @@ jobs:

- name: relayer - Unit Tests
working-directory: ./packages/relayer
run: go test ./... -count=1
run: go test ./... -count=1 -coverprofile=coverage.txt -covermode=atomic

- name: relayer - Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./packages/relayer/coverage.txt
flags: relayer
8 changes: 7 additions & 1 deletion .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: protocol - Unit Tests
working-directory: ./packages/protocol
run: pnpm install && pnpm clean && pnpm test && pnpm test:integration && pnpm export:abi
run: pnpm install && pnpm clean && pnpm test:coverage && pnpm test:integration && pnpm export:abi

- name: protocol - Generate Genesis
working-directory: ./packages/protocol
Expand All @@ -59,3 +59,9 @@ jobs:
- name: protocol - Deploy L1 Contracts
working-directory: ./packages/protocol
run: pnpm deploy:hardhat

- name: protocol - Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: ./packages/protocol/coverage
flags: protocol
3 changes: 2 additions & 1 deletion .github/workflows/whitepaper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ jobs:
uses: xu-cheng/latex-action@v2
with:
working_directory: ./packages/whitepaper
pre_compile: pdflatex -interaction=errorstopmode -halt-on-error main.tex && (bibtex main || true)
root_file: main.tex

- name: Rename
working-directory: ./packages/whitepaper
run: mkdir -p build && mv main.pdf build/taiko-whitepaper.pdf
run: rm -rf build/ && mkdir build && mv main.pdf build/taiko-whitepaper.pdf

- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ dist

# vscode
.vscode/

.pdf
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

[![Solidity](https://github.com/taikochain/taiko-mono/actions/workflows/solidity.yml/badge.svg)](https://github.com/taikochain/taiko-mono/actions/workflows/solidity.yml)

[![Relayer](https://codecov.io/gh/taikochain/taiko-mono/branch/main/graph/badge.svg?token=E468X2PTJC&flag=relayer)](https://codecov.io/gh/taikochain/taiko-mono)

[![Protocol](https://codecov.io/gh/taikochain/taiko-mono/branch/main/graph/badge.svg?token=E468X2PTJC&flag=protocol)](https://codecov.io/gh/taikochain/taiko-mono)

<!-- PROJECT LOGO -->
<br />
<div align="center">
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad // indirect
google.golang.org/grpc v1.47.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/.solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ module.exports = {
"test/libs/TestLibReceiptDecoder.sol", //integration tests
"test/thirdparty/TestLibBlockHeaderDecoder.sol", // assembly too long
],
mocha:{
grep: '^[^integration]'
}
};
17 changes: 13 additions & 4 deletions packages/relayer/.default.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ MYSQL_PASSWORD=root
MYSQL_DATABASE=relayer
MYSQL_HOST=localhost:3306
RELAYER_ECDSA_KEY=
L1_BRIDGE_ADDRESS=0xa566811E9E63e4F573Df89d5453bB89F239F7e10
L2_BRIDGE_ADDRESS=0xa566811E9E63e4F573Df89d5453bB89F239F7e10
L1_RPC_URL="wss://eth-goerli.g.alchemy.com/v2/bPAA5rQ42Zoo4ts9TYnTB2t0cuc5lf7_"
L2_RPC_URL="wss://rinkeby-light.eth.linkpool.io/ws"
L1_BRIDGE_ADDRESS=0xB12d6112D64B213880Fa53F815aF1F29c91CaCe9
L2_BRIDGE_ADDRESS=0x4eA05A0f7713333AeB4bB73F17aEeFE146CF13E3
L1_TAIKO_ADDRESS=0x9b557777Be33A8A2fE6aF93E017A0d139B439E5D
L2_TAIKO_ADDRESS=0x0027f309f7F94A8Efb6A3DBfb30827f1062803F4
L1_RPC_URL=ws://34.132.67.34:8546
L2_RPC_URL=ws://ws.a1.testnet.taiko.xyz
BLOCK_BATCH_SIZE=2
MYSQL_MAX_IDLE_CONNS=
MYSQL_MAX_OPEN_CONNS=
MYSQL_CONN_MAX_LIFETIME_IN_MS=
NUM_GOROUTINES=20
SUBSCRIPTION_BACKOFF_IN_SECONDS=3
CONFIRMATIONS_BEFORE_PROCESSING=15
3 changes: 1 addition & 2 deletions packages/relayer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
.env
.test.env
main
coverage/profile.cov
coverage/gitlab.xml
coverage.txt

# Local .terraform directories
.terraform
Expand Down
7 changes: 4 additions & 3 deletions packages/relayer/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ linters:
- gofmt
- golint
- gosec
- gosimple
- lll
- whitespace
- wsl

linters-settings:
funlen:
lines: 100
statements: 45
lines: 116
statements: 48
gocognit:
min-complexity: 32
min-complexity: 35

issues:
exclude-rules:
Expand Down
81 changes: 81 additions & 0 deletions packages/relayer/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"os"
"strconv"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -32,7 +34,13 @@ var (
"MYSQL_DATABASE",
"MYSQL_HOST",
"RELAYER_ECDSA_KEY",
"CONFIRMATIONS_BEFORE_PROCESSING",
}

defaultBlockBatchSize = 2
defaultNumGoroutines = 10
defaultSubscriptionBackoff = 2 * time.Second
defaultConfirmations = 15
)

func Run(mode relayer.Mode, layer relayer.Layer) {
Expand Down Expand Up @@ -107,6 +115,30 @@ func makeIndexers(layer relayer.Layer, db *gorm.DB) ([]*indexer.Service, func(),
return nil, nil, err
}

blockBatchSize, err := strconv.Atoi(os.Getenv("BLOCK_BATCH_SIZE"))
if err != nil || blockBatchSize <= 0 {
blockBatchSize = defaultBlockBatchSize
}

numGoroutines, err := strconv.Atoi(os.Getenv("NUM_GOROUTINES"))
if err != nil || numGoroutines <= 0 {
numGoroutines = defaultNumGoroutines
}

var subscriptionBackoff time.Duration

subscriptionBackoffInSeconds, err := strconv.Atoi(os.Getenv("SUBSCRIPTION_BACKOFF_IN_SECONDS"))
if err != nil || numGoroutines <= 0 {
subscriptionBackoff = defaultSubscriptionBackoff
} else {
subscriptionBackoff = time.Duration(subscriptionBackoffInSeconds) * time.Second
}

confirmations, err := strconv.Atoi(os.Getenv("CONFIRMATIONS_BEFORE_PROCESSING"))
if err != nil || confirmations <= 0 {
confirmations = defaultConfirmations
}

indexers := make([]*indexer.Service, 0)

if layer == relayer.L1 || layer == relayer.Both {
Expand All @@ -122,6 +154,11 @@ func makeIndexers(layer relayer.Layer, db *gorm.DB) ([]*indexer.Service, func(),
BridgeAddress: common.HexToAddress(os.Getenv("L1_BRIDGE_ADDRESS")),
DestBridgeAddress: common.HexToAddress(os.Getenv("L2_BRIDGE_ADDRESS")),
DestTaikoAddress: common.HexToAddress(os.Getenv("L2_TAIKO_ADDRESS")),

BlockBatchSize: uint64(blockBatchSize),
NumGoroutines: numGoroutines,
SubscriptionBackoff: subscriptionBackoff,
Confirmations: uint64(confirmations),
})
if err != nil {
log.Fatal(err)
Expand All @@ -143,6 +180,11 @@ func makeIndexers(layer relayer.Layer, db *gorm.DB) ([]*indexer.Service, func(),
BridgeAddress: common.HexToAddress(os.Getenv("L2_BRIDGE_ADDRESS")),
DestBridgeAddress: common.HexToAddress(os.Getenv("L1_BRIDGE_ADDRESS")),
DestTaikoAddress: common.HexToAddress(os.Getenv("L1_TAIKO_ADDRESS")),

BlockBatchSize: uint64(blockBatchSize),
NumGoroutines: numGoroutines,
SubscriptionBackoff: subscriptionBackoff,
Confirmations: uint64(confirmations),
})
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -187,6 +229,45 @@ func openDBConnection(opts relayer.DBConnectionOpts) *gorm.DB {
log.Fatal(err)
}

sqlDB, err := db.DB()
if err != nil {
log.Fatal(err)
}

var (
defaultMaxIdleConns = 50
defaultMaxOpenConns = 200
defaultConnMaxLifetime = 10 * time.Second
)

maxIdleConns, err := strconv.Atoi(os.Getenv("MYSQL_MAX_IDLE_CONNS"))
if err != nil || maxIdleConns <= 0 {
maxIdleConns = defaultMaxIdleConns
}

maxOpenConns, err := strconv.Atoi(os.Getenv("MYSQL_MAX_OPEN_CONNS"))
if err != nil || maxOpenConns <= 0 {
maxOpenConns = defaultMaxOpenConns
}

var maxLifetime time.Duration

connMaxLifetime, err := strconv.Atoi(os.Getenv("MYSQL_CONN_MAX_LIFETIME_IN_MS"))
if err != nil || connMaxLifetime <= 0 {
maxLifetime = defaultConnMaxLifetime
} else {
maxLifetime = time.Duration(connMaxLifetime)
}

// SetMaxOpenConns sets the maximum number of open connections to the database.
sqlDB.SetMaxOpenConns(maxOpenConns)

// SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
sqlDB.SetMaxIdleConns(maxIdleConns)

// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
sqlDB.SetConnMaxLifetime(maxLifetime)

return db
}

Expand Down
5 changes: 5 additions & 0 deletions packages/relayer/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ var (
ErrNoRPCClient = errors.Validation.NewWithKeyAndDetail("ERR_NO_RPC_CLIENT", "RPCClient is required")
ErrNoBridge = errors.Validation.NewWithKeyAndDetail("ERR_NO_BRIDGE", "Bridge is required")
ErrNoTaikoL2 = errors.Validation.NewWithKeyAndDetail("ERR_NO_TAIKO_L2", "TaikoL2 is required")

ErrInvalidConfirmations = errors.Validation.NewWithKeyAndDetail(
"ERR_INVALID_CONFIRMATIONS",
"Confirmations amount is invalid, must be numerical and > 0",
)
ErrInvalidMode = errors.Validation.NewWithKeyAndDetail("ERR_INVALID_MODE", "Mode not supported")
)
Loading

0 comments on commit 905a2fd

Please sign in to comment.