Skip to content

Commit

Permalink
Merge branch 'master' into evm/fix-base-fee
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamc1 authored Jun 21, 2023
2 parents a6d3611 + 6d30278 commit 19c73ac
Show file tree
Hide file tree
Showing 25 changed files with 322 additions and 118 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/tests-ethlibs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ jobs:
path: |
build/src/defid
build/src/defi-cli
ci/ethlibs_test/main.sh
- name: Upload shell commands
uses: actions/upload-artifact@v3
with:
name: sync
path: ci/ethlibs_test/main.sh

node-rpc-tests:
runs-on: ubuntu-latest
Expand All @@ -52,11 +57,16 @@ jobs:
with:
name: defibins

- name: Download shell commands
uses: actions/download-artifact@v3
with:
name: sync

- name: Setup permissions
run: chmod uog+x build/src/defid build/src/defi-cli build/src/defid build/src/defi-cli ci/ethlibs_test/main.sh
run: chmod uog+x ./defid ./defi-cli ./main.sh

- name: Setup test fixtures
run: ./ci/ethlibs_test/main.sh
run: ./main.sh

- name: Setup Go
uses: actions/setup-go@v3
Expand Down
16 changes: 8 additions & 8 deletions ci/ethlibs_test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ set -Eeuo pipefail
setup_vars() {
# directories and binaries
WORK_DIR=${WORK_DIR:-"$(pwd)"}
BUILD_DIR=${BUILD_DIR:-"${WORK_DIR}/build/src"}
DEFID_BIN=${DEFID_BIN:-"${BUILD_DIR}/defid"}
DEFI_CLI_BIN=${DEFI_CLI_BIN:-"${BUILD_DIR}/defi-cli"}
DEFID_BIN=${DEFID_BIN:-"${WORK_DIR}/defid"}
DEFI_CLI_BIN=${DEFI_CLI_BIN:-"${WORK_DIR}/defi-cli"}

# fixture
OWNERAUTHADDR="mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU"
Expand Down Expand Up @@ -68,16 +67,16 @@ setup_fixtures() {
# push fixtures
$DEFI_CLI_BIN -regtest importprivkey "$PRIVKEY_ALICE"
$DEFI_CLI_BIN -regtest importprivkey "$PRIVKEY_BOB"
$DEFI_CLI_BIN -regtest generatetoaddress 100 "$OWNERAUTHADDR"
$DEFI_CLI_BIN -regtest generatetoaddress 120 "$OWNERAUTHADDR"

$DEFI_CLI_BIN -regtest utxostoaccount '{"'"$OWNERAUTHADDR"'":"5000@DFI"}'
$DEFI_CLI_BIN -regtest utxostoaccount '{"'"$OWNERAUTHADDR"'":"500@DFI"}'
$DEFI_CLI_BIN -regtest generatetoaddress 1 "$OWNERAUTHADDR"

$DEFI_CLI_BIN -regtest setgov '{"ATTRIBUTES":{"v0/params/feature/evm":"true"}}'
$DEFI_CLI_BIN -regtest generatetoaddress 1 "$OWNERAUTHADDR"
$DEFI_CLI_BIN -regtest transferdomain '[{"src":{"address":"'"$OWNERAUTHADDR"'", "amount":"2000@DFI", "domain":2}, "dst":{"address":"'"$ALICE"'", "amount":"2000@DFI", "domain":3}}]'
$DEFI_CLI_BIN -regtest transferdomain '[{"src":{"address":"'"$OWNERAUTHADDR"'", "amount":"200@DFI", "domain":2}, "dst":{"address":"'"$ALICE"'", "amount":"200@DFI", "domain":3}}]'
$DEFI_CLI_BIN -regtest generatetoaddress 1 "$OWNERAUTHADDR"

curl http://localhost:19551 \
-H 'content-type:application/json' \
--data-binary \
Expand All @@ -86,6 +85,7 @@ setup_fixtures() {
"id":"fixture",
"method":"eth_sendTransaction",
"params":[{
"from":"'"$ALICE"'",
"data":"'"$CONTRACT_COUNTER"'",
"value":"0x00",
"gas":"0x7a120",
Expand All @@ -105,6 +105,7 @@ setup_fixtures() {
"id":"fixture",
"method":"eth_sendTransaction",
"params":[{
"from":"'"$ALICE"'",
"data":"'"$CONTRACT_COUNTERCALLER"'",
"value":"0x00",
"gas":"0x7a120",
Expand All @@ -119,7 +120,6 @@ setup_fixtures() {

main() {
setup_vars
print_info
start_node
init_node
setup_fixtures
Expand Down
115 changes: 66 additions & 49 deletions ci/sync/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@ setup_vars() {

# Files and directories
DATADIR=${DATADIR:-".defi"}
DEBUG_FILE="$DATADIR/debug.log"
CONF_FILE="$DATADIR/defi.conf"
TMP_LOG=debug-tmp-$STOP_BLOCK.log
DEBUG_FILE="${DATADIR}/debug.log"
CONF_FILE="${DATADIR}/defi.conf"
TMP_LOG="debug-tmp-${STOP_BLOCK}.log"
PRE_ROLLBACK_LOG="debug-pre-rollback.log"
POST_ROLLBACK_LOG="debug-post-rollback.log"
BASE_REF=${BASE_REF:-"master"}
BASE_PATH=https://storage.googleapis.com
BUCKET=team-drop
REF_LOG=debug-$STOP_BLOCK.log
REF_LOG_PATH=$BASE_PATH/$BUCKET/$REF_LOG_DIR/$REF_LOG
BASE_PATH="https://storage.googleapis.com"
BUCKET="team-drop"
REF_LOG="debug-${STOP_BLOCK}.log"
REF_LOG_PATH="${BASE_PATH}/${BUCKET}/${REF_LOG_DIR}/${REF_LOG}"

# Commands
DEFID_CMD="$DEFID_BIN -datadir=$DATADIR -daemon -debug=accountchange -spv -checkpoints=0"
DEFI_CLI_CMD="$DEFI_CLI_BIN -datadir=$DATADIR"
DEFID_CMD="${DEFID_BIN} -datadir=${DATADIR} -daemon -debug=accountchange -spv -checkpoints=0 -interrupt-block=$((STOP_BLOCK + 1))"
DEFI_CLI_CMD="${DEFI_CLI_BIN} -datadir=${DATADIR}"
FETCH="aria2c -x16 -s16"
GREP="grep"

ROLLBACK_BLOCK="${START_BLOCK}"
BLOCK=0
ROLLBACK_BLOCK=$START_BLOCK
ATTEMPTS=0
MAX_ATTEMPTS=10
MAX_NODE_RESTARTS=5
NODE_RESTARTS=0
PID=""
}

_ensure_script_dir() {
Expand All @@ -48,28 +49,28 @@ _cleanup() {

print_info() {
echo "======== Sync Test Info ==========
- Block range: $START_BLOCK - $STOP_BLOCK
- Block range: ${START_BLOCK} - ${STOP_BLOCK}
- Reference log:
$REF_LOG_PATH
${REF_LOG_PATH}
- snapshot:
https://storage.googleapis.com/team-drop/$BASE_REF-datadir/datadir-$START_BLOCK.tar.gz
https://storage.googleapis.com/team-drop/${BASE_REF}-datadir/datadir-${START_BLOCK}.tar.gz
- defid:
$DEFID_CMD
${DEFID_CMD}
- defi-cli:
$DEFI_CLI_CMD
${DEFI_CLI_CMD}
- Create log commands:
$GREP \"AccountChange:\" \"$DEBUG_FILE\" | cut -d\" \" -f2-
$DEFI_CLI_CMD logaccountbalances
$DEFI_CLI_CMD spv_listanchors
$DEFI_CLI_CMD logstoredinterests
$DEFI_CLI_CMD listvaults '{\"verbose\": true}' '{\"limit\":1000000}'
$DEFI_CLI_CMD listtokens '{\"limit\":1000000}'
$DEFI_CLI_CMD getburninfo
${GREP} \"AccountChange:\" \"${DEBUG_FILE}\" | cut -d\" \" -f2-
${DEFI_CLI_CMD} logaccountbalances
${DEFI_CLI_CMD} spv_listanchors
${DEFI_CLI_CMD} logstoredinterests
${DEFI_CLI_CMD} listvaults '{\"verbose\": true}' '{\"limit\":1000000}'
${DEFI_CLI_CMD} listtokens '{\"limit\":1000000}'
${DEFI_CLI_CMD} getburninfo
- defi.conf:
$(cat "$CONF_FILE")
Expand All @@ -93,36 +94,54 @@ get_full_log() {
}

rollback_and_log() {
echo "ROLLBACK_BLOCK : $ROLLBACK_BLOCK"
echo "ROLLBACK_BLOCK : ${ROLLBACK_BLOCK}"
ROLLBACK_HASH=$($DEFI_CLI_CMD getblockhash $((ROLLBACK_BLOCK)))
echo "ROLLBACK_HASH : $ROLLBACK_HASH"
echo "ROLLBACK_HASH : ${ROLLBACK_HASH}"
$DEFI_CLI_CMD invalidateblock "$ROLLBACK_HASH"
echo "Rolled back to block : $($DEFI_CLI_CMD getblockcount)"

get_full_log | grep -v "AccountChange"
}

create_pre_sync_rollback_log() {
local DATADIR_ROLLBACK="$DATADIR-rollback"
local DEFID_CMD="$DEFID_BIN -datadir=$DATADIR_ROLLBACK -daemon -debug=accountchange -spv -rpcport=9999 -port=9998 -connect=0 -checkpoints=0 -interrupt-block=$((START_BLOCK + 1))"
local DEFI_CLI_CMD="$DEFI_CLI_BIN -datadir=$DATADIR_ROLLBACK -rpcport=9999"
local DEBUG_FILE="$DATADIR_ROLLBACK/debug.log"
local DATADIR_ROLLBACK="${DATADIR}-rollback"
local DEFID_CMD="${DEFID_BIN} -datadir=${DATADIR_ROLLBACK} -daemon -debug=accountchange -spv -rpcport=9999 -port=9998 -connect=0 -checkpoints=0 -interrupt-block=$((START_BLOCK + 1))"
local DEFI_CLI_CMD="${DEFI_CLI_BIN} -datadir=${DATADIR_ROLLBACK} -rpcport=9999"
local DEBUG_FILE="${DATADIR_ROLLBACK}/debug.log"

cp -r "$DATADIR" "$DATADIR_ROLLBACK"
rm -f "$DEBUG_FILE"
start_node_and_wait "$DATADIR_ROLLBACK"
rollback_and_log > "$PRE_ROLLBACK_LOG"
stop_node
}

start_node_and_wait() {
local data_dir=${1:-${DATADIR}}
echo "Syncing to block height: ${STOP_BLOCK}"
$DEFID_CMD
sleep 90

rollback_and_log >"$PRE_ROLLBACK_LOG"

$DEFI_CLI_CMD stop
# get PID
PID=$(head -1 "./${data_dir}/defid.pid")
}

# Start defid
start_node() {
echo "Syncing to block height: $STOP_BLOCK"
$DEFID_CMD -interrupt-block=$((STOP_BLOCK + 1))
sleep 30
stop_node() {
local ATTEMPTS=0

# check to ensure defid process stops (50s timeout threshold)
if [ -n "$PID" ]; then
$DEFI_CLI_CMD stop
while ps -p "$PID" > /dev/null; do
if [ "$ATTEMPTS" -gt "$MAX_ATTEMPTS" ]; then
echo "Failed to stop node, exiting"
exit 1
else
ATTEMPTS=$((ATTEMPTS + 1))
sleep 5
fi
done
fi
}

main() {
Expand All @@ -133,23 +152,22 @@ main() {
setup_vars
print_info
create_pre_sync_rollback_log
start_node
start_node_and_wait

# Sync to target block height
while [ "$BLOCK" -lt "$STOP_BLOCK" ]; do
if [ "$ATTEMPTS" -gt "$MAX_ATTEMPTS" ]; then
if [ "$NODE_RESTARTS" -lt "$MAX_NODE_RESTARTS" ]; then
echo "Node Stuck After $ATTEMPTS attempts, restarting node"
$DEFI_CLI_CMD stop
sleep 20
start_node
echo "Node Stuck After ${ATTEMPTS} attempts, restarting node"
stop_node
start_node_and_wait
NODE_RESTARTS=$((NODE_RESTARTS + 1))
ATTEMPTS=0
else
exit 1
fi
fi
CUR_BLOCK=$($DEFI_CLI_CMD getblockcount || echo $BLOCK)
CUR_BLOCK=$($DEFI_CLI_CMD getblockcount || echo "$BLOCK")
if [ "$CUR_BLOCK" -eq "$BLOCK" ]; then
ATTEMPTS=$((ATTEMPTS + 1))

Expand All @@ -158,22 +176,21 @@ main() {
else
ATTEMPTS=0
fi
BLOCK=${CUR_BLOCK:-$BLOCK}
echo "Current block: $BLOCK"
BLOCK=${CUR_BLOCK:-${BLOCK}}
echo "Current block: ${BLOCK}"
sleep 20
done

# Create temporary log file
get_full_log >>"$TMP_LOG"
get_full_log >> "$TMP_LOG"

# Download reference log file
echo "Downloading reference log file : $REF_LOG_PATH"
echo "Downloading reference log file : ${REF_LOG_PATH}"
$FETCH "$REF_LOG_PATH"

# Create rollback log after sync
rollback_and_log >"$POST_ROLLBACK_LOG"

$DEFI_CLI_CMD stop
rollback_and_log > "$POST_ROLLBACK_LOG"
stop_node
}

main "$@"
2 changes: 1 addition & 1 deletion lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/ain-evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ethbloom = "0.13.0"
ethereum-types = "0.14.1"
serde_json = "1.0.96"
statrs = "0.16.0"
rustc-hex = "2.1.0"

# Trie dependencies
hash-db = "0.16.0"
Expand Down
18 changes: 18 additions & 0 deletions lib/ain-evm/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"coinbase": "0x3333333333333333333333333333333333333333",
"difficulty": "0x400000",
"extraData": "0x686f727365",
"gasLimit": "0x1388",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x123123123123123f",
"timestamp": "0x539",
"alloc": {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x09184e72a000"
}
},
"config": {
"ethash": {}
}
}
Loading

0 comments on commit 19c73ac

Please sign in to comment.