Giter VIP home page Giter VIP logo

socket-relayer's Introduction

Assignment - The objective of this exercise were as follows:

  1. Create a functional relayer
  2. Demonstrate understanding of the core components - Queue, Network Interaction, transaction Sending & Tracking

The Biconomy relayer-node has been used as the base for this exercise.

  1. The relayer (originally) supports three types of transaction relays - i) ERC4337 Compliant - AA | ii) Biconomy Smart Contract Wallet related | iii) Cross Chain with integrations to Wormhole and Axelar

Following are the core components in the entire flow:

  1. Server- It has a server which receives the transactions, identifies the transaction type and routes to the transactionHandler
  2. Transaction Sservice - with a transaction listener. It is used to create, execute and send a transaction and notify retry attempts.
  3. Network Service - connects to the blockchain via a Json rpcUrl
  4. Relayer Manager with load distribution algorithm based on strategy of sorting by balance and sorting by least pending count to allocate the transaction in queue to it
  5. Database Service - Redis for creating and maintaining a cache with information such as transactionId: retryCount | MongoDb for storing the transactions by Id and keeping their status and state and utilising it for resubmission based on transactionListener service
  6. Gas Price Service - managing, calculating and modifying gas limits when making retry attempts

In addition, there were FeeOptions, Notification Manager and Smart Contract Wallet components - which were more relevant to Biconomoy's specific use case. These have been removed.

The current submission allows for two of the flows:

  1. AA flow
  2. Cross Chain Transaction flow (Incomplete)

Requirements:

  1. Need wssUrl & httpUrl to replace the existing static config mentions

######################################################################################## ########################################################################################

Relayer Node

The Relayer Node is responsible for validating transactions, paying their gas fees, and sending them to the network. Relayers allow you to send transactions and take care of transaction sending, nonce management, gas pricing estimation, and resubmissions. This way you don’t need to worry about monitoring transactions to ensure they get mined. The Relayer infrastructure composes of multiple EOAs on each chain. Every relayer has an inbuilt auto-scaling functionality. Thus in cases of a high load of transactions, the relayer infra can spin up additional relayers to handle this. A socket server is attached to the relayer node via which one can subscribe and get updates on the transaction events like transaction hash generated, transaction mined, etc.

Local deployment

Requirements:

For centrifugo use the following base configuration file

{
  "token_hmac_secret_key": "averystrongsecret",
  "admin_password": "usedIfAdminSetToTrue",
  "admin_secret": "averystrongsecretforadmin",
  "api_key": "usedforpostapi",
  "allowed_origins": ["*"],
  "debug": true,
  "admin": true,
  "log_level": "debug",
  "client_anonymous": true,
  "client_channel_limit": 512,
  "namespaces": [
    {
      "name": "relayer",
      "publish": true,
      "history_size": 10,
      "history_ttl": "300s",
      "recover": true,
      "anonymous": false
    },
    {
      "name": "transaction",
      "publish": true,
      "history_size": 10,
      "history_ttl": "300s",
      "recover": true,
      "anonymous": true
    }
  ]
}

Steps to run the project

  1. Clone the project
git clone https://github.com/bcnmy/relayer-node.git
  1. Checkout to the main branch
git checkout main
  1. Install dependencies. Make sure node version is 16 or above.
yarn install
  1. Check if config.json.enc file exists in the config folder at the root of the repository. If not or if you want to make any changes in the configuration. Create a file config.json in the config folder. You can use the template shown below for local deployment or find the config-example.json file in the folder.
{
  "slack": {
    "token": "",
    "channel": ""
  },
  "dataSources": {
    "mongoUrl": "",
    "redisUrl": ""
  },
  "socketService": {
    "token": "",
    "apiKey": ""
  },
  "relayer": {
    "nodePathIndex": 0
  },
  "queueUrl": "",
  "simulationData": {
    "tenderlyData": {
      "tenderlyUser": "",
      "tenderlyProject": "",
      "tenderlyAccessKey": ""
    }
  },
  "chains": {
    "provider": {
      "5": "",
      "137": "",
      "80001": "",
      "97": "",
      "420": "",
      "421613": "",
      "43113": ""
    }
  },
  "relayerManagers": [{
    "relayerSeed": "",
    "ownerAccountDetails": {
      "5": {
        "publicKey": "",
        "privateKey": ""
      },
      "137": {
        "publicKey": "",
        "privateKey": ""
      },
      "80001": {
        "publicKey": "",
        "privateKey": ""
      },
      "97": {
        "publicKey": "",
        "privateKey": ""
      },
      "420": {
        "publicKey": "",
        "privateKey": ""
      },
      "421613": {
        "publicKey": "",
        "privateKey": ""
      },
      "43113": {
        "publicKey": "",
        "privateKey": ""
      }
    }
  }],
  "tokenPrice": {
    "coinMarketCapApi": ""
  }
}

Create a .env file and add the following:

CONFIG_PASSPHRASE=passphrase

Now To update the config.json.enc file:

CONFIG_PASSPHRASE=passphrase ts-node encrypt-config.ts
  1. To update the configuration for chain specific parameters (provider url, currency, decimals), relayer manager, fee options, and transactions use static-config.json in the config folder.

  2. Run the following code to start the project.

yarn run build && yarn run start

socket-relayer's People

Contributors

arcticfloyd1984 avatar jfdelgad avatar lovejeet avatar arunanksharan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.