Skip to content

Commit

Permalink
Merged origin/main.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Jun 6, 2024
2 parents 706ca6c + a9485fe commit 94dffd9
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 29 deletions.
139 changes: 139 additions & 0 deletions .github/workflows/manual-deploy-dexynth-gateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Deploys Ten Gateway for Dexynth on Azure for Testnet
# Builds the Ten Gateway image, pushes the image to dockerhub and starts the Obscuro Gateway on Azure VM

name: '[M] Deploy Ten Gateway Dexynth'
run-name: '[M] Deploy Ten Gateway Dexynth ( ${{ github.event.inputs.testnet_type }} )'
on:
workflow_dispatch:
inputs:
testnet_type:
description: 'Testnet Type'
required: true
default: 'sepolia-testnet'
type: choice
options:
- 'sepolia-testnet'

jobs:
build-and-deploy-dexynth:
runs-on: ubuntu-latest
environment:
name: {{ github.event.inputs.testnet_type }}
steps:
- name: 'Print GitHub variables'
# This is a useful record of what the environment variables were at the time the job ran, for debugging and reference
run: |
echo "GitHub Variables = ${{ toJSON(vars) }}"
- uses: actions/checkout@v3

- name: 'Extract branch name'
shell: bash
run: |
echo "Branch Name: ${GITHUB_REF_NAME}"
echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: 'Set up Docker'
uses: docker/setup-buildx-action@v1

- name: 'Login to Azure docker registry'
uses: azure/docker-login@v1
with:
login-server: testnetobscuronet.azurecr.io
username: testnetobscuronet
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Build and Push Docker Image
run: |
DOCKER_BUILDKIT=1 docker build --build-arg TESTNET_TYPE=${{ github.event.inputs.testnet_type }} -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY_DEXYNTH }} -f ./tools/walletextension/Dockerfile .
docker push ${{ vars.DOCKER_BUILD_TAG_GATEWAY_DEXYNTH }}
# This will fail some deletions due to resource dependencies ( ie. you must first delete the vm before deleting the disk)
- name: 'Delete deployed VMs'
uses: azure/CLI@v1
with:
inlineScript: |
$(az resource list --tag ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY_DEXYNTH }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true
# This will clean up any lingering dependencies - might fail if there are no resources to cleanup
- name: 'Delete VMs dependencies'
uses: azure/CLI@v1
with:
inlineScript: |
$(az resource list --tag ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY_DEXYNTH }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true
- name: 'Ensure VM Static Public IP Exists'
uses: azure/CLI@v1
with:
inlineScript: |
az network public-ip show -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" || az network public-ip create -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" --allocation-method Static --sku Standard
- name: 'Assign/Update DNS Name for Public IP'
uses: azure/CLI@v1
with:
inlineScript: |
existing_dns_name=$(az network public-ip show -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" --query dnsSettings.domainNameLabel -o tsv)
if [ -z "$existing_dns_name" ]; then
az network public-ip update -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" --dns-name "obscurogateway-${{ github.event.inputs.testnet_type }}-dexynth"
fi
- name: 'Create VM for Gateway node on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm create -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth" \
--admin-username obscurouser --admin-password "${{ secrets.OBSCURO_NODE_VM_PWD }}" \
--public-ip-address "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" \
--tags deploygroup=ObscuroGateway-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}-dexynth ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY_DEXYNTH }}=true \
--vnet-name ObscuroGateway-${{ github.event.inputs.testnet_type }}-dexynth-01VNET --subnet ObscuroGateway-${{ github.event.inputs.testnet_type }}-dexynth-01Subnet \
--size Standard_D4_v5 --image Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:latest \
--authentication-type password
- name: 'Open Obscuro node-${{ matrix.host_id }} ports on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm open-port -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth" --port 80,81
# To overcome issues with critical VM resources being unavailable, we need to wait for the VM to be ready
- name: 'Allow time for VM initialization'
shell: bash
run: sleep 30

- name: 'Start Obscuro gateway on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm run-command invoke -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth" \
--command-id RunShellScript \
--scripts 'mkdir -p /home/obscuro \
&& sudo apt-get update \
&& sudo apt-get install -y gcc \
&& sudo snap refresh && sudo snap install --channel=1.18 go --classic \
&& curl -fsSL https://get.docker.com -o get-docker.sh && sh ./get-docker.sh \
&& git clone --depth 1 -b ${{ env.BRANCH_NAME }} https://github.com/ten-protocol/go-ten.git /home/obscuro/go-obscuro \
&& docker network create --driver bridge node_network || true \
&& docker run -d --name datadog-agent \
--network node_network \
-e DD_API_KEY=${{ secrets.DD_API_KEY }} \
-e DD_LOGS_ENABLED=true \
-e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
-e DD_LOGS_CONFIG_AUTO_MULTI_LINE_DETECTION=true \
-e DD_CONTAINER_EXCLUDE_LOGS="name:datadog-agent" \
-e DD_SITE="datadoghq.eu" \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /opt/datadog-agent/run:/opt/datadog-agent/run:rw \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
datadog/agent:latest \
&& cd /home/obscuro/go-obscuro/ \
&& docker run -d -p 80:80 -p 81:81 --name ${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth \
-e OBSCURO_GATEWAY_VERSION="${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }}" \
${{ vars.DOCKER_BUILD_TAG_GATEWAY_DEXYNTH }} \
-host=0.0.0.0 -port=8080 -portWS=81 -nodeHost=${{ vars.L2_RPC_URL_VALIDATOR_DEXYNTH }} -verbose=true \
-logPath=sys_out -dbType=mariaDB -dbConnectionURL="obscurouser:${{ secrets.OBSCURO_GATEWAY_MARIADB_USER_PWD }}@tcp(obscurogateway-mariadb-${{ github.event.inputs.testnet_type }}.uksouth.cloudapp.azure.com:3306)/ogdb"'
2 changes: 1 addition & 1 deletion contracts/generated/EthereumBridge/EthereumBridge.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/src/bridge/L2/EthereumBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ contract EthereumBridge is

function sendNative(address receiver) external payable {
require(msg.value > 0, "Nothing sent.");
require(hasTokenMapping(address(0x0)), "No mapping for token.");

bytes memory data = abi.encodeWithSelector(
IBridge.receiveAssets.selector,
Expand All @@ -67,6 +66,7 @@ contract EthereumBridge is
receiver
);
queueMessage(remoteBridgeAddress, data, uint32(Topics.TRANSFER), 0, 0);
_messageBus().sendValueToL2{value: msg.value}(receiver, msg.value);
}

function sendERC20(
Expand Down
1 change: 0 additions & 1 deletion contracts/src/management/ManagementContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
isWithdrawalSpent[keccak256(abi.encode(_msg))] = true;

messageBus.receiveValueFromL2(_msg.receiver, _msg.amount);
//todo track state
}

// An attested enclave will pickup the Network Secret Request
Expand Down
6 changes: 3 additions & 3 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ type batchHeaderEncoding struct {
CrossChainMessages []MessageBus.StructsCrossChainMessage `json:"crossChainMessages"`
LatestInboundCrossChainHash common.Hash `json:"inboundCrossChainHash"` // The block hash of the latest block that has been scanned for cross chain messages.
LatestInboundCrossChainHeight *hexutil.Big `json:"inboundCrossChainHeight"` // The block height of the latest block that has been scanned for cross chain messages.
TransfersTree common.Hash
CrossChainTree SerializedCrossChainTree `json:"crossChainTree"`
CrossChainRootHash common.Hash `json:"crossChainTreeHash"`
CrossChainTree SerializedCrossChainTree `json:"crossChainTree"`
}

// MarshalJSON custom marshals the BatchHeader into a json
Expand Down Expand Up @@ -122,7 +122,7 @@ func (b *BatchHeader) UnmarshalJSON(data []byte) error {
b.CrossChainMessages = dec.CrossChainMessages
b.LatestInboundCrossChainHash = dec.LatestInboundCrossChainHash
b.LatestInboundCrossChainHeight = (*big.Int)(dec.LatestInboundCrossChainHeight)
b.CrossChainRoot = dec.TransfersTree
b.CrossChainRoot = dec.CrossChainRootHash
b.CrossChainTree = dec.CrossChainTree
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion go/enclave/crosschain/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (vt ValueTransfers) ForMerkleTree() [][]interface{} {
for idx := range vt {
hashedVal := vt.HashPacked(idx)
val := []interface{}{
"v",
"v", // [v, "0xblabla"]
hashedVal,
}
values = append(values, val)
Expand Down
6 changes: 4 additions & 2 deletions go/enclave/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ type RPCServer struct {
// NewEnclaveRPCServer prepares an enclave RPCServer (doesn't start listening until `StartServer` is called
func NewEnclaveRPCServer(listenAddress string, enclave common.Enclave, logger gethlog.Logger) *RPCServer {
return &RPCServer{
enclave: enclave,
grpcServer: grpc.NewServer(),
enclave: enclave,
grpcServer: grpc.NewServer(
grpc.MaxRecvMsgSize(1024 * 1024 * 50),
),
logger: logger,
listenAddress: listenAddress,
}
Expand Down
18 changes: 13 additions & 5 deletions go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,11 @@ func (g *Guardian) periodicBundleSubmission() {

bundleSubmissionTicker := time.NewTicker(interval)

fromSequenceNumber := uint64(0)
fromSequenceNumber, _, err := g.sl.L1Publisher().GetBundleRangeFromManagementContract()
if err != nil {
g.logger.Error(`Unable to get bundle range from management contract and initialize cross chain publishing`, log.ErrKey, err)
return
}

for {
select {
Expand All @@ -645,21 +649,25 @@ func (g *Guardian) periodicBundleSubmission() {
continue
}

if from.Uint64() > fromSequenceNumber {
fromSequenceNumber = from.Uint64()
if from.Uint64() > fromSequenceNumber.Uint64() {
fromSequenceNumber.Set(from)
}

bundle, err := g.enclaveClient.ExportCrossChainData(context.Background(), fromSequenceNumber, to.Uint64())
bundle, err := g.enclaveClient.ExportCrossChainData(context.Background(), fromSequenceNumber.Uint64(), to.Uint64())
if err != nil {
if !errors.Is(err, errutil.ErrCrossChainBundleNoBatches) {
g.logger.Error("Unable to export cross chain bundle from enclave", log.ErrKey, err)
}
if errors.Is(err, context.DeadlineExceeded) {
g.logger.Error(`Cross chain bundle export timed out.`, log.ErrKey, err)
return // stop the process - if we are timing out we are not going to catch up
}
continue
}

if len(bundle.CrossChainRootHashes) == 0 {
g.logger.Debug("No cross chain data to submit")
fromSequenceNumber = to.Uint64() + 1
fromSequenceNumber.SetUint64(to.Uint64() + 1)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion go/host/rpc/enclaverpc/enclave_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (c *Client) StreamL2Updates() (chan common.StreamL2UpdatesResponse, func())
batchChan := make(chan common.StreamL2UpdatesResponse, 10)
cancelCtx, cancel := context.WithCancel(context.Background())

stream, err := c.protoClient.StreamL2Updates(cancelCtx, &generated.StreamL2UpdatesRequest{})
stream, err := c.protoClient.StreamL2Updates(cancelCtx, &generated.StreamL2UpdatesRequest{}, grpc.MaxCallRecvMsgSize(1024*1024*50))
if err != nil {
c.logger.Error("Error opening batch stream.", log.ErrKey, err)
cancel()
Expand Down
17 changes: 8 additions & 9 deletions integration/networktest/env/network_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ func (t *testnetEnv) startTenGateway() {
TenChainID: integration.TenChainID,
}
tenGWContainer := walletextension.NewContainerFromConfig(cfg, t.logger)
go func() {
fmt.Println("Starting Ten Gateway, HTTP Port:", _gwHTTPPort, "WS Port:", _gwWSPort)
err := tenGWContainer.Start()
if err != nil {
t.logger.Error("failed to start ten gateway", "err", err)
panic(err)
}
t.tenGatewayContainer = tenGWContainer
}()

fmt.Println("Starting Ten Gateway, HTTP Port:", _gwHTTPPort, "WS Port:", _gwWSPort)
err := tenGWContainer.Start()
if err != nil {
t.logger.Error("failed to start ten gateway", "err", err)
panic(err)
}
t.tenGatewayContainer = tenGWContainer
t.testnetConnector.tenGatewayURL = fmt.Sprintf("http://localhost:%d", _gwHTTPPort)
}

Expand Down
96 changes: 93 additions & 3 deletions integration/networktest/tests/helpful/accs_and_contracts_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,113 @@
package helpful

import (
"context"
"fmt"
"math/big"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ten-protocol/go-ten/go/common/retry"
"github.com/ten-protocol/go-ten/go/wallet"
"github.com/ten-protocol/go-ten/integration/common/testlog"
"github.com/ten-protocol/go-ten/integration/networktest"
"github.com/ten-protocol/go-ten/integration/networktest/actions"
"github.com/ten-protocol/go-ten/integration/networktest/env"
)

var _accountToFund = common.HexToAddress("0xD19f62b5A721747A04b969C90062CBb85D4aAaA8")
/*
* This file contains helpful tests for funding accounts, transferring funds, interacting with contracts, etc.
*/

// Run this test to fund an account with native funds
// Run this test to fund an account with native L2 funds
func TestSendFaucetFunds(t *testing.T) {
// Set the account to fund here
accountToFund := common.HexToAddress("<account address to fund>")

networktest.TestOnlyRunsInIDE(t)
networktest.Run(
"send-faucet-funds",
t,
env.LongRunningLocalNetwork(""),
&actions.AllocateFaucetFunds{Account: &_accountToFund},
&actions.AllocateFaucetFunds{Account: &accountToFund},
)
}

// Run this test to send native L1 ETH from one account to another
func TestTransferL1Funds(t *testing.T) {
// Set the accounts addresses and amount to send here
fromPK := "<pk string with no 0x prefix>"
to := common.HexToAddress("<account address to send to>")
// amount to send in wei
amt := big.NewInt(0).Mul(big.NewInt(1), big.NewInt(int64(params.Ether)))

networktest.TestOnlyRunsInIDE(t)
networktest.Run(
"send-native-funds",
t,
env.SepoliaTestnet(),
actions.RunOnlyAction(func(ctx context.Context, network networktest.NetworkConnector) (context.Context, error) {
l1Wallet := wallet.NewInMemoryWalletFromConfig(fromPK, _sepoliaChainID, testlog.Logger())
cli, err := network.GetL1Client()
if err != nil {
panic(err)
}
// in sepolia if you have issues, you may need a more reliable RPC endpoint, e.g. infura with an api-key:
// cli, err := ethadapter.NewEthClientFromURL("https://sepolia.infura.io/v3/<api-key>", 10*time.Second, common.HexToAddress("0x0"), testlog.Logger())
nonce, err := cli.Nonce(l1Wallet.Address())
if err != nil {
panic(err)
}
l1Wallet.SetNonce(nonce)

gasPrice, err := cli.EthClient().SuggestGasPrice(context.Background())
if err != nil {
panic(err)
}
// apply multiplier to the gas price here if you want to guarantee it goes through quickly
// gasPrice = big.NewInt(0).Mul(gasPrice, big.NewInt(2))

// create transaction from l1Wallet to toAddress
tx := &types.LegacyTx{
Nonce: l1Wallet.GetNonce(),
Value: amt,
Gas: uint64(25_000),
GasPrice: gasPrice,
To: &to,
}
signedTx, err := l1Wallet.SignTransaction(tx)
if err != nil {
panic(err)
}

err = cli.SendTransaction(signedTx)
if err != nil {
panic(err)
}

// await receipt
err = retry.Do(func() error {
receipt, err := cli.TransactionReceipt(signedTx.Hash())
if err != nil {
return err
}
if receipt == nil {
return fmt.Errorf("no receipt yet")
}
if receipt.Status != types.ReceiptStatusSuccessful {
return retry.FailFast(fmt.Errorf("receipt had status failed for transaction %s", signedTx.Hash().Hex()))
}
return nil
}, retry.NewTimeoutStrategy(70*time.Second, 20*time.Second))

if err != nil {
panic(err)
}

return ctx, nil
}),
)
}
Loading

0 comments on commit 94dffd9

Please sign in to comment.