-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmillau-to-rialto-messages-generator.sh
executable file
·149 lines (130 loc) · 4.36 KB
/
millau-to-rialto-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
#!/bin/bash
. ./prelude.sh
# THIS SCRIPT IS NOT INTENDED FOR USE IN PRODUCTION ENVIRONMENT
#
# This scripts periodically calls relay binary to generate Millau -> Rialto
# messages.
set -eu
# Path to relay binary
RELAY_BINARY_PATH=./bin/substrate-relay
# Millau node host
MILLAU_HOST=127.0.0.1
# Millau node port
MILLAU_PORT=10946
# Millau signer
MILLAU_SIGNER=//Dave
# Rialto signer
RIALTO_SIGNER=//Dave
# 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 (Rialto)
MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE=128
# submit Millau to Rialto message
submit_message() {
MESSAGE_PARAMS="$*"
$RELAY_BINARY_PATH 2>&1 send-message millau-to-rialto \
--source-host=$MILLAU_HOST\
--source-port=$MILLAU_PORT\
--source-signer=$MILLAU_SIGNER\
--target-signer=$RIALTO_SIGNER\
--lane=$LANE\
--origin Target \
$MESSAGE_PARAMS
}
# submit Millau to Rialto message to lane#1
submit_message_at_lane_1() {
MESSAGE_PARAMS="$*"
$RELAY_BINARY_PATH 2>&1 send-message millau-to-rialto \
--source-host=$MILLAU_HOST\
--source-port=$MILLAU_PORT\
--source-signer=$MILLAU_SIGNER\
--target-signer=$RIALTO_SIGNER\
--lane=00000001\
--origin Target\
--dispatch-fee-payment=at-target-chain\
--dispatch-weight=max\
$MESSAGE_PARAMS
$RELAY_BINARY_PATH 2>&1 send-message millau-to-rialto \
--source-host=$MILLAU_HOST\
--source-port=$MILLAU_PORT\
--source-signer=$MILLAU_SIGNER\
--target-signer=$RIALTO_SIGNER\
--lane=00000001\
--origin Target\
--dispatch-fee-payment=at-source-chain\
--dispatch-weight=max\
$MESSAGE_PARAMS
}
COUNTER=0
BATCH_TIME=0
while true
do
SUBMIT_DELAY_S=`shuf -i 0-$MAX_SUBMIT_DELAY_S -n 1`
# sleep some time
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
echo "Sending message from Millau to Rialto ($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 Millau to Rialto ($((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 Millau to Rialto ($((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 Millau to Rialto ($((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 Millau to Rialto ($((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