forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (147 loc) · 7.85 KB
/
check-state-compatibility.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# This workflow checks that a specific commit / branch / tag is state compatible
# with the latest osmosis version by:
# - building the new `osmosisd` binary with the latest changes
# - replaying a configurable number of previous blocks from chain history
# Currently, the node starts from a snapshot taken some blocks before the last epoch
# and waits `DELTA_HALT_HEIGHT` blocks after epoch before finally halting.
# Important Caveat:
# The fact that this workflow succeeds and the binary doesn't fail doesn't
# directly imply that the new binary is state-compatible.
# It could be that the binary is not state-compatible, but the condition
# which would break state compatibility was not present in the chunk of block history used.
# On the other hand, if the workflow fails, the binary is not state-compatible.
name: Check state compatibility
# ************************************ NOTE ************************************
#
# DO NOT TRIGGER THIS WORKFLOW ON PUBLIC FORKS
#
# This workflow runs on a self-hosted runner and forks to this repository
# can potentially run dangerous code on the self-hosted runner machine
# by creating a pull request that executes the code in a workflow.
#
# ******************************************************************************
on:
pull_request:
branches:
- "v[0-9]+.x"
env:
GOLANG_VERSION: 1.18
GENESIS_URL: https://github.com/osmosis-labs/networks/raw/main/osmosis-1/genesis.json
ADDRBOOK_URL: https://rpc.osmosis.zone/addrbook
SNAPSHOT_BUCKET: https://snapshots.osmosis.zone
RPC_ENDPOINT: https://rpc.osmosis.zone
LCD_ENDPOINT: https://lcd.osmosis.zone
DELTA_HALT_HEIGHT: 50
jobs:
compare_versions:
# Compare current mainnet osmosis major version with the major version of github branch
# Skip the next job if the current github major is greater than the current mainnet major
runs-on: self-hosted
outputs:
should_i_run: ${{ steps.compare_versions.outputs.should_i_run }}
mainnet_major_version: ${{ steps.mainnet_version.outputs.mainnet_major_version }}
steps:
- name: Get mainnet major version
id: mainnet_version
run: |
# Find current major version via rpc.osmosis.zone/abci_info
RPC_ABCI_INFO=$(curl -s --retry 5 --retry-delay 5 --connect-timeout 30 -H "Accept: application/json" ${{ env.RPC_ENDPOINT }}/abci_info)
MAINNET_MAJOR_VERSION=$(echo $RPC_ABCI_INFO | dasel --plain -r json 'result.response.version' | cut -f 1 -d '.')
echo "MAINNET_MAJOR_VERSION=$MAINNET_MAJOR_VERSION" >> $GITHUB_ENV
echo "mainnet_major_version=$MAINNET_MAJOR_VERSION" >> $GITHUB_OUTPUT
- name: Get GitHub branch major version
id: compare_versions
run: |
CURRENT_BRANCH_MAJOR_VERSION=$(echo ${{ github.event.pull_request.base.ref }} | tr -dc '0-9')
SHOULD_I_RUN=$(( $CURRENT_BRANCH_MAJOR_VERSION <= $MAINNET_MAJOR_VERSION ))
echo -n "Mainnet version: $MAINNET_MAJOR_VERSION | Branch version: $CURRENT_BRANCH_MAJOR_VERSION | Should I run: "
if (( $CURRENT_BRANCH_MAJOR_VERSION <= $MAINNET_MAJOR_VERSION ));
then
echo 'should_i_run=true' >> $GITHUB_OUTPUT;
echo "true"
else
echo 'should_i_run=false' >> $GITHUB_OUTPUT;
echo "false"
fi
check_state_compatibility:
# DO NOT CHANGE THIS: please read the note above
if: ${{ github.event.pull_request.head.repo.full_name == 'osmosis-labs/osmosis' && needs.compare_versions.outputs.should_i_run == 'true' }}
needs: compare_versions
runs-on: self-hosted
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: 🐿 Setup Golang
uses: actions/setup-go@v4
with:
go-version: '^1.20'
- name: 🔨 Build the osmosisd binary
run: |
make build
build/osmosisd version
- name: 🧪 Initialize Osmosis Node
run: |
rm -rf $HOME/.osmosisd/ || true
build/osmosisd init runner -o
# Download genesis file if not present
mkdir -p /mnt/data/genesis/osmosis-1/
if [ ! -f "/mnt/data/genesis/osmosis-1/genesis.json" ]; then
wget -q -O /mnt/data/genesis/osmosis-1/genesis.json ${{ env.GENESIS_URL }}
fi
# Copy genesis to config folder
cp /mnt/data/genesis/osmosis-1/genesis.json $HOME/.osmosisd/config/genesis.json
- name: ⏬ Download last pre-epoch snapshot
run: |
REPO_MAJOR_VERSION=v14
SNAPSHOT_INFO_URL=${{ env.SNAPSHOT_BUCKET }}/$REPO_MAJOR_VERSION/snapshots.json
# Get the latest pre-epoch snapshot information from bucket
SNAPSHOT_INFO=$(curl -sL --retry 5 --retry-delay 5 --connect-timeout 30 -H "Accept: application/json" $SNAPSHOT_INFO_URL)
SNAPSHOT_URL=$(echo $SNAPSHOT_INFO | jq -r '.[] | select(.type == "pre-epoch").url')
SNAPSHOT_ID=$(echo $SNAPSHOT_INFO | jq -r '.[] | select(.type == "pre-epoch").filename' | cut -f 1 -d '.')
# Download snapshot if not already present
mkdir -p /mnt/data/snapshots/$REPO_MAJOR_VERSION/
if [ ! -d "/mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID" ]; then
rm -rf /mnt/data/snapshots/$REPO_MAJOR_VERSION/*
mkdir /mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID
wget -q -O - $SNAPSHOT_URL | lz4 -d | tar -C /mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID -xvf -
fi
# Copy snapshot in Data folder
cp -R /mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID/* $HOME/.osmosisd/
- name: 🧪 Configure Osmosis Node
run: |
CONFIG_FOLDER=$HOME/.osmosisd/config
# Find last epoch block comparing repo version to current chain version
REPO_MAJOR_VERSION=14
if [ $REPO_MAJOR_VERSION == $MAINNET_MAJOR_VERSION ]; then
# I'm in the latest major, fetch the epoch info from the lcd endpoint
LAST_EPOCH_BLOCK_HEIGHT=$(curl -s --retry 5 --retry-delay 5 --connect-timeout 30 ${{ env.LCD_ENDPOINT }}/osmosis/epochs/v1beta1/epochs | dasel --plain -r json 'epochs.(identifier=day).current_epoch_start_height')
else
# I'm in a previous major, calculate the epoch height from the snapshot height
# (Snapshot is taken 100 blocks before epoch)
SNAPSHOT_INFO_URL=${{ env.SNAPSHOT_BUCKET }}/v$REPO_MAJOR_VERSION/snapshots.json
SNAPSHOT_INFO=$(curl -sL --retry 5 --retry-delay 5 --connect-timeout 30 -H "Accept: application/json" $SNAPSHOT_INFO_URL)
SNAPSHOT_BLOCK_HEIGHT=$(echo $SNAPSHOT_INFO | jq -r '.[] | select(.type == "pre-epoch").height')
LAST_EPOCH_BLOCK_HEIGHT=$(($SNAPSHOT_BLOCK_HEIGHT + 100))
fi
HALT_HEIGHT=$(($LAST_EPOCH_BLOCK_HEIGHT + ${{ env.DELTA_HALT_HEIGHT }}))
echo "Osmosis repo version: $REPO_MAJOR_VERSION"
echo "Last Epoch Height: $LAST_EPOCH_BLOCK_HEIGHT"
echo "Halt Height: $HALT_HEIGHT"
# Edit config.toml
dasel put string -f $CONFIG_FOLDER/config.toml '.tx_index.indexer' null
dasel put string -f $CONFIG_FOLDER/config.toml '.p2p.persistent_peers' '37c195e518c001099f956202d34af029b04f2c97@p2p.archive.osmosis.zone:26656'
dasel put string -f $CONFIG_FOLDER/config.toml 'seeds' ''
# Edit app.toml
dasel put string -f $CONFIG_FOLDER/app.toml '.halt-height' $HALT_HEIGHT
dasel put string -f $CONFIG_FOLDER/app.toml '.pruning' everything
dasel put string -f $CONFIG_FOLDER/app.toml '.state-sync.snapshot-interval' 0
# Download addrbook
wget -q -O $CONFIG_FOLDER/addrbook.json ${{ env.ADDRBOOK_URL }}
- name: 🧪 Start Osmosis Node
run: build/osmosisd start
- name: 🧹 Clean up Osmosis Home
if: always()
run: rm -rf $HOME/.osmosisd/ || true