From 1daffac0341ea9935049d1e5d3a0d80730293c09 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 28 May 2024 12:16:39 +0100 Subject: [PATCH 1/8] replace health-check db query (#1938) --- go/enclave/storage/storage.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/enclave/storage/storage.go b/go/enclave/storage/storage.go index 0385605d58..c804424271 100644 --- a/go/enclave/storage/storage.go +++ b/go/enclave/storage/storage.go @@ -370,13 +370,13 @@ func (s *storageImpl) IsBlockAncestor(ctx context.Context, block *types.Block, m func (s *storageImpl) HealthCheck(ctx context.Context) (bool, error) { defer s.logDuration("HealthCheck", measure.NewStopwatch()) - headBatch, err := s.FetchHeadBatch(ctx) + seqNo, err := s.FetchCurrentSequencerNo(ctx) if err != nil { return false, err } - if headBatch == nil { - return false, fmt.Errorf("head batch is nil") + if seqNo == nil { + return false, fmt.Errorf("no batches are stored") } return true, nil From 99a8aeeeb1213c1b65e69531a26edf46571c96a3 Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Thu, 30 May 2024 17:07:11 +0100 Subject: [PATCH 2/8] Enclave: fix panic on uninitialised mempool (#1940) --- go/enclave/txpool/txpool.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index 8653d9626f..6deca4a1a4 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -51,7 +51,7 @@ func NewTxPool(blockchain *ethchainadapter.EthChainAdapter, gasTip *big.Int, log // Start starts the pool // can only be started after t.blockchain has at least one block inside func (t *TxPool) Start() error { - if t.pool != nil { + if t.running { return fmt.Errorf("tx pool already started") } @@ -75,6 +75,9 @@ func (t *TxPool) PendingTransactions() map[gethcommon.Address][]*gethtxpool.Lazy // Add adds a new transactions to the pool func (t *TxPool) Add(transaction *common.L2Tx) error { + if !t.running { + return fmt.Errorf("tx pool not running") + } var strErrors []string for _, err := range t.pool.Add([]*types.Transaction{transaction}, false, false) { if err != nil { From b335bd1e12b1fd620a7d29770ab2efa903a3629d Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Fri, 31 May 2024 11:09:38 +0100 Subject: [PATCH 3/8] Host: avoid spamming stuck L1 transactions (#1941) --- go/ethadapter/geth_rpc_client.go | 14 ++++++-------- go/ethadapter/interface.go | 2 +- go/host/l1/publisher.go | 9 ++++++++- integration/ethereummock/node.go | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/go/ethadapter/geth_rpc_client.go b/go/ethadapter/geth_rpc_client.go index 17745cd903..983ab08877 100644 --- a/go/ethadapter/geth_rpc_client.go +++ b/go/ethadapter/geth_rpc_client.go @@ -246,12 +246,16 @@ func (e *gethRPCClient) FetchLastBatchSeqNo(address gethcommon.Address) (*big.In // PrepareTransactionToSend takes a txData type and overrides the From, Gas and Gas Price field with current values func (e *gethRPCClient) PrepareTransactionToSend(ctx context.Context, txData types.TxData, from gethcommon.Address) (types.TxData, error) { - return e.PrepareTransactionToRetry(ctx, txData, from, 0) + nonce, err := e.EthClient().PendingNonceAt(ctx, from) + if err != nil { + return nil, fmt.Errorf("could not get nonce - %w", err) + } + return e.PrepareTransactionToRetry(ctx, txData, from, nonce, 0) } // PrepareTransactionToRetry takes a txData type and overrides the From, Gas and Gas Price field with current values // it bumps the price by a multiplier for retries. retryNumber is zero on first attempt (no multiplier on price) -func (e *gethRPCClient) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, retryNumber int) (types.TxData, error) { +func (e *gethRPCClient) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, nonce uint64, retryNumber int) (types.TxData, error) { unEstimatedTx := types.NewTx(txData) gasPrice, err := e.EthClient().SuggestGasPrice(ctx) if err != nil { @@ -279,12 +283,6 @@ func (e *gethRPCClient) PrepareTransactionToRetry(ctx context.Context, txData ty return nil, fmt.Errorf("could not estimate gas - %w", err) } - // we fetch the current nonce on every retry to avoid any risk of nonce reuse/conflicts - nonce, err := e.EthClient().PendingNonceAt(ctx, from) - if err != nil { - return nil, fmt.Errorf("could not fetch nonce - %w", err) - } - return &types.LegacyTx{ Nonce: nonce, GasPrice: retryPrice, diff --git a/go/ethadapter/interface.go b/go/ethadapter/interface.go index 281f1e6abf..31a1071869 100644 --- a/go/ethadapter/interface.go +++ b/go/ethadapter/interface.go @@ -35,7 +35,7 @@ type EthClient interface { // PrepareTransactionToSend updates the tx with from address, current nonce and current estimates for the gas and the gas price PrepareTransactionToSend(ctx context.Context, txData types.TxData, from gethcommon.Address) (types.TxData, error) - PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, retries int) (types.TxData, error) + PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, nonce uint64, retries int) (types.TxData, error) FetchLastBatchSeqNo(address gethcommon.Address) (*big.Int, error) diff --git a/go/host/l1/publisher.go b/go/host/l1/publisher.go index 94d0ea8220..5971f92bda 100644 --- a/go/host/l1/publisher.go +++ b/go/host/l1/publisher.go @@ -391,12 +391,19 @@ func (p *Publisher) publishTransaction(tx types.TxData) error { retries := -1 + // we keep trying to send the transaction with this nonce until it is included in a block + // note: this is only safe because of the sendingLock guaranteeing only one transaction in-flight at a time + nonce, err := p.ethClient.Nonce(p.hostWallet.Address()) + if err != nil { + return fmt.Errorf("could not get nonce for L1 tx: %w", err) + } + // while the publisher service is still alive we keep trying to get the transaction into the L1 for !p.hostStopper.IsStopping() { retries++ // count each attempt so we can increase gas price // update the tx gas price before each attempt - tx, err := p.ethClient.PrepareTransactionToRetry(p.sendingContext, tx, p.hostWallet.Address(), retries) + tx, err := p.ethClient.PrepareTransactionToRetry(p.sendingContext, tx, p.hostWallet.Address(), nonce, retries) if err != nil { return errors.Wrap(err, "could not estimate gas/gas price for L1 tx") } diff --git a/integration/ethereummock/node.go b/integration/ethereummock/node.go index cb41bac416..669c2de5c1 100644 --- a/integration/ethereummock/node.go +++ b/integration/ethereummock/node.go @@ -99,7 +99,7 @@ func (m *Node) PrepareTransactionToSend(_ context.Context, txData types.TxData, }, nil } -func (m *Node) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, _ int) (types.TxData, error) { +func (m *Node) PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, _ uint64, _ int) (types.TxData, error) { return m.PrepareTransactionToSend(ctx, txData, from) } From c0bf4086fd81945fdd6793f5832ed09baca96d55 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Mon, 3 Jun 2024 14:32:48 +0100 Subject: [PATCH 4/8] small mempool fixes (#1943) --- go/enclave/evm/evm_facade.go | 12 ++++++++++-- go/enclave/txpool/txpool.go | 14 +++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/go/enclave/evm/evm_facade.go b/go/enclave/evm/evm_facade.go index 5005f7b600..059b6f851e 100644 --- a/go/enclave/evm/evm_facade.go +++ b/go/enclave/evm/evm_facade.go @@ -36,6 +36,8 @@ import ( gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc" ) +var ErrGasNotEnoughForL1 = errors.New("gas limit too low to pay for execution and l1 fees") + // ExecuteTransactions // header - the header of the rollup where this transaction will be included // fromTxIndex - for the receipts and events, the evm needs to know for each transaction the order in which it was executed in the block. @@ -91,7 +93,12 @@ func ExecuteTransactions( if err != nil { tCountRollback++ result[t.Tx.Hash()] = err - logger.Info("Failed to execute tx:", log.TxKey, t.Tx.Hash(), log.CtrErrKey, err) + // only log tx execution errors if they are unexpected + logFailedTx := logger.Info + if errors.Is(err, gethcore.ErrNonceTooHigh) || errors.Is(err, gethcore.ErrNonceTooLow) || errors.Is(err, gethcore.ErrFeeCapTooLow) || errors.Is(err, ErrGasNotEnoughForL1) { + logFailedTx = logger.Debug + } + logFailedTx("Failed to execute tx:", log.TxKey, t.Tx.Hash(), log.CtrErrKey, err) continue } result[t.Tx.Hash()] = r @@ -160,8 +167,9 @@ func executeTransaction( // The gas limit of the transaction (evm message) should always be higher than the gas overhead // used to cover the l1 cost + // todo - this check has to be added to the mempool as well if msg.GasLimit < l1Gas.Uint64() { - return nil, fmt.Errorf("gas limit set by user is too low to pay for execution and l1 fees. Want at least: %d have: %d", l1Gas, msg.GasLimit) + return nil, fmt.Errorf("%w. Want at least: %d have: %d", ErrGasNotEnoughForL1, l1Gas, msg.GasLimit) } // Remove the gas overhead for l1 publishing from the gas limit in order to define diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index 6deca4a1a4..efcd3dd3af 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -5,15 +5,17 @@ import ( "math/big" "strings" "sync" + _ "unsafe" + + gethcommon "github.com/ethereum/go-ethereum/common" + "github.com/holiman/uint256" // unsafe package imported in order to link to a private function in go-ethereum. // This allows us to validate transactions against the tx pool rules. - _ "unsafe" gethlog "github.com/ethereum/go-ethereum/log" "github.com/ten-protocol/go-ten/go/common/log" - gethcommon "github.com/ethereum/go-ethereum/common" gethtxpool "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/txpool/legacypool" "github.com/ethereum/go-ethereum/core/types" @@ -67,9 +69,11 @@ func (t *TxPool) Start() error { // PendingTransactions returns all pending transactions grouped per address and ordered per nonce func (t *TxPool) PendingTransactions() map[gethcommon.Address][]*gethtxpool.LazyTransaction { - // todo + // todo - for now using the base fee from the block + baseFee := t.Chain.CurrentBlock().BaseFee return t.pool.Pending(gethtxpool.PendingFilter{ - // BaseFee: + BaseFee: uint256.NewInt(baseFee.Uint64()), + OnlyPlainTxs: true, }) } @@ -121,5 +125,5 @@ func (t *TxPool) Close() error { t.logger.Error("Could not close legacy pool", log.ErrKey, err) } }() - return t.legacyPool.Close() + return t.pool.Close() } From 9cee2fd47b3a9b7ac448874896e4152b1c6f73c6 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 4 Jun 2024 10:01:29 +0100 Subject: [PATCH 5/8] increase max message size grpc config (#1946) --- go/enclave/rpc_server.go | 6 ++++-- go/host/rpc/enclaverpc/enclave_client.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go/enclave/rpc_server.go b/go/enclave/rpc_server.go index df24e5066a..6b5cf31a28 100644 --- a/go/enclave/rpc_server.go +++ b/go/enclave/rpc_server.go @@ -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, } diff --git a/go/host/rpc/enclaverpc/enclave_client.go b/go/host/rpc/enclaverpc/enclave_client.go index 76ca2d05fe..583434d4d3 100644 --- a/go/host/rpc/enclaverpc/enclave_client.go +++ b/go/host/rpc/enclaverpc/enclave_client.go @@ -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() From 0f3d42bf22188f0accd350724b42f44a428f1d02 Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:46:57 +0100 Subject: [PATCH 6/8] Network tests: start gateway synchronously to fix race (#1947) --- integration/networktest/env/network_setup.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/integration/networktest/env/network_setup.go b/integration/networktest/env/network_setup.go index 06ae70ab75..bd107052da 100644 --- a/integration/networktest/env/network_setup.go +++ b/integration/networktest/env/network_setup.go @@ -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) } From b8935c31e2429eae6a230c7d4b47a7ead1a8733b Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:36:33 +0100 Subject: [PATCH 7/8] Network tests: util func for L1 transfers (#1948) --- .../tests/helpful/accs_and_contracts_test.go | 96 ++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/integration/networktest/tests/helpful/accs_and_contracts_test.go b/integration/networktest/tests/helpful/accs_and_contracts_test.go index 9b6673bfe9..e96271ee05 100644 --- a/integration/networktest/tests/helpful/accs_and_contracts_test.go +++ b/integration/networktest/tests/helpful/accs_and_contracts_test.go @@ -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("") + 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 := "" + to := common.HexToAddress("") + // 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/", 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 + }), ) } From e6453082eaa9931d93d7ba33153e30b13ceb0d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Wed, 5 Jun 2024 15:56:12 +0200 Subject: [PATCH 8/8] deploy separate Ten gateway for Dexynth (#1949) --- .../manual-deploy-dexynth-gateway.yml | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 .github/workflows/manual-deploy-dexynth-gateway.yml diff --git a/.github/workflows/manual-deploy-dexynth-gateway.yml b/.github/workflows/manual-deploy-dexynth-gateway.yml new file mode 100644 index 0000000000..201999b3e0 --- /dev/null +++ b/.github/workflows/manual-deploy-dexynth-gateway.yml @@ -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"'