-
Notifications
You must be signed in to change notification settings - Fork 0
/
spade-manage-publish-mpool.sh
67 lines (67 loc) · 2.39 KB
/
spade-manage-publish-mpool.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
#!/bin/bash
#------------------------------------------------
# Process CLI arguments
#
#------------------------------------------------
usage()
{
echo "usage: $0 -a fxxxxx.." >&2
}
if [ -z "$1" ]; then
usage
exit 1
fi
while getopts "a:" f
do
case "$f" in
a) echo "Monitoring publish address: ${OPTARG}";publishAddress=${OPTARG} ;;
*) usage
exit 1 ;;
esac
done
#------------------------------------------------
# VARIABLES
# publishAddress set from cli
#------------------------------------------------
basefeeLimit=1000000000
#------------------------------------------------
# functions
#
#------------------------------------------------
replacePublishMsgIfNeeded() {
publishPendingMsgGasFeeCap=$(lotus mpool pending --local | grep "$publishAddress" -A5 | grep GasFeeCap | awk '{print $2'} | awk '{print substr($0, 2, length($0) - 3)}' | head -n1)
publishPendingMsgNonce=$(lotus mpool pending --local | grep "$publishAddress" -A5 | grep Nonce | awk '{print $2'} | awk '{ print substr( $0, 1, length($0)-1 ) }' | head -n1)
basefee=$(lotus chain head | awk 'NR==1{print; exit}' | xargs lotus chain getblock | jq -r .ParentBaseFee)
echo The basefee is: "$basefee"
echo The GasFeeCap is: "$publishPendingMsgGasFeeCap"
if [ -n "$publishPendingMsgGasFeeCap" ] && [ $(("$publishPendingMsgGasFeeCap")) -le $(("$basefee")) ]; then
echo GasFeeCap is too low
if [ "$(("$basefee"))" -le "$basefeeLimit" ]; then
echo "lotus mpool replace --auto --fee-limit 0.${basefee:0:1} $publishAddress $publishPendingMsgNonce"
replaceMsg=$(lotus mpool replace --auto --fee-limit 0."${basefee:0:1}" "$publishAddress" "$publishPendingMsgNonce")
echo sleep 5 mins
sleep 300
fi
sleep 5
fi
}
check_mpool() {
mps=$(lotus mpool pending --local | grep -o "$publishAddress" | wc -l)
#echo checking mpool for msgs, found "$mps"
while [ "$mps" -gt 0 ]; do
echo "Found publish msgs in mpool sleep 5 seconds... "
sleep 5
replacePublishMsgIfNeeded
mps=$(lotus mpool pending --local | grep -o "$publishAddress" | wc -l)
echo checking mpool for msgs, found "$mps"
done
}
#------------------------------------------------
# main
#
#------------------------------------------------
echo Will manage Publish messages when BaseFee is less than $basefeeLimit
while :; do
check_mpool
sleep 60
done