-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpopulate_config.sh
executable file
·209 lines (174 loc) · 7.07 KB
/
populate_config.sh
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
set -eu
source <(grep -v '^#' "./.env" | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g')
declare -A NODES=(
["flare"]="https://flare-api.flare.network/ext/C/rpc"
["songbird"]="https://songbird-api.flare.network/ext/C/rpc"
["coston"]="https://coston-api.flare.network/ext/C/rpc"
["coston2"]="https://coston2-api.flare.network/ext/C/rpc"
)
ROOT_DIR="$(pwd)"
CONFIG_DIR="${ROOT_DIR}/config/${NETWORK}"
CHAIN_CONFIG="${CONFIG_DIR}/config.json"
DEPLOYED_CONTRACTS="${CONFIG_DIR}/contracts.json"
INITIAL_REWARD_EPOCH="${CONFIG_DIR}/initial_reward_epoch.txt"
CHAIN_ID_FILE="${CONFIG_DIR}/chain_id.txt"
get_address_by_name() {
name="$1"
echo $(jq -r ".[] | select(.name == \"$name\") | .address" "$DEPLOYED_CONTRACTS")
}
write_attestation_source() {
attestation_type=$1; shift
source=$1; shift
lut_limit=$1; shift
url_env_name="${source^^}_${attestation_type^^}_URL"
api_key_env_name="${source^^}_${attestation_type^^}_API_KEY"
if [[ ${!url_env_name:+x} != "x" ]]; then
echo "warning: $attestation_type for $source source config wasn't generated: $url_env_name env variable is not set" >&2
return
fi
url="${!url_env_name}"
api_key="${!api_key_env_name:-""}"
cat <<EOF
## $source
[types.$attestation_type.Sources.$source]
url = "$url"
api_key = "$api_key"
lut_limit = "$lut_limit"
queue = "$source"
EOF
}
write_attestation_type() {
name=$1;
cat <<EOF
# $name
[types.$name]
abi_path = "configs/abis/$name.json"
EOF
}
write_attestation_queue() {
name=$1; shift
cat <<EOF
[queues.$name]
size = 1000
max_dequeues_per_second = 100
max_workers = 10
max_attempts = 3
time_off = "2s"
EOF
}
write_fdc_attestation_types() {
config_file=$1; shift
(
# queues
write_attestation_queue "SGB"
write_attestation_queue "FLR"
write_attestation_queue "ETH"
write_attestation_queue "BTC"
write_attestation_queue "DOGE"
write_attestation_queue "XRP"
# evm transaction
write_attestation_type "EVMTransaction"
write_attestation_source "EVMTransaction" "SGB" 18446744073709551615
write_attestation_source "EVMTransaction" "FLR" 18446744073709551615
write_attestation_source "EVMTransaction" "ETH" 18446744073709551615
# payment
write_attestation_type "Payment"
write_attestation_source "Payment" "BTC" 1209600
write_attestation_source "Payment" "DOGE" 1209600
write_attestation_source "Payment" "XRP" 1209600
# balance decreasing transaction
write_attestation_type "BalanceDecreasingTransaction"
write_attestation_source "BalanceDecreasingTransaction" "BTC" 1209600
write_attestation_source "BalanceDecreasingTransaction" "DOGE" 1209600
write_attestation_source "BalanceDecreasingTransaction" "XRP" 1209600
# confirmed block height exists
write_attestation_type "ConfirmedBlockHeightExists"
write_attestation_source "ConfirmedBlockHeightExists" "BTC" 1209600
write_attestation_source "ConfirmedBlockHeightExists" "DOGE" 1209600
write_attestation_source "ConfirmedBlockHeightExists" "XRP" 1209600
# referenced payment nonexistence
write_attestation_type "ReferencedPaymentNonexistence"
write_attestation_source "ReferencedPaymentNonexistence" "BTC" 1209600
write_attestation_source "ReferencedPaymentNonexistence" "DOGE" 1209600
write_attestation_source "ReferencedPaymentNonexistence" "XRP" 1209600
# address validity
write_attestation_type "AddressValidity"
write_attestation_source "AddressValidity" "BTC" 18446744073709551615
write_attestation_source "AddressValidity" "DOGE" 18446744073709551615
write_attestation_source "AddressValidity" "XRP" 18446744073709551615
) >>$config_file
}
main() {
if [ -d "mounts" ] || [ -f "mounts" ]; then
echo "cleaning configs from previous runs:"
echo "rm -r mounts"
rm -r "mounts"
fi
echo ""
mount_dirs=(
"mounts/system-client/"
"mounts/c-chain-indexer/"
"mounts/ftso-client/"
"mounts/fdc-client/"
"mounts/fast-updates/"
)
echo "preparing mount dirs:"
for dest in "${mount_dirs[@]}"; do
echo "mkdir -p $dest"
mkdir -p "$dest"
done
echo ""
echo "writing configs for c-chain-indexer, system-client, ftso-client, fdc-client and fast-updates"
# read contract adresses
export SUBMISSION=$(get_address_by_name "Submission")
export RELAY=$(get_address_by_name "Relay")
export FLARE_SYSTEMS_MANAGER=$(get_address_by_name "FlareSystemsManager")
export VOTER_REGISTRY=$(get_address_by_name "VoterRegistry")
export VOTER_PRE_REGISTRY=$(get_address_by_name "VoterPreRegistry")
export FLARE_SYSTEMS_CALCULATOR=$(get_address_by_name "FlareSystemsCalculator")
export FTSO_REWARD_OFFERS_MANAGER=$(get_address_by_name "FtsoRewardOffersManager")
export REWARD_MANAGER=$(get_address_by_name "RewardManager")
export FAST_UPDATER=$(get_address_by_name "FastUpdater")
export FAST_UPDATES_CONFIGURATION=$(get_address_by_name "FastUpdatesConfiguration")
export FAST_UPDATE_INCENTIVE_MANAGER=$(get_address_by_name "FastUpdateIncentiveManager")
export FDC_HUB=$(get_address_by_name "FdcHub")
# read config parameters
export FIRST_VOTING_EPOCH_START_SEC=$(jq -r .firstVotingRoundStartTs "$CHAIN_CONFIG")
export VOTING_EPOCH_DURATION_SEC=$(jq -r .votingEpochDurationSeconds "$CHAIN_CONFIG")
export FIRST_REWARD_EPOCH_START_VOTING_ID=$(jq -r .firstRewardEpochStartVotingRoundId "$CHAIN_CONFIG")
export REWARD_EPOCH_DURATION_IN_VOTING_EPOCHS=$(jq -r .rewardEpochDurationInVotingEpochs "$CHAIN_CONFIG")
export INITIAL_REWARD_EPOCH_ID=$(cat "$INITIAL_REWARD_EPOCH")
# chain id
export CHAIN_ID=$(cat "$CHAIN_ID_FILE")
# block height
block_hex=$(curl -s "${NODES["$NETWORK"]}" \
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' \
| jq -r '.result')
export INDEXER_START_BLOCK=$((16#${block_hex/0x/} - 1000000))
# write configs
# c chain indexer
mkdir -p "mounts/c-chain-indexer/"
CONFIG_FILE="mounts/c-chain-indexer/config.toml"
envsubst < "template-configs/c-chain-indexer.template.toml" > "$CONFIG_FILE"
# system client
mkdir -p "mounts/system-client"
CONFIG_FILE="mounts/system-client/config.toml"
envsubst < "template-configs/system-client.template.toml" > "$CONFIG_FILE"
# ftso client
mkdir -p "mounts/ftso-client"
CONFIG_FILE="mounts/ftso-client/.env"
envsubst < "template-configs/ftso-client.template.env" > "$CONFIG_FILE"
# fdc client
mkdir -p "mounts/fdc-client"
CONFIG_FILE="mounts/fdc-client/config.toml"
envsubst < "template-configs/fdc-client.template.toml" > "$CONFIG_FILE"
write_fdc_attestation_types $CONFIG_FILE
# fast updates
mkdir -p "mounts/fast-updates"
CONFIG_FILE="mounts/fast-updates/config.toml"
envsubst < "template-configs/fast-updates.template.toml" > "$CONFIG_FILE"
}
main