Skip to content

Commit

Permalink
Merge pull request #159 from Cerebellum-Network/dev-cere
Browse files Browse the repository at this point in the history
Sync Workflows: Dev, Stage, Enable and Disable Realyers
  • Loading branch information
MRamanenkau authored Feb 12, 2024
2 parents 4ecffed + e0eea57 commit 0c55d1a
Show file tree
Hide file tree
Showing 35 changed files with 779 additions and 160 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,17 @@ on:
- dev-cere
workflow_dispatch:

permissions:
id-token: write
contents: read

jobs:
build:
uses: Cerebellum-Network/reusable-workflows/.github/workflows/build-and-push-docker.yaml@1.0.0
uses: Cerebellum-Network/reusable-workflows/.github/workflows/deploy-to-ecr.yaml@master
with:
runs-on: '["self-hosted", "cere-network-large-workers"]'
org: cerebellumnetwork
runs-on: '["self-hosted", "cere-network-large"]'
environment: dev
image: crb-${{ github.event.repository.name }}
repository: crb-${{ github.event.repository.name }}
aws_account_id: ${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}
repository: network-relayer
file: ./Dockerfile
secrets: inherit

deploy:
uses: Cerebellum-Network/reusable-workflows/.github/workflows/[email protected]
needs: build
with:
runs-on: '["self-hosted", "cere-network-dev-deployer"]'
helm-repo-path: network/network-relayer
helm-release: network-relayer
namespace: network
tag: ${{ needs.build.outputs.version }}
environment: dev
secrets: inherit
25 changes: 25 additions & 0 deletions .github/workflows/disable-relayers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Disable Relayers

on:
workflow_dispatch:

jobs:
disable-relayers:
runs-on: [ "self-hosted", "cere-network-prd-deployer" ]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup kubectl
uses: azure/setup-kubectl@v1
with:
version: ${{ secrets.KUBECTL_VERSION }}
- name: Set replicas to 0 for relayers
run: |
# Get a list of network-relayers
deployments=$(kubectl get deployment -n network | grep '^network-relayer' | awk '{print $1}')
# Iterate over the deployments and scale each one to 0 replicas
for deployment in $deployments; do
kubectl scale deployment -n network --replicas=0 $deployment
done
25 changes: 25 additions & 0 deletions .github/workflows/enable-relayers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Enable Relayers

on:
workflow_dispatch:

jobs:
enable-relayers:
runs-on: [ "self-hosted", "cere-network-prd-deployer" ]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup kubectl
uses: azure/setup-kubectl@v1
with:
version: ${{ secrets.KUBECTL_VERSION }}
- name: Set replicas to 1 for relayers
run: |
# Get a list of network-relayers
deployments=$(kubectl get deployment -n network | grep '^network-relayer' | awk '{print $1}')
# Iterate over the deployments and scale each one to 1 replicas
for deployment in $deployments; do
kubectl scale deployment -n network --replicas=1 $deployment
done
27 changes: 9 additions & 18 deletions .github/workflows/stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,17 @@ on:
- 'hotfix/**'
workflow_dispatch:

permissions:
id-token: write
contents: read

jobs:
build:
uses: Cerebellum-Network/reusable-workflows/.github/workflows/build-and-push-docker.yaml@1.0.0
uses: Cerebellum-Network/reusable-workflows/.github/workflows/deploy-to-ecr.yaml@master
with:
runs-on: '["self-hosted", "cere-network-large-workers"]'
org: cerebellumnetwork
environment: stage
image: crb-${{ github.event.repository.name }}
repository: crb-${{ github.event.repository.name }}
runs-on: '["self-hosted", "cere-network-large"]'
environment: stg
aws_account_id: ${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}
repository: network-relayer
file: ./Dockerfile
secrets: inherit

deploy:
uses: Cerebellum-Network/reusable-workflows/.github/workflows/[email protected]
needs: build
with:
runs-on: '["self-hosted", "cere-network-stg-deployer"]'
helm-repo-path: network/network-relayer
helm-release: network-relayer
namespace: network
tag: ${{ needs.build.outputs.version }}
environment: stage
secrets: inherit
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 ChainSafe Systems
# SPDX-License-Identifier: LGPL-3.0-only

FROM golang:1.18-stretch AS builder
FROM golang:1.21.5-alpine AS builder
ADD . /src
WORKDIR /src
RUN go mod download
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Release Notes

## vNext
- ...
- Added workflows to disable and enable relayers.

## v2.7.0
- Added support of the Cere node v2.32.0
Expand Down
11 changes: 10 additions & 1 deletion chains/ethereum/writer_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ethereum
import (
"context"
"errors"
"github.com/ethereum/go-ethereum/common"
"math/big"
"time"

Expand All @@ -31,6 +32,8 @@ var ErrFatalQuery = errors.New("query of chain state failed")
// proposalIsComplete returns true if the proposal state is either Passed, Transferred or Cancelled
func (w *writer) proposalIsComplete(srcId msg.ChainId, nonce msg.Nonce, dataHash [32]byte) bool {
prop, err := w.bridgeContract.GetProposal(w.conn.CallOpts(), uint8(srcId), uint64(nonce), dataHash)
w.log.Debug("Proposal", "src", prop)

if err != nil {
w.log.Error("Failed to check proposal existence", "err", err)
return false
Expand Down Expand Up @@ -92,12 +95,17 @@ func (w *writer) createErc20Proposal(m msg.Message) bool {
data := ConstructErc20ProposalData(m.Payload[0].([]byte), m.Payload[1].([]byte))
dataHash := utils.Hash(append(w.cfg.erc20HandlerContract.Bytes(), data...))

w.log.Debug("Proposal Amount", "src", new(big.Int).SetBytes(m.Payload[0].([]byte)).String())
w.log.Debug("Proposal Destination Address", "src", common.BytesToAddress(m.Payload[1].([]byte)))
w.log.Debug("Proposal DataHash", "src", dataHash)

if !w.shouldVote(m, dataHash) {
if w.proposalIsPassed(m.Source, m.DepositNonce, dataHash) {
// We should not vote for this proposal but it is ready to be executed
w.executeProposal(m, data, dataHash)
return true
} else {
w.log.Info("Proposal did not pass yet.")
return false
}
}
Expand All @@ -109,9 +117,10 @@ func (w *writer) createErc20Proposal(m msg.Message) bool {
return false
}

// watch for execution event
w.log.Info("Submitting proposal transactions")
go w.watchThenExecute(m, data, dataHash, latestBlock)

w.log.Info("Submit vote on proposal")
w.voteProposal(m, dataHash)

return true
Expand Down
10 changes: 5 additions & 5 deletions chains/substrate/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

utils "github.com/Cerebellum-Network/ChainBridge/shared/substrate"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
gsrpc "github.com/Cerebellum-Network/go-substrate-rpc-client/v4"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/rpc/author"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/signature"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types/codec"
gsrpc "github.com/Cerebellum-Network/go-substrate-rpc-client/v8"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/rpc/author"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/signature"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types/codec"
"github.com/ChainSafe/log15"
)

Expand Down
2 changes: 1 addition & 1 deletion chains/substrate/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package substrate
import (
"testing"

"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
)

func TestConnect_QueryStorage(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion chains/substrate/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/Cerebellum-Network/chainbridge-utils/blockstore"
metrics "github.com/Cerebellum-Network/chainbridge-utils/metrics/types"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/ChainSafe/log15"
)

Expand Down
4 changes: 2 additions & 2 deletions chains/substrate/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
subtest "github.com/Cerebellum-Network/ChainBridge/shared/substrate/testing"
"github.com/Cerebellum-Network/chainbridge-utils/blockstore"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types/codec"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types/codec"
)

const ListenerTimeout = time.Second * 30
Expand Down
2 changes: 1 addition & 1 deletion chains/substrate/test_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
utils "github.com/Cerebellum-Network/ChainBridge/shared/substrate"
"github.com/Cerebellum-Network/chainbridge-utils/keystore"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/ChainSafe/log15"
"github.com/ethereum/go-ethereum/common/hexutil"
)
Expand Down
6 changes: 3 additions & 3 deletions chains/substrate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"math/big"

"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/scale"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types/codec"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/scale"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types/codec"
)

type voteState struct {
Expand Down
4 changes: 2 additions & 2 deletions chains/substrate/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
utils "github.com/Cerebellum-Network/ChainBridge/shared/substrate"
metrics "github.com/Cerebellum-Network/chainbridge-utils/metrics/types"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types/codec"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types/codec"
"github.com/ChainSafe/log15"
)

Expand Down
4 changes: 2 additions & 2 deletions chains/substrate/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"reflect"
"testing"

"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types/codec"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types/codec"

utils "github.com/Cerebellum-Network/ChainBridge/shared/substrate"
subtest "github.com/Cerebellum-Network/ChainBridge/shared/substrate/testing"
Expand Down
11 changes: 5 additions & 6 deletions cmd/chainbridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,15 @@ func run(ctx *cli.Context) error {
return errors.New("unrecognized Chain Type")
}

if err != nil {
return err
}

if chain.Scan {
c.AddChain(newChain)
} else {
c.SetRouter(newChain)
}

if err != nil {
return err
}

}

// Start prometheus and health server
Expand Down Expand Up @@ -238,7 +237,7 @@ func run(ctx *cli.Context) error {
http.HandleFunc(fmt.Sprintf("/health/%s", c.Name()), h.HealthStatus)
}
// nolint
// ToDo: enable linter after fixint required timeouts vulnerability https://deepsource.io/directory/analyzers/go/issues/GO-S2114
// ToDo: enable linter after fixint required timeouts vulnerability https://deepsource.io/directory/analyzers/go/issues/GO-S2114
err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
if errors.Is(err, http.ErrServerClosed) {
log.Info("Health status server is shutting down", err)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- "8546:8545"

sub-chain:
image: "cerebellumnetwork/pos-node:v2.32.0-rc1"
image: "cerebellumnetwork/pos-node:v4.8.2"
container_name: sub-chain
command: bash -c "/usr/local/bin/cere --dev --alice --ws-external --rpc-external"
ports:
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
subtest "github.com/Cerebellum-Network/ChainBridge/shared/substrate/testing"
"github.com/Cerebellum-Network/chainbridge-utils/core"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
log "github.com/ChainSafe/log15"
"github.com/ethereum/go-ethereum/common"
)
Expand Down
2 changes: 1 addition & 1 deletion e2e/fungible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
utils "github.com/Cerebellum-Network/ChainBridge/shared/ethereum"
ethtest "github.com/Cerebellum-Network/ChainBridge/shared/ethereum/testing"
subtest "github.com/Cerebellum-Network/ChainBridge/shared/substrate/testing"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
log "github.com/ChainSafe/log15"
)

Expand Down
2 changes: 1 addition & 1 deletion e2e/nonfungible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
sub "github.com/Cerebellum-Network/ChainBridge/e2e/substrate"
ethtest "github.com/Cerebellum-Network/ChainBridge/shared/ethereum/testing"
subtest "github.com/Cerebellum-Network/ChainBridge/shared/substrate/testing"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
log "github.com/ChainSafe/log15"
)

Expand Down
4 changes: 2 additions & 2 deletions e2e/parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
subutils "github.com/Cerebellum-Network/ChainBridge/shared/substrate"
subtest "github.com/Cerebellum-Network/ChainBridge/shared/substrate/testing"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/signature"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/signature"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
log "github.com/ChainSafe/log15"
"github.com/ethereum/go-ethereum/common"
)
Expand Down
4 changes: 2 additions & 2 deletions e2e/substrate/substrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/Cerebellum-Network/chainbridge-utils/core"
"github.com/Cerebellum-Network/chainbridge-utils/keystore"
"github.com/Cerebellum-Network/chainbridge-utils/msg"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v4/types/codec"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types"
"github.com/Cerebellum-Network/go-substrate-rpc-client/v8/types/codec"
"github.com/ChainSafe/log15"
"golang.org/x/crypto/blake2b"
)
Expand Down
Loading

0 comments on commit 0c55d1a

Please sign in to comment.