-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add settlement module with batch add and verify functions
- Implemented the settlement module in the sequencer. - This module introduces 'add batch' and 'verify batch' functionalities. - Enhances the sequencer's efficiency in handling batch operations. Co-authored-by: Uddesh Jaiswal <[email protected]> Co-authored-by: Rahul Singh Maraskole <[email protected]> Co-authored-by: Shubham Sharma <[email protected]> Co-authored-by: Kritarth Agrawal <[email protected]> Co-authored-by: Shobhit Sharma <[email protected]>
- Loading branch information
1 parent
841e31d
commit 7fa3328
Showing
20 changed files
with
636 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
![Project Logo](https://www.airchains.io/assets/logos/airchains-svm-rollup-full-logo.png) | ||
|
||
# Overview | ||
|
||
The SVM Chain Sequencer is a groundbreaking, high-performance tool developed to enhance transaction and block management on Smart Virtual Machine (SVM) chains. This innovative tool is distinguished by its integration of cutting-edge technologies and processes, tailored specifically for SVM chains, to ensure streamlined, efficient, and reliable blockchain operations. | ||
|
||
## Table of Contents | ||
|
||
- [Overview](#overview) | ||
- [Table of Contents](#table-of-contents) | ||
- [Key Features](#key-features) | ||
- [Usage](#usage) | ||
- [Script Files Overview](#script-files-overview) | ||
- [License](#license) | ||
- [Acknowledgments](#acknowledgments) | ||
|
||
## Key Features | ||
|
||
- **Optimized Transaction Processing**: Utilizes advanced algorithms to effectively manage and process transactions, significantly increasing throughput and reducing latency in SVM chain environments. | ||
|
||
- **Sophisticated Block Management**: The sequencer is equipped with refined block management capabilities, ensuring smooth and efficient block generation and propagation within the SVM ecosystem. | ||
|
||
- **Data Integrity and Availability**: Integrates robust Data Availability (DA) processes, vital for maintaining the integrity and accessibility of data on the chain. This feature enhances the trustworthiness and transparency of the SVM network. | ||
|
||
- **Custom Batching Techniques**: Features bespoke batching techniques that are specifically designed for SVM chains, optimizing the handling of transaction loads and enhancing overall network performance. | ||
|
||
- **Seamless Integration with SVM Layer**: Designed to seamlessly integrate with the SVM layer, the sequencer maintains consistent performance and compatibility, reinforcing the strength and stability of SVM-based applications. | ||
|
||
- **High Scalability and Flexibility**: Built to accommodate the growing demands of SVM chains, offering scalable solutions that adapt to varying transaction volumes and network conditions. | ||
|
||
- **Reliability and Security**: Prioritizes reliability and security in its design, ensuring that the SVM Chain Sequencer operates with high resilience and robustness, safeguarding against potential threats and vulnerabilities. | ||
|
||
## 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. | ||
|
||
## Script Files Overview | ||
|
||
This repository includes a set of four essential script files designed to facilitate various operational aspects of the node. Each script has a specific purpose, detailed below: | ||
|
||
- **init.sh**: This script is responsible for setting up the initial environment. It creates all necessary folders and files required for the node's operation. | ||
|
||
``` | ||
sh scripts/init.sh | ||
``` | ||
|
||
- **start.sh**: Designed to simply start the node without altering its current state or block height. Ideal for routine starts where no changes to the environment are needed. | ||
|
||
``` | ||
sh scripts/start.sh | ||
``` | ||
|
||
- **restart.sh**: Used for refreshing the node's environment. It first deletes and then recreates all folders and files, followed by restarting the node to apply these changes. | ||
|
||
``` | ||
sh scripts/restart.sh | ||
``` | ||
|
||
- **test.sh**: As the name suggests, this script is used for testing purposes. It contains commands and procedures specifically intended for testing the node's functionalities and performance. | ||
|
||
``` | ||
sh scripts/test.sh | ||
``` | ||
|
||
> Note: before proceeding to run the sequencer, please ensure that the `init.sh` script has been executed to initialize the basic directory structure and configuration files. | ||
_Important Security Notice Regarding init.sh Execution_ | ||
|
||
Please be aware that running the `init.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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package settlement_client | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/airchains-network/svm-sequencer-node/common" | ||
"github.com/airchains-network/svm-sequencer-node/common/logs" | ||
"github.com/airchains-network/svm-sequencer-node/types" | ||
"github.com/syndtr/goleveldb/leveldb" | ||
"io" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type PostAddBatchStruct struct { | ||
ChainID string `json:"chain_id"` | ||
BatchNumber uint64 `json:"batch_number"` | ||
Witness []byte `json:"witness"` | ||
} | ||
|
||
func AddBatch(witnessVector any, batchNumber int, lds *leveldb.DB) string { | ||
|
||
logs.LogMessage("INFO:", "Submitting batch to settlement") | ||
|
||
settlementChainInfoByte, err := lds.Get([]byte("settlementChainInfo"), nil) | ||
if err != nil { | ||
logs.LogMessage("ERROR:", fmt.Sprintf("Error in getting settlementChainInfo from static db : %s", err.Error())) | ||
return "nil" | ||
} | ||
|
||
var settlementChainInfo types.SettlementLayerChainInfoStruct | ||
err = json.Unmarshal(settlementChainInfoByte, &settlementChainInfo) | ||
if err != nil { | ||
logs.LogMessage("ERROR:", fmt.Sprintf("Error in unmarshalling settlementChainInfo : %s", err.Error())) | ||
return "nil" | ||
} | ||
chainID := settlementChainInfo.ChainId | ||
|
||
//var frVector fr.Vector | ||
|
||
wvByte, _ := json.Marshal(witnessVector) | ||
|
||
postAddBatchStruct := PostAddBatchStruct{ | ||
ChainID: chainID, | ||
BatchNumber: uint64(batchNumber), | ||
Witness: wvByte, | ||
} | ||
|
||
jsonData, err := json.Marshal(postAddBatchStruct) | ||
if err != nil { | ||
logs.LogMessage("ERROR:", fmt.Sprintf("Error in marshalling postAddBatchStruct : %s", err.Error())) | ||
return "nil" | ||
} | ||
rpcUrl := fmt.Sprintf("%s/add_batch", common.SettlementClientRPC) | ||
req, err := http.NewRequest("POST", rpcUrl, bytes.NewBuffer(jsonData)) | ||
if err != nil { | ||
logs.LogMessage("ERROR:", fmt.Sprintf("Error creating request:", err)) | ||
return "nil" | ||
} | ||
|
||
req.Header.Set("Content-Type", "application/json") | ||
logs.LogMessage("INFO:", "Sending request to settlement client") | ||
// Send the request | ||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
logs.LogMessage("ERROR:", fmt.Sprintf("Error sending request:", err)) | ||
return "nil" | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Read and unmarshal the response | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
logs.LogMessage("ERROR:", fmt.Sprintf("Error reading response:", err)) | ||
return "nil" | ||
} | ||
|
||
var response types.SettlementClientResponseStruct | ||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
logs.LogMessage("ERROR:", fmt.Sprintf("Error unmarshalling response:", err)) | ||
return "nil" | ||
} | ||
|
||
if !response.Status { | ||
logs.LogMessage("ERROR:", "error in adding batch to settlement") | ||
logs.LogMessage("INFO:", "Retrying in 5 seconds...") | ||
time.Sleep(5 * time.Second) | ||
AddBatch(witnessVector, batchNumber, lds) | ||
} | ||
|
||
return response.Data | ||
} |
Oops, something went wrong.