Skip to content

Commit

Permalink
testnode-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed Mar 22, 2022
1 parent 50b5d74 commit 4668047
Show file tree
Hide file tree
Showing 8 changed files with 3,034 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ solgen/build
solgen/cache/
solgen/go
**/node_modules
/reproducible-wasm

target/**/*
brotli/buildfiles/**/*

# testnode-scripts go to a different docker image
testnode-scripts/
blockscout/

# Arbitrator ignores

# Rust outputs
Expand Down
26 changes: 17 additions & 9 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ services:
environment:
ETHEREUM_JSONRPC_VARIANT: 'geth'
ETHEREUM_JSONRPC_HTTP_URL: http://sequencer:7545/
INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER: true
INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER: "true"
DATABASE_URL: postgresql://postgres:@postgres:5432/blockscout?ssl=false
ECTO_USE_SSL: false
ECTO_USE_SSL: "false"
ports:
- 4000:4000

Expand Down Expand Up @@ -59,8 +59,8 @@ services:
volumes:
- "seqdata:/data"
- "l1keystore:/l1keystore"
- "deploydata:/deploydata"
command: --persistent.data /data --dev-init --l1.url ws://geth:8546 --l1.wallet.pathname /l1keystore --l1.wallet.password passphrase --l1.deployment /deploydata/deployment.json --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642 --http.vhosts * --http.api net,web3,eth,txpool,debug --node.archive
- "config:/config"
command: --dev-init --l1.url ws://geth:8546 --conf.file /config/sequencer_config.json --node.feed.output.enable --node.feed.output.port 9642 --http.vhosts * --http.api net,web3,eth,txpool,debug
depends_on:
- geth

Expand All @@ -73,8 +73,8 @@ services:
volumes:
- "unsafestaker-data:/data"
- "l1keystore:/l1keystore"
- "deploydata:/deploydata"
command: --persistent.data /data --dev-init --l1.url ws://geth:8546 --l1.wallet.pathname /l1keystore --l1.wallet.password passphrase --l1.deployment /deploydata/deployment.json --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.validator.enable --node.validator.strategy MakeNodes --node.validator.staker-interval 10s --node.forwarding-target null --node.validator.dangerous.without-block-validator --node.archive
- "config:/config"
command: --dev-init --l1.url ws://geth:8546 --conf.file /config/unsafe_staker_config.json
depends_on:
- sequencer

Expand All @@ -87,11 +87,19 @@ services:
volumes:
- "validator-data:/data"
- "l1keystore:/l1keystore"
- "deploydata:/deploydata"
command: --persistent.data /data --dev-init --l1.url ws://geth:8546 --l1.wallet.pathname /l1keystore --l1.wallet.password passphrase --l1.deployment /deploydata/deployment.json --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.validator.enable --node.validator.strategy MakeNodes --node.validator.staker-interval 10s --node.forwarding-target null --node.archive
- "config:/config"
command: --dev-init --l1.url ws://geth:8546 --conf.file /config/validator_config.json
depends_on:
- sequencer

testnode-scripts:
build: testnode_scripts/
volumes:
- "l1keystore:/l1keystore"
- "config:/config"
depends_on:
- geth

relay:
pid: host
build: .
Expand All @@ -106,6 +114,6 @@ volumes:
seqdata:
unsafestaker-data:
validator-data:
deploydata:
config:
postgres-data:

20 changes: 16 additions & 4 deletions test-node.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ else
force_init=false
fi

run=true
force_build=false
validate=false
while [[ $# -gt 0 ]]; do
Expand All @@ -45,13 +46,18 @@ while [[ $# -gt 0 ]]; do
validate=true
shift
;;
--no-run)
run=false
shift
;;
*)
echo Usage: $0 \[OPTIONS..]
echo
echo OPTIONS:
echo --build: rebuild docker image
echo --init: remove all data, rebuild, deploy new rollup
echo --validate: heavy computation, validating all blocks in WASM
echo --no-run: does not launch nodes \(usefull with build or init\)
exit 0
esac
done
Expand All @@ -74,12 +80,16 @@ if $force_init; then
fi
docker volume prune -f --filter label=com.docker.compose.project=nitro

echo == Generating l1 key
echo == Generating l1 keys
docker-compose run --entrypoint sh geth -c "echo passphrase > /root/.ethereum/passphrase"
docker-compose run geth account new --password /root/.ethereum/passphrase --keystore /keystore
docker-compose run geth account new --password /root/.ethereum/passphrase --keystore /keystore
docker-compose run geth account new --password /root/.ethereum/passphrase --keystore /keystore

echo == funding validator and writing configs
docker-compose run testnode-scripts index.js --l1url ws://geth:8546 --l1keystore /l1keystore --config /config/ --writeconf --fundvalidator

echo == Deploying L2
docker-compose run --entrypoint target/bin/deploy sequencer -l1conn ws://geth:8546 -l1keystore /l1keystore -l1deployment /deploydata/deployment.json -authorizevalidators 10
docker-compose run --entrypoint target/bin/deploy sequencer -l1conn ws://geth:8546 -l1keystore /l1keystore -l1deployment /config/deployment.json -authorizevalidators 10
fi

echo == Launching Sequencer
Expand All @@ -90,4 +100,6 @@ if $validate; then
else
STAKER_NODE="staker-unsafe"
fi
docker-compose up sequencer $STAKER_NODE blockscout
if $run; then
docker-compose up sequencer $STAKER_NODE blockscout
fi
1 change: 1 addition & 0 deletions testnode_scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions testnode_scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:17
WORKDIR /workspace
RUN npm install -g typescript
COPY ./package.json ./yarn.lock ./
RUN yarn
COPY ./*.ts ./
RUN tsc *.ts
110 changes: 110 additions & 0 deletions testnode_scripts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const Web3 = require('web3')
const fs = require('fs')
const yargs = require('yargs')
const { hideBin } = require('yargs/helpers')
const path = require('path');


async function setupValidator(l1url: string, keystorePath: string, configpath: string, fund: boolean, writeconf: boolean) {
const web3 = new Web3(l1url)

var keyFilenames = fs.readdirSync(keystorePath)
keyFilenames.sort()

const encKey = JSON.parse(fs.readFileSync(path.join(keystorePath, keyFilenames[0])))
const decryptedFaucet = web3.eth.accounts.decrypt(encKey, "passphrase")
const validatorAddress = JSON.parse(fs.readFileSync(path.join(keystorePath, keyFilenames[1]))).address

if (fund) {
const valueToSend = web3.utils.toHex(web3.utils.toWei("10", 'ether'))
const nonce = await web3.eth.getTransactionCount(decryptedFaucet.address, 'latest'); // nonce starts counting from 0
const gasPrice = await web3.eth.getGasPrice()
const gasEstimate = await web3.eth.estimateGas({
from: decryptedFaucet.address,
to: validatorAddress,
value: valueToSend,
nonce: nonce
})
const transaction = {
'to': validatorAddress, // faucet address to return eth
'value': valueToSend,
'gas': gasPrice * 2,
'gasLimit': gasEstimate * 2,
'nonce': nonce,
// optional data field to send message or execute smart contract
};

const signedTx = await web3.eth.accounts.signTransaction(transaction, decryptedFaucet.privateKey);

const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);

console.log(receipt)
}

if (writeconf) {
const baseConfig = {
"l1": {
"deployment": "/config/deployment.json",
"wallet": {
"account": "",
"password": "passphrase",
"pathname": keystorePath,
},
},
"node": {
"archive": true,
"forwarding-target": "null",
"validator": {
"dangerous": {
"without-block-validator": false
},
"disable-challenge": false,
"enable": false,
"staker-interval": "10s",
"strategy": "MakeNodes",
"target-machine-count": 4,
},
"sequencer": {
"enable": false
}
},
"persistent": {
"data": "/data"
},
"ws": {
"addr": "0.0.0.0"
},
"http": {
"addr": "0.0.0.0"
},
}
const baseConfJSON = JSON.stringify(baseConfig)

var validatorConfig = JSON.parse(baseConfJSON)
validatorConfig.l1.wallet.account = validatorAddress
validatorConfig.node.validator.enable = true
var validconfJSON = JSON.stringify(validatorConfig)
fs.writeFileSync(path.join(configpath, "validator_config.json"), validconfJSON)

var unsafeStakerConfig = JSON.parse(validconfJSON)
unsafeStakerConfig.node.validator.dangerous["without-block-validator"] = true
fs.writeFileSync(path.join(configpath, "unsafe_staker_config.json"), JSON.stringify(unsafeStakerConfig))

var sequencerConfig = JSON.parse(baseConfJSON)
sequencerConfig.l1.wallet.account = decryptedFaucet.address
sequencerConfig.node.sequencer.enable = true
fs.writeFileSync(path.join(configpath, "sequencer_config.json"), JSON.stringify(sequencerConfig))
}

web3.currentProvider.connection.close()
}

async function main() {
const argv = yargs(hideBin(process.argv)).argv

console.log(argv)

await setupValidator(argv.l1url, argv.l1keystore, argv.config, argv.fundvalidator, argv.writeconf)
}

main();
16 changes: 16 additions & 0 deletions testnode_scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "nitro_test",
"version": "1.0.0",
"description": "testing environment Arbitrum Nitro",
"main": "index.js",
"author": "Offchain Labs, Inc.",
"license": "Apache-2.0",
"dependencies": {
"fs": "^0.0.1-security",
"path": "^0.12.7",
"web3": "^1.7.1",
"yargs": "^17.4.0"
},
"private": true,
"devDependencies": {}
}
Loading

0 comments on commit 4668047

Please sign in to comment.