Skip to content

Commit

Permalink
Add rollback diff to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Jan 30, 2023
1 parent 68d44fb commit 8038374
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/fullsync-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ jobs:
strategy:
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}

continue-on-error: true
env:
DATADIR : datadir-${{matrix.blocks.start}}
STOP_BLOCK: ${{matrix.blocks.stop}}
Expand Down Expand Up @@ -131,13 +130,23 @@ jobs:
chmod 777 defi-cli
chmod 777 sync_then_diff.sh
- name: Sync and Diff
- name: Sync
run: ./sync_then_diff.sh

- name: Diff log
run: |
echo "diff debug-${{matrix.blocks.stop}}.log debug-tmp-${{matrix.blocks.stop}}.log"
diff debug-${{matrix.blocks.stop}}.log debug-tmp-${{matrix.blocks.stop}}.log
continue-on-error: true

- name: Diff rollback log
run: |
echo "diff debug-pre-rollback.log debug-post-rollback.log"
diff debug-pre-rollback.log debug-post-rollback.log
continue-on-error: true

- name: Show debug.log
run: cat $DATADIR/debug.log
if: ${{ failure() || success() }}

- name: Show log file
run: cat debug-tmp-$STOP_BLOCK.log
if: ${{ failure() || success() }}
51 changes: 40 additions & 11 deletions ci/parallel_sync/sync_then_diff.sh → ci/parallel_sync/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ setup_vars() {
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

# Commands
DEFID_CMD="$DEFID_BIN -datadir=$DATADIR -daemon -debug=accountchange -spv"
DEFID_CMD="$DEFID_BIN -datadir=$DATADIR -daemon -debug=accountchange -spv -checkpoints=0"
DEFI_CLI_CMD="$DEFI_CLI_BIN -datadir=$DATADIR"
FETCH="wget -q"
FETCH="aria2c -x16 -s16"
GREP="grep"

BLOCK=0
ROLLBACK_BLOCK=$START_BLOCK
ATTEMPTS=0
MAX_ATTEMPTS=10
MAX_NODE_RESTARTS=5
Expand Down Expand Up @@ -62,10 +65,8 @@ print_info() {
"
}

create_log_file () {
echo "Output log to $TMP_LOG file"
{
$GREP "AccountChange:" "$DEBUG_FILE" | cut -d" " -f2-
get_full_log () {
{ $GREP "AccountChange:" "$DEBUG_FILE" || test $? = 1; } | cut -d" " -f2-
echo "-- logaccountbalances --"
$DEFI_CLI_CMD logaccountbalances
echo "-- spv_listanchors --"
Expand All @@ -78,7 +79,26 @@ create_log_file () {
$DEFI_CLI_CMD listtokens '{"limit":1000000}'
echo "-- getburninfo --"
$DEFI_CLI_CMD getburninfo
} >> "$TMP_LOG"
}

create_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"

cp -r "$DATADIR" "$DATADIR_ROLLBACK"
rm -f "$DEBUG_FILE"
$DEFID_CMD
sleep 90
echo "ROLLBACK_BLOCK : $ROLLBACK_BLOCK"
ROLLBACK_HASH=$($DEFI_CLI_CMD getblockhash $((ROLLBACK_BLOCK)))
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" >> "$PRE_ROLLBACK_LOG"
$DEFI_CLI_CMD stop
}

# Start defid
Expand All @@ -91,6 +111,7 @@ start_node () {
main() {
setup_vars
print_info
create_rollback_log
start_node

# Sync to target block height
Expand Down Expand Up @@ -122,15 +143,23 @@ main() {
done

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

$DEFI_CLI_CMD stop
# Download reference log file
echo "Downloading reference log file : $REF_LOG_PATH"
$FETCH "$REF_LOG_PATH"

echo "diff $TMP_LOG $REF_LOG"
diff "$TMP_LOG" "$REF_LOG"
# Rollback to starting block and diff against initial rollback file
echo "ROLLBACK_BLOCK $ROLLBACK_BLOCK"
ROLLBACK_HASH=$($DEFI_CLI_CMD getblockhash $((ROLLBACK_BLOCK)))
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" >> "$POST_ROLLBACK_LOG"
echo "diff $PRE_ROLLBACK_LOG $POST_ROLLBACK_LOG"

$DEFI_CLI_CMD stop
}

main "$@"

0 comments on commit 8038374

Please sign in to comment.