Skip to content

Commit

Permalink
Sonic RPC: target a devnet
Browse files Browse the repository at this point in the history
  • Loading branch information
wsodsong committed Nov 21, 2024
1 parent 1195876 commit d051c30
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 30 deletions.
57 changes: 49 additions & 8 deletions release_testing/operational_tests/P04.jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// P04 performs end-to-end test synchronizing from genesis to the head of the chain, test runs artificial RPC requests adn compare block receipts

pipeline {
agent { node "x86-4-32-archive" }
agent { node "${params.Agent}" }

options {
timestamps ()
Expand All @@ -12,7 +12,8 @@ pipeline {
environment {
GOGC = '50'
GOMEMLIMIT = '28GiB'
SONICSTATEDB = '/mnt/sonic-statedb/mainnet'
SONICSTATEDB = ''
OPTIONS = ''
}

parameters {
Expand All @@ -31,6 +32,17 @@ pipeline {
defaultValue: "http://10.128.0.10",
description: 'URL address of referential Sonic node'
)
string(
//default agent for devnet. For mainnet, use x86-4-32-archive
name: 'Agent',
defaultValue: 'x86-4-32-m',
description: 'Agent label to run the job. For Opera mainnet, use x86-4-32-archive.'
)
choice(
name: 'Network',
choices: ['Sonic devnet', 'Opera mainnet'],
description: 'Network to test'
)
}

stages {
Expand All @@ -54,15 +66,44 @@ pipeline {
}
}

stage('Build') {
stage('Confugure & Build') {
steps {
sh "make"
sh 'make'

script {
// resume from an existing statedb
if ("${Network}" == 'Opera mainnet') {
SONICSTATEDB = '/mnt/sonic-statedb/mainnet'
OPTIONS = '--lachesis.suppress-frame-panic'
// needs genesis and config files
} else if ("${Network}" == 'Sonic devnet') {
// variables
def tmppath = '/mnt/tmp-disk/'
def genesispath = "${tmppath}/genesis.json"
def tomlpath = "${tmppath}/sonic-devnet.toml"

SONICSTATEDB = "${tmppath}/sonic"
OPTIONS = "--config ${tomlpath}"

// download genesis and config files
sh "wget -O ${genesispath} https://storage.googleapis.com/sonic-snapshots/devnet/genesis.json"
sh "wget -O ${tomlpath} https://storage.googleapis.com/sonic-snapshots/devnet/config.toml"

// prepare stateDb from genesis
sh """./build/sonictool --datadir ${SONICSTATEDB} \
genesis json ${genesispath} \
--experimental --mode rpc"""
} else {
error 'Invalid network'
}
}
}
}


stage('Synchronization') {
steps {
sh "./build/sonicd --datadir ${SONICSTATEDB} --cache 16047 --verbosity 2 --exitwhensynced.age 1s --lachesis.suppress-frame-panic"
sh "./build/sonicd --datadir ${SONICSTATEDB} --verbosity 2 --exitwhensynced.age 1s ${OPTIONS}"
}
}

Expand Down Expand Up @@ -93,8 +134,8 @@ pipeline {
--http.port=80 \
--http.corsdomain="*" \
--http.vhosts="*" \
--http.api=eth,web3,net,ftm,txpool,abft,dag
--lachesis.suppress-frame-panic"""
--http.api=eth,web3,net,ftm,txpool,abft,dag \
${OPTIONS}"""
}
}
}
Expand Down Expand Up @@ -138,4 +179,4 @@ pipeline {
]
}
}
}
}
44 changes: 22 additions & 22 deletions utils/test_getBlockReceipts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TESTED_API="$1"
REF_API="$2"
RANGE="$3"
HEAD="$4"

if [ -z "${RANGE}" ]; then
RANGE=1000
fi
Expand All @@ -28,41 +28,41 @@ fi
while [ "${RANGE}" -ge 0 ]; do
BLK=$((${HEAD}-${RANGE}))
BLK16=$(printf '0x%x' ${BLK})

BLK_HEAD=$(curl -s -X POST -H "Content-Type: application/json" --data '{"method":"eth_getBlockByNumber","params":["'${BLK16}'",false],"id":1,"jsonrpc":"2.0"}' ${REF_API})
BLK_HASH=$(echo "${BLK_HEAD}" | jq -r ".result.hash")
ROOT_HASH=$(echo "${BLK_HEAD}" | jq -r ".result.stateRoot")
BLK_TXCOUNT=$(echo "${BLK_HEAD}" | jq -r ".result.transactions | length")

echo "Testing block #${BLK}"

MY_HEAD=$(curl -s -X POST -H "Content-Type: application/json" --data '{"method":"eth_getHeaderByNumber","params":["'${BLK16}'"],"id":1,"jsonrpc":"2.0"}' ${TESTED_API})
MY_HASH=$(echo "${MY_HEAD}" | jq -r ".result.hash")
if [ "${BLK_HASH}" != "${MY_HASH}" ]; then
echo "Error: block hash not matched; ${BLK_HASH} expected; ${MY_HASH} received)"
MY_ROOT=$(echo "${MY_HEAD}" | jq -r ".result.stateRoot")

if [ "${ROOT_HASH}" != "${MY_ROOT}" ]; then
echo "Error: block hash not matched; ${ROOT_HASH} expected; ${MY_ROOT} received)"
exit 1
else
echo " block hash confirmed; ${BLK_HASH}"
echo " block hash confirmed; ${ROOT_HASH}"
fi

BLK_RECEIPTS=$(curl -s -X POST -H "Content-Type: application/json" --data '{"method":"eth_getBlockReceipts","params":["'${BLK16}'"],"id":1,"jsonrpc":"2.0"}' ${TESTED_API})
RCPT_COUNT=$(echo "${BLK_RECEIPTS}" | jq -r ".result | length")

if [ ${BLK_TXCOUNT} -ne ${RCPT_COUNT} ]; then
echo "Error: wrong number of receipts received; ${BLK_TXCOUNT} expected; ${RCPT_COUNT} received)"
exit 1
exit 1
else
echo " transaction count confirmed; ${BLK_TXCOUNT} transaction(s) inside"
fi

INDEX=0
while [ ${INDEX} -lt ${RCPT_COUNT} ]; do
MY_RECEIPT=$(echo ${BLK_RECEIPTS} | jq --sort-keys ".result[${INDEX}]")
TX_HASH=$(echo ${MY_RECEIPT} | jq -r ".transactionHash")

TX_RECEIPT=$(curl -s -X POST -H "Content-Type: application/json" --data '{"method":"eth_getTransactionReceipt","params":["'${TX_HASH}'"],"id":1,"jsonrpc":"2.0"}' ${REF_API})
TX_RECEIPT=$(echo ${TX_RECEIPT} | jq --sort-keys ".result")

TEST=$(jq -r -n --argjson A "$MY_RECEIPT" --argjson B "$TX_RECEIPT" -f <(cat<<"EOF"
def walk(f):
. as $in
Expand All @@ -81,24 +81,24 @@ if $A | equiv($B) then empty else "failed" end
EOF
)
)
)
if [ -z "${TEST}" ]; then
echo " #${INDEX}: ${TX_HASH}; receipt ok"
else
echo "Error: tx receipt check failed for #${INDEX}: ${TX_HASH}"

echo "My Receipt"
echo ${MY_RECEIPT} | jq

echo "Reference Receipt"
echo ${TX_RECEIPT} | jq

exit 1
fi

INDEX=$((${INDEX}+1))
done

RANGE=$((${RANGE}-1))
done

Expand Down

0 comments on commit d051c30

Please sign in to comment.