Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ten-protocol/go-ten into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus committed Aug 22, 2024
2 parents 7e53432 + de8de30 commit 484278a
Show file tree
Hide file tree
Showing 47 changed files with 257 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-dexynth-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ jobs:
${{ 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" \
-rateLimitUserComputeTime=${{ vars.GATEWAY_RATE_LIMIT_USER_COMPUTE_TIME }} -rateLimitWindow=${{ vars.GATEWAY_RATE_LIMIT_WINDOW }} -maxConcurrentRequestsPerUser=${{ vars.GATEWAY_MAX_CONCURRENT_REQUESTS_PER_USER }} '
-rateLimitUserComputeTime=0 '
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-obscuro-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ jobs:
-e OBSCURO_GATEWAY_VERSION="${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }}" \
--log-opt max-file=3 --log-opt max-size=10m \
${{ vars.DOCKER_BUILD_TAG_GATEWAY }} \
-host=0.0.0.0 -port=8080 -portWS=81 -nodeHost=${{ vars.L2_RPC_URL_VALIDATOR }} -verbose=true \
-host=0.0.0.0 -port=80 -portWS=81 -nodeHost=${{ vars.L2_RPC_URL_VALIDATOR }} -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" \
-rateLimitUserComputeTime=${{ vars.GATEWAY_RATE_LIMIT_USER_COMPUTE_TIME }} -rateLimitWindow=${{ vars.GATEWAY_RATE_LIMIT_WINDOW }} -maxConcurrentRequestsPerUser=${{ vars.GATEWAY_MAX_CONCURRENT_REQUESTS_PER_USER }} '
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-ten-bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

- name: Build and Push Docker FE Image
run: |
DOCKER_BUILDKIT=1 docker build -t ${{ vars.DOCKER_BUILD_TAG_BRIDGE_FE }} -f ./contracts/src/bridge/frontend/Dockerfile .
DOCKER_BUILDKIT=1 docker build -t ${{ vars.DOCKER_BUILD_TAG_BRIDGE_FE }} -f ./tools/bridge-frontend/Dockerfile .
docker push ${{ vars.DOCKER_BUILD_TAG_BRIDGE_FE }}
- name: "Deploy FE to Azure Container Instances"
Expand Down
17 changes: 3 additions & 14 deletions .github/workflows/manual-deploy-ten-gateway-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,16 @@ on:
- 'dev-testnet'
- 'uat-testnet'
- 'sepolia-testnet'

jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.testnet_type }}
strategy:
fail-fast: false
matrix:
include:
- testnet_type: 'dev-testnet'
GATEWAY_API_URL: 'https://dev-testnet.ten.xyz'
- testnet_type: 'uat-testnet'
GATEWAY_API_URL: 'https://uat-testnet.ten.xyz'
- testnet_type: 'sepolia-testnet'
GATEWAY_API_URL: 'https://testnet.ten.xyz'
steps:
- name: 'Print GitHub variables'
run: |
echo "Selected Testnet Type: ${{ matrix.testnet_type }}"
echo "Gateway API URL: ${{ matrix.GATEWAY_API_URL }}"
echo "Gateway API URL: ${{ vars.GATEWAY_URL }}"
- uses: actions/checkout@v4

Expand All @@ -46,7 +35,7 @@ jobs:
echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: 'Set up Docker'
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3.6.1

- name: 'Login to Azure docker registry'
uses: azure/docker-login@v1
Expand All @@ -62,7 +51,7 @@ jobs:

- name: Build and Push Docker Image
run: |
DOCKER_BUILDKIT=1 docker build --build-arg GATEWAY_API_URL=${{ matrix.GATEWAY_API_URL }} -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY_FE }} -f ./tools/walletextension/frontend/Dockerfile .
DOCKER_BUILDKIT=1 docker build --build-arg GATEWAY_API_URL=${{ vars.GATEWAY_URL }} -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY_FE }} -f ./tools/walletextension/frontend/Dockerfile .
docker push ${{ vars.DOCKER_BUILD_TAG_GATEWAY_FE }}
- name: "Deploy Gateway FE to Azure Container Instances"
Expand Down
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"ten-hardhat-plugin": "^0.0.9"
},
"peerDependencies": {
"@nomicfoundation/hardhat-verify" : "2.0.8"
"@nomicfoundation/hardhat-verify" : "2.0.8",
"@nomicfoundation/hardhat-ethers":"3.0.6"
}
}
30 changes: 30 additions & 0 deletions design/ux/on_tx_hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Platform-level traffic incentives

We want a flexible mechanism to incentivise traffic.

For example:
- every transaction is rewarded with a ZEN token
- if you hold over 1000 TEN tokens, you receive two ZEN tokens
- if you use the newly launched app X during the first week, you double your reward
- randomly, tx senders could receive hidden prizes
- every 1000 transactions, you receive 100 ZEN
- etc

## Solution

In the Genesis block, we deploy an upgradeable contract. The address is saved.
This contract will have a method `onTransactions(tx[])` that delegates to a dynamic implementation.

*Note1: The method receives all transactions from the batch.*
*Note2: The `tx` - is a reduced object containing everything except the calldata*


At the end of every batch, our EVM implementation will create a synthetic transaction that calls `onTransactions`.


## Discusson

- the logic should be simple because it will be applied to every transaction, and it will impact performance.
- The implementation can be changed at any time
- The contract should not fail.
-
1 change: 1 addition & 0 deletions integration/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
DefaultGethHTTPPortOffset = 400
DefaultPrysmP2PPortOffset = 500
DefaultPrysmRPCPortOffset = 550
DefaultPrysmGatewayPortOffset = 560
DefaultHostP2pOffset = 600 // The default offset for the host P2p
DefaultEnclaveOffset = 700 // The default offset between a Geth nodes port and the enclave ports. Used in Socket Simulations.
DefaultHostRPCHTTPOffset = 800 // The default offset for the host's RPC HTTP port
Expand Down
61 changes: 34 additions & 27 deletions integration/eth2network/main/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
prysmBeaconRPCStartPortName = "prysmBeaconRPCStartPort"
prysmBeaconRPCStartPortUsage = "The initial port to start allocating prysm rpc port"

prysmBeaconGatewayStartPortName = "prysmBeaconGatewayStartPort"
prysmBeaconGatewayStartPortUsage = "The gateway port to connect to prysm"

prysmBeaconP2PStartPortName = "prysmBeaconP2PtartPort"
prysmBeaconP2PStartPortUsage = "The p2p udp prysm port"

Expand All @@ -38,28 +41,30 @@ const (
)

type ethConfig struct {
chainID int
gethHTTPStartPort int
gethWSStartPort int
gethAuthRPCStartPort int
gethNetworkStartPort int
prysmBeaconRPCStartPort int
prysmBeaconP2PStartPort int
logLevel int
prefundedAddrs []string
chainID int
gethHTTPStartPort int
gethWSStartPort int
gethAuthRPCStartPort int
gethNetworkStartPort int
prysmBeaconRPCStartPort int
prysmBeaconP2PStartPort int
prysmBeaconGatewayStartPort int
logLevel int
prefundedAddrs []string
}

func defaultConfig() *ethConfig {
return &ethConfig{
chainID: 1337,
gethHTTPStartPort: 12000,
gethWSStartPort: 12100,
gethAuthRPCStartPort: 12200,
gethNetworkStartPort: 12300,
prysmBeaconRPCStartPort: 12400,
prysmBeaconP2PStartPort: 12500,
prefundedAddrs: []string{},
logLevel: int(gethlog.LvlDebug),
chainID: 1337,
gethHTTPStartPort: 12000,
gethWSStartPort: 12100,
gethAuthRPCStartPort: 12200,
gethNetworkStartPort: 12300,
prysmBeaconRPCStartPort: 12400,
prysmBeaconP2PStartPort: 12500,
prysmBeaconGatewayStartPort: 12600,
prefundedAddrs: []string{},
logLevel: int(gethlog.LvlDebug),
}
}

Expand All @@ -73,6 +78,7 @@ func parseCLIArgs() *ethConfig {
gethNetworkStartPort := flag.Int(gethNetworkStartPortName, defaultConfig.gethNetworkStartPort, gethNetworkStartPortUsage)
prysmBeaconP2PStartPort := flag.Int(prysmBeaconP2PStartPortName, defaultConfig.prysmBeaconP2PStartPort, prysmBeaconP2PStartPortUsage)
prysmBeaconRPCStartPort := flag.Int(prysmBeaconRPCStartPortName, defaultConfig.prysmBeaconRPCStartPort, prysmBeaconRPCStartPortUsage)
prysmBeaconGatewayStartPort := flag.Int(prysmBeaconGatewayStartPortName, defaultConfig.prysmBeaconGatewayStartPort, prysmBeaconGatewayStartPortUsage)
logLevel := flag.Int(logLevelName, defaultConfig.logLevel, logLevelUsage)
prefundedAddrs := flag.String(prefundedAddrsName, "", prefundedAddrsUsage)

Expand All @@ -91,14 +97,15 @@ func parseCLIArgs() *ethConfig {
}

return &ethConfig{
chainID: *chainID,
gethHTTPStartPort: *gethHTTPPort,
gethWSStartPort: *gethWSPort,
gethAuthRPCStartPort: *gethAuthRPCStartPort,
gethNetworkStartPort: *gethNetworkStartPort,
prysmBeaconRPCStartPort: *prysmBeaconRPCStartPort,
prysmBeaconP2PStartPort: *prysmBeaconP2PStartPort,
logLevel: *logLevel,
prefundedAddrs: parsedPrefundedAddrs,
chainID: *chainID,
gethHTTPStartPort: *gethHTTPPort,
gethWSStartPort: *gethWSPort,
gethAuthRPCStartPort: *gethAuthRPCStartPort,
gethNetworkStartPort: *gethNetworkStartPort,
prysmBeaconRPCStartPort: *prysmBeaconRPCStartPort,
prysmBeaconP2PStartPort: *prysmBeaconP2PStartPort,
prysmBeaconGatewayStartPort: *prysmBeaconGatewayStartPort,
logLevel: *logLevel,
prefundedAddrs: parsedPrefundedAddrs,
}
}
3 changes: 2 additions & 1 deletion integration/eth2network/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func main() {
config.gethWSStartPort,
config.gethHTTPStartPort,
config.prysmBeaconRPCStartPort,
config.prysmBeaconGatewayStartPort,
config.chainID,
6*time.Minute,
3*time.Minute,
config.prefundedAddrs...,
)

Expand Down
40 changes: 31 additions & 9 deletions integration/eth2network/pos_eth2_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -49,6 +50,7 @@ type PosImpl struct {
gethRPCPort int
gethHTTPPort int
beaconRPCPort int
beaconGatewayPort int
gethLogFile string
prysmBeaconLogFile string
prysmValidatorLogFile string
Expand All @@ -69,7 +71,7 @@ type PosEth2Network interface {
GenesisBytes() []byte
}

func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPort, gethWSPort, gethHTTPPort, beaconRPCPort, chainID int, timeout time.Duration, walletsToFund ...string) PosEth2Network {
func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPort, gethWSPort, gethHTTPPort, beaconRPCPort, beaconGatewayPort, chainID int, timeout time.Duration, walletsToFund ...string) PosEth2Network {
build, err := getBuildNumber()
if err != nil {
panic(fmt.Sprintf("could not get build number: %s", err.Error()))
Expand Down Expand Up @@ -129,6 +131,7 @@ func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPor
gethRPCPort: gethRPCPort,
gethHTTPPort: gethHTTPPort,
beaconRPCPort: beaconRPCPort,
beaconGatewayPort: beaconGatewayPort,
gethBinaryPath: gethBinaryPath,
prysmBinaryPath: prysmBinaryPath,
prysmBeaconBinaryPath: prysmBeaconBinaryPath,
Expand All @@ -155,7 +158,7 @@ func (n *PosImpl) Start() error {
err := eg.Wait()
go func() {
n.gethProcessID, n.beaconProcessID, n.validatorProcessID, err = startNetworkScript(n.gethNetworkPort, n.beaconP2PPort,
n.gethRPCPort, n.gethHTTPPort, n.gethWSPort, n.beaconRPCPort, n.chainID, n.buildDir, n.prysmBeaconLogFile,
n.gethRPCPort, n.gethHTTPPort, n.gethWSPort, n.beaconRPCPort, n.beaconGatewayPort, n.chainID, n.buildDir, n.prysmBeaconLogFile,
n.prysmValidatorLogFile, n.gethLogFile, n.prysmBeaconBinaryPath, n.prysmBinaryPath, n.prysmValidatorBinaryPath,
n.gethBinaryPath, n.gethdataDir, n.beacondataDir, n.validatordataDir)
time.Sleep(time.Second)
Expand All @@ -176,27 +179,44 @@ func (n *PosImpl) Stop() error {
}

func (n *PosImpl) checkExistingNetworks() error {
port := n.gethWSPort
_, err := ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", port))
_, err := ethclient.Dial(fmt.Sprintf("ws://127.0.0.1:%d", n.gethWSPort))
if err == nil {
return fmt.Errorf("unexpected geth node is active before the network is started")
}

client := http.Client{
Timeout: 2 * time.Second,
}

url := fmt.Sprintf("http://127.0.0.1:%d", n.beaconGatewayPort)

resp, err := client.Get(url)
if err == nil {
defer resp.Body.Close()
return fmt.Errorf("unexpected beacon node is active before the network is started")
}
return nil
}

// waitForMergeEvent connects to the geth node and waits until block 2 (the merge block) is reached
func (n *PosImpl) waitForMergeEvent(startTime time.Time) error {
ctx := context.Background()
dial, err := ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPort))
gethDial, err := ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.gethHTTPPort))
if err != nil {
return err
}

// wait for beacon process to start
time.Sleep(5 * time.Second)
_, err = ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.beaconGatewayPort))
if err != nil {
return err
}
time.Sleep(2 * time.Second)
number := uint64(0)
// wait for the merge block
err = retry.Do(
func() error {
number, err = dial.BlockNumber(ctx)
number, err = gethDial.BlockNumber(ctx)
if err != nil {
return err
}
Expand All @@ -213,7 +233,7 @@ func (n *PosImpl) waitForMergeEvent(startTime time.Time) error {

fmt.Printf("Reached the merge block after %s\n", time.Since(startTime))

if err = n.prefundedBalanceActive(dial); err != nil {
if err = n.prefundedBalanceActive(gethDial); err != nil {
fmt.Printf("Error prefunding account %s\n", err.Error())
return err
}
Expand All @@ -238,13 +258,14 @@ func (n *PosImpl) GenesisBytes() []byte {
return n.gethGenesisBytes
}

func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile,
func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, beaconGatewayPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile,
beaconBinary, prysmBinary, validatorBinary, gethBinary, gethdataDir, beacondataDir, validatordataDir string,
) (int, int, int, error) {
startScript := filepath.Join(basepath, "start-pos-network.sh")
gethNetworkPortStr := strconv.Itoa(gethNetworkPort)
beaconP2PPortStr := strconv.Itoa(beaconP2PPort)
beaconRPCPortStr := strconv.Itoa(beaconRPCPort)
beaconGatewayPortStr := strconv.Itoa(beaconGatewayPort)
gethHTTPPortStr := strconv.Itoa(gethHTTPPort)
gethWSPortStr := strconv.Itoa(gethWSPort)
gethRPCPortStr := strconv.Itoa(gethRPCPort)
Expand All @@ -257,6 +278,7 @@ func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPor
"--geth-ws", gethWSPortStr,
"--geth-rpc", gethRPCPortStr,
"--beacon-rpc", beaconRPCPortStr,
"--grpc-gateway-port", beaconGatewayPortStr,
"--chainid", chainStr,
"--build-dir", buildDir,
"--base-path", basepath,
Expand Down
3 changes: 2 additions & 1 deletion integration/eth2network/pos_eth2_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ func TestStartPosEth2Network(t *testing.T) {
_startPort+integration.DefaultGethWSPortOffset,
_startPort+integration.DefaultGethHTTPPortOffset,
_startPort+integration.DefaultPrysmRPCPortOffset,
_startPort+integration.DefaultPrysmGatewayPortOffset,
integration.EthereumChainID,
6*time.Minute,
3*time.Minute,
)

// wait until the merge has happened
Expand Down
3 changes: 3 additions & 0 deletions integration/eth2network/start-pos-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GETH_HTTP_PORT=8025
GETH_WS_PORT=9000
GETH_RPC_PORT=8552
BEACON_RPC_PORT=4000
BEACON_GATEWAY_PORT=3500
CHAIN_ID=1337
BUILD_DIR="./build"
BASE_PATH="./"
Expand Down Expand Up @@ -50,6 +51,7 @@ while [[ "$#" -gt 0 ]]; do
--geth-network) GETH_NETWORK_PORT="$2"; shift ;;
--beacon-p2p) BEACON_P2P_PORT="$2"; shift ;;
--beacon-rpc) BEACON_RPC_PORT="$2"; shift ;;
--grpc-gateway-port) BEACON_GATEWAY_PORT="$2"; shift ;;
--geth-http) GETH_HTTP_PORT="$2"; shift ;;
--geth-ws) GETH_WS_PORT="$2"; shift ;;
--geth-rpc) GETH_RPC_PORT="$2"; shift ;;
Expand Down Expand Up @@ -106,6 +108,7 @@ ${BEACON_BINARY} --datadir="${BEACONDATA_DIR}" \
--rpc-host=127.0.0.1 \
--rpc-port="${BEACON_RPC_PORT}" \
--p2p-udp-port="${BEACON_P2P_PORT}" \
--grpc-gateway-port=${BEACON_GATEWAY_PORT} \
--accept-terms-of-use \
--jwt-secret "${BASE_PATH}/jwt.hex" \
--suggested-fee-recipient 0x123463a4B065722E99115D6c222f267d9cABb524 \
Expand Down
1 change: 1 addition & 0 deletions integration/noderunner/noderunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) {
_startPort+integration.DefaultGethWSPortOffset,
_startPort+integration.DefaultGethHTTPPortOffset,
_startPort+integration.DefaultPrysmRPCPortOffset,
_startPort+integration.DefaultPrysmGatewayPortOffset,
integration.EthereumChainID,
3*time.Minute,
)
Expand Down
Loading

0 comments on commit 484278a

Please sign in to comment.