Skip to content

Commit

Permalink
new sequencer for junction
Browse files Browse the repository at this point in the history
  • Loading branch information
aakash4dev committed Jan 23, 2024
0 parents commit eaba581
Show file tree
Hide file tree
Showing 33 changed files with 27,751 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/data
provingKey.txt
verificationKey.txt
verificationKey.json
.idea
.DS_Store
.env
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Uddesh Jaiswal <[email protected]>
Rahul Singh Maraskole <[email protected]>
Kritarth Agrawal <[email protected]>
Shubham Sharma <[email protected]>
Shobhit Sharma <[email protected]>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Airchains

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
![Project Logo](https://www.airchains.io/assets/logos/airchains-evm-rollup-full-logo.png)

# Overview

EVM Chain Sequencer is a high-performance, innovative tool designed to optimize transaction and block management on Ethereum Virtual Machine (EVM) chains. This tool stands out for its integration of advanced batching and Data Availability (DA) processes, ensuring efficient and reliable blockchain operations.

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Key Features](#key-features)
- [Usage](#usage)
- [License](#license)
- [Acknowledgments](#acknowledgments)

## Key Features

- **Enhanced Transaction Batching**: Implements sophisticated algorithms for efficient transaction aggregation, significantly improving throughput and reducing latency.

- **Data Availability (DA) Processes**: Incorporates robust DA mechanisms to ensure data integrity and accessibility, enhancing trust and transparency in the blockchain network.

- **Seamless Settlement Layer Integration**: Designed for smooth interaction with the settlement layer, maintaining operational integrity and consistent performance.

- **High Throughput and Reliability**: Focuses on handling large volumes of transactions effectively, ensuring both high throughput and steadfast reliability in blockchain operations.

## Usage

In order to tailor the Sequencer to better align with your specific requirements, please proceed to update key configuration parameters within the `common/constants.go` file. The following constants are crucial for the optimal functioning of the sequencer and can be adjusted to meet your operational needs:

- **BatchSize**: Modify this value to alter the batch size for transaction processing. This adjustment can optimize throughput and efficiency based on your workload.

- **BlockDelay**: Adjust this constant to set the delay between blocks check, aligning it with your network's block generation rate for synchronized operations.

- **ExecutionClientRPC**: Update this URL to connect the sequencer with your preferred execution client's RPC interface.

- **SettlementClientRPC**: Change this URL to integrate the sequencer with the desired settlement layer's RPC service.

- **KeyringDirectory**: Specify a new directory path for the keyring, ensuring secure and organized storage of cryptographic keys.

- **DaClientRPC**: Alter this URL to link the sequencer with your chosen Data Availability (DA) service's RPC endpoint.

Each of these parameters plays a critical role in the configuration and performance of the sequencer. It is recommended to carefully consider the implications of these changes to maintain optimal functionality and security of the system.

> Note: before proceeding to run the sequencer, please ensure that the `init_dir.sh` script has been executed to initialize the basic directory structure and configuration files.
_Important Security Notice Regarding init_dir.sh Execution_

Please be aware that running the `init_dir.sh` script necessitates the entry of your terminal password. This requirement stems from the inclusion of `sudo` commands within the script. These commands elevate privileges for certain operations, which are essential for the correct setup and configuration of the environment.

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Acknowledgments

Special thanks to the `gnark` library, an efficient and elegant toolkit for zk-SNARKs on Go. This library has been instrumental in our development process. For more information and to explore their work, visit their GitHub repository at [Consensys/gnark.](https://github.com/Consensys/gnark)
151 changes: 151 additions & 0 deletions airdb/air-leveldb/leveldb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package air_leveldb

import (
"github.com/syndtr/goleveldb/leveldb"
"log"
)

var txDbInstance *leveldb.DB
var blockDbInstance *leveldb.DB
var staticDbInstance *leveldb.DB
var batchesDbInstance *leveldb.DB
var proofDbInstance *leveldb.DB
var publicWitnessDbInstance *leveldb.DB
var daDbInstance *leveldb.DB

// The function initializes a LevelDB database for transactions and returns a boolean indicating
// whether the initialization was successful.
func InitTxDb() bool {
txDB, err := leveldb.OpenFile("data/leveldb/tx", nil)
if err != nil {
log.Fatal("Failed to open transaction LevelDB:", err)
return false
}
txDbInstance = txDB
return true
}

// The function initializes a LevelDB database for storing blocks and returns a boolean indicating
// whether the initialization was successful.
func InitBlockDb() bool {
blockDB, err := leveldb.OpenFile("data/leveldb/blocks", nil)
if err != nil {
log.Fatal("Failed to open block LevelDB:", err)
return false
}
blockDbInstance = blockDB
return true
}

// The function initializes a static LevelDB database and returns a boolean indicating whether the
// initialization was successful or not.
func InitStaticDb() bool {
staticDB, err := leveldb.OpenFile("data/leveldb/static", nil)
if err != nil {
log.Fatal("Failed to open static LevelDB:", err)
return false
}
staticDbInstance = staticDB
return true
}

// The function initializes a batches LevelDB database and returns a boolean indicating whether the
// initialization was successful or not.
func InitBatchesDb() bool {
batchesDB, err := leveldb.OpenFile("data/leveldb/batches", nil)
if err != nil {
log.Fatal("Failed to open batches LevelDB:", err)
return false
}
batchesDbInstance = batchesDB
return true
}

// The function initializes a proof LevelDB database and returns a boolean indicating whether the
// initialization was successful or not.
func InitProofDb() bool {
proofDB, err := leveldb.OpenFile("data/leveldb/proof", nil)
if err != nil {
log.Fatal("Failed to open proof LevelDB:", err)
return false
}
proofDbInstance = proofDB
return true
}

func InitPublicWitnessDb() bool {
publicWitnessDB, err := leveldb.OpenFile("data/leveldb/publicWitness", nil)
if err != nil {
log.Fatal("Failed to open public witness LevelDB:", err)
return false
}
publicWitnessDbInstance = publicWitnessDB
return true
}

func InitDaDb() bool {
daDB, err := leveldb.OpenFile("data/leveldb/da", nil)
if err != nil {
log.Fatal("Failed to open da LevelDB:", err)
return false
}
daDbInstance = daDB
return true
}

// The function `InitDb` initializes three different databases and returns true if all of them are
// successfully initialized, otherwise it returns false.
func InitDb() bool {
txStatus := InitTxDb()
blockStatus := InitBlockDb()
staticStatus := InitStaticDb()
batchesStatus := InitBatchesDb()
proofStatus := InitProofDb()
publicWitnessStatus := InitPublicWitnessDb()
daDbInstanceStatus := InitDaDb()

if txStatus && blockStatus && staticStatus && batchesStatus && proofStatus && publicWitnessStatus && daDbInstanceStatus {
return true
} else {
return false
}
}

// The function GetTxDbInstance returns the instance of the air-leveldb database.
func GetTxDbInstance() *leveldb.DB {
return txDbInstance
}

// The function returns the instance of the block database.
func GetBlockDbInstance() *leveldb.DB {
return blockDbInstance
}

// The function `GetStaticDbInstance()` is returning the instance of the LevelDB database that was
// initialized in the `InitStaticDb()` function. This allows other parts of the code to access and use
// the LevelDB database instance for performing operations such as reading or writing data.
func GetStaticDbInstance() *leveldb.DB {
return staticDbInstance
}

// The function `GetBatchesDbInstance()` is returning the instance of the LevelDB database that was
// initialized in the `InitBatchesDb()` function. This allows other parts of the code to access and use
// the LevelDB database instance for performing operations such as reading or writing data.
func GetBatchesDbInstance() *leveldb.DB {
return batchesDbInstance
}

// The function `GetProofDbInstance()` is returning the instance of the LevelDB database that was
// initialized in the `InitProofDb()` function. This allows other parts of the code to access and use
// the LevelDB database instance for performing operations such as reading or writing data.
func GetProofDbInstance() *leveldb.DB {
return proofDbInstance
}

func GetPublicWitnessDbInstance() *leveldb.DB {
return publicWitnessDbInstance
}

func GetDaDbInstance() *leveldb.DB {
return daDbInstance
}
12 changes: 12 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package common

import "os"


const BatchSize = 25
const BlockDelay = 5
const ExecutionClientRPC = "http://localhost:8545/"
const SettlementClientRPC = "http://localhost:8080"
const KeyringDirectory = "./account/keys"
var DaClientRPC = os.Getenv("DA_CLIENT_RPC")
// const DaClientRPC = "http://localhost:5050/celestia"
87 changes: 87 additions & 0 deletions common/functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package common

import (
"context"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc"
"io"
"log"
"math/big"
"net/http"
"strconv"
"strings"
)

func ToString(value interface{}) string {
switch v := value.(type) {
case string:
return v
case []interface{}:
jsonBytes, _ := json.Marshal(v)
return string(jsonBytes)
default:
return fmt.Sprintf("%v", v)
}
}

func GetBalance(address string, blockNumber uint64) (string, error) {
payload := fmt.Sprintf(`{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["%s", "%s"],
"id": 1
}`, address, "0x"+strconv.FormatUint(blockNumber, 16))

resp, err := http.Post(ExecutionClientRPC, "application/json", strings.NewReader(payload))
if err != nil {
return "", err
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}

var jsonResponse map[string]interface{}
err = json.Unmarshal(body, &jsonResponse)
if err != nil {
return "", err
}

if errMsg, ok := jsonResponse["error"]; ok {
return "", fmt.Errorf("error from Ethereum node: %v", errMsg)
}

if result, ok := jsonResponse["result"].(string); ok {
balance, success := new(big.Int).SetString(result[2:], 16)
if !success {
return "", fmt.Errorf("failed to parse balance")
}

etherBalance := new(big.Float).Quo(new(big.Float).SetInt(balance), new(big.Float).SetInt64(1e18))
return etherBalance.String(), nil
} else {
log.Fatal("Failed to parse balance")
return "", err
}
}

func GetAccountNonce(ctx context.Context, address string, blockNumber uint64) (string, error) {
client, err := rpc.Dial(ExecutionClientRPC)
if err != nil {
return "0", err
}
accountAddress := common.HexToAddress(address)
formatedBlockNumber := "0x" + strconv.FormatUint(blockNumber, 16)
var result string
err = client.CallContext(ctx, &result, "eth_getTransactionCount", accountAddress, formatedBlockNumber)
if err != nil {
fmt.Println("Error getting transaction count:", err)
return "0", err
}

return result, nil
}
7 changes: 7 additions & 0 deletions common/logs/logMsg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package logs

import (
"github.com/ComputerKeeda/sslogger"
)

var Log sslogger.Logger
15 changes: 15 additions & 0 deletions config/chainInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"chainInfo": {
"chainID": "aircosmic_2605-1107",
"key": "AccountName",
"moniker": "ChainName"
},
"daInfo": {
"daSelected": "Celestia",
"daWalletAddress": "0xaddress",
"daWalletKeypair": "0xaddress"
},
"sequencerInfo": {
"sequencerType": "Air Sequencer"
}
}
Loading

0 comments on commit eaba581

Please sign in to comment.