This script issues akash tx market lease withdraw
only against leases which ran out of balance.
The deployment gets automatically closed when it runs out of balance in escrow account. But the balance settlement occurs only after a lease withdraw transaction.
Without timely withdrawal from the escrow accounts freeloaders can deploy an expensive deployment which will ran out of 5 AKT deposit by far and still be up & running until provider withdraws the lease.
The default --withdrawal-period
is set to 24h which is too much for large providers and, at the same time,
setting this parameter to a low value would cause a lease withdrawal TX for every deployment causing unnecessary fee spending.
It takes the active leases (akash query market lease list
) per provider you set,
then it checks balance remaining per every deployment.
After that it withdraws from the escrow account (akash tx market lease withdraw
) only those dseq's which ran out of balance.
It should run on a provider side or wherever it's got provider's key (for issuing akash tx market lease withdraw
)
and the access to Akash RPC node for broadcasting that TX.
I suggest to wrap it into a shell script and add it to crontab to run every 1 minute.
# revision 6
# Note: [as per Adam] this script assumes that there is only one lease per deployment.
export AKASH_OUTPUT=json
export AKASH_NODE=http://....
PROVIDER=akash1vky0uh4wayh9npd74uqesglpaxwymynnspf6a4
HEIGHT=$(akash query block | jq -r '.block.header.height')
akash query market lease list \
--provider $PROVIDER \
--gseq 0 --oseq 0 \
--state active --page 1 --limit 5000 \
| jq -r '.leases[].lease | [(.lease_id | .owner, (.dseq|tonumber), (.gseq|tonumber), (.oseq|tonumber), .provider)] | @tsv | gsub("\\t";",")' \
| while IFS=, read owner dseq gseq oseq provider; do \
REMAINING=$(akash query escrow blocks-remaining --dseq $dseq --owner $owner | jq -r '.balance_remaining')
## FOR DEBUGGING/INFORMATIONAL PURPOSES
echo "INFO: $owner/$dseq/$gseq/$oseq balance remaining $REMAINING"
if (( $(echo "$REMAINING < 0" | bc -l) )); then
## UNCOMMENT WHEN READY
## echo "( sleep 2s; cat key-pass.txt; cat key-pass.txt ) | akash tx market lease withdraw --provider $provider --owner $owner --dseq $dseq --oseq $oseq --gseq $gseq --gas-prices=0.025uakt --gas=auto --gas-adjustment=1.3 -y;
## sleep 10
## TODO: sleep 10 is necessary as a safeguard against account sequence re-use.
## BUG: this script needs NOT to run at the same time provider withdraws the lease.
## FOR DEBUGGING PURPOSES, COMMENT WHEN READY
echo "INFO: akash tx market lease withdraw --provider $provider --owner $owner --dseq $dseq --oseq $oseq --gseq $gseq --gas-prices=0.025uakt --gas=auto --gas-adjustment=1.3 -y";
fi
done
Similar workaround https://github.com/ovrclk/akash/issues/1635#issuecomment-1168944395