-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrialto-to-millau-messages-generator.sh
executable file
·157 lines (138 loc) · 4.55 KB
/
rialto-to-millau-messages-generator.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
#!/bin/bash
. ./prelude.sh
# THIS SCRIPT IS NOT INTENDED FOR USE IN PRODUCTION ENVIRONMENT
#
# This scripts periodically calls relay binary to generate Rialto -> Millau
# messages.
set -eu
# Path to relay binary
RELAY_BINARY_PATH=./bin/substrate-relay
# Rialto node host
RIALTO_HOST=127.0.0.1
# Rialto node port
RIALTO_PORT=9946
# Rialto signer
RIALTO_SIGNER=//Dave
# Millau node host
MILLAU_HOST=127.0.0.1
# Millau node port
MILLAU_PORT=10944
# Millau signer
MILLAU_SIGNER=//Alice
# Max delay before submitting transactions (s)
MAX_SUBMIT_DELAY_S=60
# Lane to send message over
LANE=00000000
# Maximal number of unconfirmed messages at the target chain (Millau)
MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE=1024
# submit Rialto to Millau message
submit_message() {
MESSAGE_PARAMS="$*"
$RELAY_BINARY_PATH 2>&1 send-message rialto-to-millau \
--source-host=$RIALTO_HOST\
--source-port=$RIALTO_PORT\
--source-signer=$RIALTO_SIGNER\
--target-signer=$MILLAU_SIGNER\
--lane=$LANE\
--origin Target \
$MESSAGE_PARAMS
}
# submit Rialto to Millau message at lane#1
submit_message_at_lane_1() {
MESSAGE_PARAMS="$*"
$RELAY_BINARY_PATH 2>&1 send-message rialto-to-millau \
--source-host=$RIALTO_HOST\
--source-port=$RIALTO_PORT\
--source-signer=$RIALTO_SIGNER\
--target-host=$MILLAU_HOST\
--target-port=$MILLAU_PORT\
--target-version-mode=Auto\
--target-signer=$MILLAU_SIGNER\
--lane=00000001\
--origin Target\
--dispatch-fee-payment=at-target-chain\
--dispatch-weight=max\
$MESSAGE_PARAMS
$RELAY_BINARY_PATH 2>&1 send-message rialto-to-millau \
--source-host=$RIALTO_HOST\
--source-port=$RIALTO_PORT\
--source-signer=$RIALTO_SIGNER\
--target-signer=$MILLAU_SIGNER\
--lane=00000001\
--origin Target\
--dispatch-fee-payment=at-source-chain\
--dispatch-weight=max\
$MESSAGE_PARAMS
}
COUNTER=0
BATCH_TIME=0
while true
do
# sleep some time
SUBMIT_DELAY_S=`shuf -i 0-$MAX_SUBMIT_DELAY_S -n 1`
echo "Sleeping $SUBMIT_DELAY_S seconds..."
sleep $SUBMIT_DELAY_S
date "+%Y-%m-%d %H:%M:%S"
# prepare message to send
MESSAGE="remark --remark-payload=01234567"
# submit message
COUNTER=$(( COUNTER + 1 ))
echo "Sending message from Rialto to Millau ($COUNTER)"
submit_message --conversion-rate-override metric $MESSAGE
submit_message_at_lane_1 --conversion-rate-override metric $MESSAGE
if [ ! -z "$GENERATE_LARGE_MESSAGES" ]; then
# submit messages with maximal size. chance ~10%
if [ `shuf -i 0-100 -n 1` -lt 10 ]; then
MESSAGES_COUNT=`shuf -i 1-6 -n 1`
echo "Sending $MESSAGES_COUNT maximal size messages from Rialto to Millau ($((COUNTER + 1)))"
for i in $(seq 1 $MESSAGES_COUNT);
do
COUNTER=$(( COUNTER + 1 ))
submit_message --conversion-rate-override metric remark --remark-size=max
done
fi
# submit messages with maximal dispatch weight. chance ~10%
if [ `shuf -i 0-100 -n 1` -lt 10 ]; then
MESSAGES_COUNT=`shuf -i 1-6 -n 1`
echo "Sending $MESSAGES_COUNT maximal dispatch weight messages from Rialto to Millau ($((COUNTER + 1)))"
for i in $(seq 1 $MESSAGES_COUNT);
do
COUNTER=$(( COUNTER + 1 ))
submit_message --dispatch-weight=max --conversion-rate-override metric remark
done
fi
# submit messages with both maximal size and dispatch weight. chance ~10%
if [ `shuf -i 0-100 -n 1` -lt 10 ]; then
MESSAGES_COUNT=`shuf -i 1-3 -n 1`
echo "Sending $MESSAGES_COUNT maximal size + dispatch weight messages from Rialto to Millau ($((COUNTER + 1)))"
for i in $(seq 1 $MESSAGES_COUNT);
do
COUNTER=$(( COUNTER + 1 ))
submit_message --dispatch-weight=max --conversion-rate-override metric remark --remark-size=max
done
fi
# submit a lot of regular messages. chance ~10%, but at most once per 30m
if [ $SECONDS -ge $BATCH_TIME ]; then
if [ `shuf -i 0-100 -n 1` -lt 10 ]; then
BATCH_TIME=$((SECONDS + 1800))
echo "Sending $MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE simple messages from Rialto to Millau ($((COUNTER + 1)))"
COUNTER=$(( COUNTER + 1 ))
SEND_MESSAGE_OUTPUT=$(submit_message --conversion-rate-override metric remark)
echo $SEND_MESSAGE_OUTPUT
ACTUAL_CONVERSION_RATE_REGEX="conversion rate override: ([0-9\.]+)"
if [[ $SEND_MESSAGE_OUTPUT =~ $ACTUAL_CONVERSION_RATE_REGEX ]]; then
ACTUAL_CONVERSION_RATE=${BASH_REMATCH[1]}
else
echo "Unable to find conversion rate in send-message output"
exit 1
fi
for i in $(seq 2 $MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE);
do
COUNTER=$(( COUNTER + 1 ))
echo " Sending message #$COUNTER"
submit_message --conversion-rate-override $ACTUAL_CONVERSION_RATE remark
done
fi
fi
fi
done