Skip to content

Instantly share code, notes, and snippets.

@tristan
Last active October 26, 2020 16:12
Show Gist options
  • Save tristan/6d02fca748413c4855a9210c46d817a6 to your computer and use it in GitHub Desktop.
Save tristan/6d02fca748413c4855a9210c46d817a6 to your computer and use it in GitHub Desktop.
testing parity instantSeal
#!/bin/bash
set -x
# find some available ports to use
PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
WS_PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
JSONRPC_PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
# create a temp directory
TMP_DIR=$(mktemp -d)
# check the parity version
VERSION=$(parity --version | grep Parity-Ethereum/v2 | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')
if [[ $(echo "2.5.8
$VERSION" | sort -V | head -n 1) == 2.5.8 ]]; then
USE_OLD_CHAIN=0
else
USE_OLD_CHAIN=1
fi
# generate chain file
if [[ $USE_OLD_CHAIN == 1 ]]; then
# for version 2.5.7 and earlier
cat <<EOF > $TMP_DIR/chain.json
{
"name": "testing.parity.dev",
"params": {
"gasLimitBoundDivisor": "0x0400",
"accountStartNonce": "0x0100000",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"eip150Transition": "0x0",
"eip160Transition": "0x0",
"eip161abcTransition": "0x0",
"eip161dTransition": "0x0",
"eip155Transition": "0x0",
"eip140Transition": "0x0",
"eip211Transition": "0x0",
"eip214Transition": "0x0",
"eip658Transition": "0x0",
"eip145Transition": "0x0",
"eip1014Transition": "0x0",
"eip1052Transition": "0x0",
"wasmActivationTransition": "0x0",
"networkID": "0x42"
},
"accounts": {
"0000000000000000000000000000000000000001": {
"balance": "1",
"builtin": {
"name": "ecrecover",
"pricing": {
"linear": {
"base": 3000,
"word": 0
}
}
}
},
"0000000000000000000000000000000000000002": {
"balance": "1",
"builtin": {
"name": "sha256",
"pricing": {
"linear": {
"base": 60,
"word": 12
}
}
}
},
"0000000000000000000000000000000000000003": {
"balance": "1",
"builtin": {
"name": "ripemd160",
"pricing": {
"linear": {
"base": 600,
"word": 120
}
}
}
},
"0000000000000000000000000000000000000004": {
"balance": "1",
"builtin": {
"name": "identity",
"pricing": {
"linear": {
"base": 15,
"word": 3
}
}
}
},
"0000000000000000000000000000000000000005": {
"builtin": {
"name": "modexp",
"activate_at": "0x0",
"pricing": {
"modexp": {
"divisor": 2
}
}
}
},
"0000000000000000000000000000000000000006": {
"builtin": {
"name": "alt_bn128_add",
"activate_at": "0x0",
"pricing": {
"linear": {
"base": 500,
"word": 0
}
}
}
},
"0000000000000000000000000000000000000007": {
"builtin": {
"name": "alt_bn128_mul",
"activate_at": "0x0",
"pricing": {
"linear": {
"base": 40000,
"word": 0
}
}
}
},
"0000000000000000000000000000000000000008": {
"builtin": {
"name": "alt_bn128_pairing",
"activate_at": "0x0",
"pricing": {
"alt_bn128_pairing": {
"base": 100000,
"pair": 80000
}
}
}
},
"f0fd3db9396b084d26d4f838eade9f111a715a29": {
"balance": "1606938044258990275541962092341162602522202993782792835301376",
"nonce": "1048576"
}
},
"engine": {
"instantSeal": {
"params": {}
}
},
"genesis": {
"seal": {
"generic": "0x0"
},
"difficulty": "0x400",
"author": "0x0102030405060708090001020304050607080900",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x7A1200"
}
}
EOF
else
# for version 2.5.8 and later
cat <<EOF > $TMP_DIR/chain.json
{
"name": "testing.parity.dev",
"params": {
"gasLimitBoundDivisor": "0x0400",
"accountStartNonce": "0x0100000",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"eip150Transition": "0x0",
"eip160Transition": "0x0",
"eip161abcTransition": "0x0",
"eip161dTransition": "0x0",
"eip155Transition": "0x0",
"eip98Transition": "0x7fffffffffffff",
"maxCodeSize": 24576,
"maxCodeSizeTransition": "0x0",
"eip140Transition": "0x0",
"eip211Transition": "0x0",
"eip214Transition": "0x0",
"eip658Transition": "0x0",
"eip145Transition": "0x0",
"eip1014Transition": "0x0",
"eip1052Transition": "0x0",
"wasmActivationTransition": "0x0",
"networkID": "0x42"
},
"accounts": {
"0000000000000000000000000000000000000001": {
"balance": "1",
"builtin": {
"name": "ecrecover",
"pricing": {
"linear": {
"base": 3000,
"word": 0
}
}
}
},
"0000000000000000000000000000000000000002": {
"balance": "1",
"builtin": {
"name": "sha256",
"pricing": {
"linear": {
"base": 60,
"word": 12
}
}
}
},
"0000000000000000000000000000000000000003": {
"balance": "1",
"builtin": {
"name": "ripemd160",
"pricing": {
"linear": {
"base": 600,
"word": 120
}
}
}
},
"0000000000000000000000000000000000000004": {
"balance": "1",
"builtin": {
"name": "identity",
"pricing": {
"linear": {
"base": 15,
"word": 3
}
}
}
},
"0000000000000000000000000000000000000005": {
"balance": "1",
"builtin": {
"name": "modexp",
"activate_at": 0,
"pricing": {
"modexp": {
"divisor": 20
}
}
}
},
"0000000000000000000000000000000000000006": {
"balance": "1",
"builtin": {
"name": "alt_bn128_add",
"activate_at": 0,
"eip1108_transition": "0x7fffffffffffff",
"pricing": {
"alt_bn128_const_operations": {
"price": 500,
"eip1108_transition_price": 150
}
}
}
},
"0000000000000000000000000000000000000007": {
"balance": "1",
"builtin": {
"name": "alt_bn128_mul",
"activate_at": 0,
"eip1108_transition": "0x7fffffffffffff",
"pricing": {
"alt_bn128_const_operations": {
"price": 40000,
"eip1108_transition_price": 6000
}
}
}
},
"0000000000000000000000000000000000000008": {
"balance": "1",
"builtin": {
"name": "alt_bn128_pairing",
"activate_at": 0,
"eip1108_transition": "0x7fffffffffffff",
"pricing": {
"alt_bn128_pairing": {
"base": 100000,
"pair": 80000,
"eip1108_transition_base": 45000,
"eip1108_transition_pair": 34000
}
}
}
},
"f0fd3db9396b084d26d4f838eade9f111a715a29": {
"balance": "1606938044258990275541962092341162602522202993782792835301376",
"nonce": "1048576"
}
},
"engine": {
"instantSeal": {
"params": {}
}
},
"genesis": {
"seal": {
"generic": "0x0"
},
"difficulty": "0x400",
"author": "0x0102030405060708090001020304050607080900",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x7A1200"
}
}
EOF
fi
# start parity
/usr/bin/parity --port $PORT --no-color --chain $TMP_DIR/chain.json --author 0102030405060708090001020304050607080900 --tracing on --node-key 74a32e8a5ea986ebb4becf4746a09b2bb7abb8ee09f6ead3bc4c0d8968fc27ed --base-path $TMP_DIR/data --jsonrpc-port $JSONRPC_PORT --jsonrpc-hosts all --ws-interface local --ws-port $WS_PORT --ws-origins all --ws-hosts all --min-gas-price 10000000000 --logging "own_tx=trace,rpc=trace,chain=trace,engine=trace,miner=trace,state=trace" &
PARITY_PID=$!
finish() {
kill $PARITY_PID
wait $PARITY_PID
rm -r $TMP_DIR
}
trap finish EXIT
next_id() {
echo $((1 + RANDOM % 100000))
}
NODE_URL=http://localhost:$JSONRPC_PORT
# wait for boot
while ! curl -s -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"eth_blockNumber\", \"id\": \"$(next_id)\", \"params\": []}" $NODE_URL; do
sleep 1
done
send_transaction() {
curl -s -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"eth_sendRawTransaction\", \"id\": \"$(next_id)\", \"params\": [\"$3\"]}" $NODE_URL
while : ; do
if curl -s -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"eth_getTransactionByHash\", \"id\": \"$(next_id)\", \"params\": [\"$2\"]}" $NODE_URL | grep "\"blockNumber\":\"$1\""; then
break
fi
sleep 1
done
}
# try send some transactions
send_transaction 0x1 0xc337816fd40c6a54f77a1445fa1ea6ab5101294974515312052b670650e2aca9 0xf8718310000085028fa6ae0082520894000000000000000000000000000000000000000089056bc75e2d631000008081a8a0e0e959ccf4b4baf9b32dda1c210a321e71af96b5f66269fb2beb38298f89e5e8a0207b860442764f685024479d57c99a2c91fcd5b204eb2c728a98320dc9db04a5
send_transaction 0x2 0x60b9b36033d99d36b52ff94d033f2d99ff1bf15c5c848d8af9b8295c3d19fbd7 0xf8718310000185028fa6ae0082520894000000000000000000000000000000000000000089056bc75e2d631000008081a8a021025e7ddc5ad4744c2dfeffa84fdddaaa64e9f4681657c731e3cc020b3f9592a00f42710314e49d47c66aa63003d6820cdfc59c72c7a8037cbce5024b81ebaa1a
send_transaction 0x3 0xc849b5f7e6b73d531aa4381646cb3b25871efcc5287c879f834a2e036e409938 0xf8718310000285028fa6ae0082520894000000000000000000000000000000000000000089056bc75e2d631000008081a8a06391c32a10f084529e42a2b992f0da95994fcace83e99735765cc758c0d137ffa018683b0cd87c7d231004608e11b81841992b0b5b47e8ea7f31c9e5653d2f0c90
send_transaction 0x4 0x7e1388c57e625c824902dd8a61e06679d74265d7451b4cd1f3f4be0c2ccd5473 0xf8718310000385028fa6ae0082520894000000000000000000000000000000000000000089056bc75e2d631000008081a8a0eb6b075192aadbc0899c57fb86ed0cf11709dd116344ea8dd9990c4e81320d62a072798f2facc4b0cb30e65cd429c6aabfed654d9817e85b52021bfdbeea8a2bd5
send_transaction 0x5 0x3b88fddb61a52e80bc8141354bb9cf1445c6b3fbf3ac2a2421c2af3f61741f21 0xf8718310000485028fa6ae0082520894000000000000000000000000000000000000000089056bc75e2d631000008081a8a08eed90177f77ef1ae1c943522c496f26ed71c0c3e7a54f4bfea9ea1a7eff635ea07d73fa41256f5727694bec32fd2da0046ad804654af26746d61719ff26ccaa5f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment