Skip to content

Commit

Permalink
Add fakenet script to modify epoch rate
Browse files Browse the repository at this point in the history
  • Loading branch information
matejmode committed Nov 27, 2024
1 parent 3349c56 commit f22a5e3
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
24 changes: 21 additions & 3 deletions sonic/epoch-sealing-fakenet.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pipeline {
sh "sudo setcap 'cap_net_bind_service=+ep' ./build/sonicd"

catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
sh """timeout 60m ./build/sonicd \
sh """timeout 20m ./build/sonicd \
--mode=rpc \
--fakenet 1/1 \
--datadir=${SONICSTATEDB} \
Expand All @@ -95,10 +95,20 @@ pipeline {
}
}

stage('Modify epoch frequency') {
steps {
sleep(time:15,unit:"SECONDS")
dir('lascala/utils/network-rules-updator') {
sh "npm install"
sh 'node index.js --url http://127.0.0.1:80 --rulesPath rules-epoch-every-10sec.json'
}
}
}

stage('Validate fakenet') {
steps {
// wait 59 minutes then 1 minutes for validation is enough
sleep(time:3540,unit:"SECONDS")
// wait 19 minutes then 1 minutes for validation is enough
sleep(time:1140,unit:"SECONDS")

dir('lascala/utils') {
sh 'python3 validate-epoch-sealing.py 2 last http://127.0.0.1:80'
Expand All @@ -109,6 +119,14 @@ pipeline {
}
}

stage('Teardown') {
steps {
dir('lascala/utils/network-rules-updator') {
sh "rm -rf package-lock.json node_modules"
}
}
}

post {
always {
build job: '/Notifications/slack-notification', parameters: [
Expand Down
69 changes: 69 additions & 0 deletions utils/network-rules-updator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const {ethers, JsonRpcProvider, toQuantity, ZeroAddress, AbiCoder, getNumber} = require("ethers");
const fs = require("fs");
const NodeDriverAuthAddress = "0xd100ae0000000000000000000000000000000000";
const NodeDriverAuthAbi = [{
"constant": false,
"inputs": [{"internalType": "bytes", "name": "diff", "type": "bytes"}],
"name": "updateNetworkRules",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}];
const PRIVATE_KEY = "163f5f0f9a621d72fedd85ffca3d08d131ab4e812181e0d30ffd1c885d20aac7"
const PUBLIC_ADDR = "0x239fA7623354eC26520dE878B52f13Fe84b06971"

function prepareUpdateNetworkRulesCall(rulesPath) {
// load contents of rulesPath file and convert it to bytes
const rules = fs.readFileSync(rulesPath);
var rulesBytes = new Uint8Array(rules)
var iface = new ethers.Interface(NodeDriverAuthAbi)
var calldata = iface.encodeFunctionData("updateNetworkRules", [rulesBytes]);
return calldata;
}

/**
* @param {string} url
* @param {string} rulesPath
* @returns {Promise<void>}
*/
async function main(url, rulesPath) {
return new Promise(async (resolve) => {
const provider = new ethers.JsonRpcProvider(url);
const signer = new ethers.Wallet(PRIVATE_KEY, provider)

var calldata = prepareUpdateNetworkRulesCall(rulesPath);
const tx = await signer.sendTransaction({
to: NodeDriverAuthAddress,
data: calldata,
});
console.log(tx);

// confirm status of tx receipt
const receipt = await provider.waitForTransaction(tx.hash);
if (receipt.status !== 1) {
console.log(receipt);
} else {
console.log("Transaction receipt confirmed");
}

console.log("Rules updated - wait for next epoch for rules to take an effect...");

resolve(true);
})
}

const argv = require("minimist")(process.argv.slice(2), {string: ["url", "rulesPath"]});
if (argv.url === undefined) {
console.error("Missing required RPC endpoint URL address --url");
process.exit(1);
}

if (argv.rulesPath === undefined) {
console.error("Missing required new rulesPath --rulesPath");
process.exit(1);
}

main(argv.url, argv.rulesPath).catch(error => {
console.error(error);
}).then(() => console.log('done'));
16 changes: 16 additions & 0 deletions utils/network-rules-updator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "opera-epoch-seals",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ethers": "^6.13.2",
"minimist": "^1.2.8"
}
}
6 changes: 6 additions & 0 deletions utils/network-rules-updator/rules-epoch-every-10sec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Epochs": {
"MaxEpochDuration": 10000000000
}
}

0 comments on commit f22a5e3

Please sign in to comment.