Skip to content

Instantly share code, notes, and snippets.

@yondonfu
Last active January 22, 2023 19:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yondonfu/ea57cfe9510b6526288d456229a3d61e to your computer and use it in GitHub Desktop.
Save yondonfu/ea57cfe9510b6526288d456229a3d61e to your computer and use it in GitHub Desktop.
Mark expired tickets

This gist contains a script for marking expired tickets in a node's DB so the node does not continuously try to redeem tickets that have expired. This will be fixed in the node in an upcoming release, but for now you can use this script to address this issue.

Usage

First, make sure you have sqlite3 installed. You can check by running which sqlite3 and if there is a path returned you have sqlite3 installed. If you do not have sqlite3 installed:

  • OSX: brew install sqlite3
  • Ubuntu: apt-get install sqlite3
  1. git clone https://gist.github.com/ea57cfe9510b6526288d456229a3d61e.git

  2. Visit https://explorer.livepeer.org/ and note the current round number which can be found in the lower left hand corner of the screen.

  3. cd ea57cfe9510b6526288d456229a3d61e

  4. bash mark_expired_tickets.sh <PATH_TO_DB_FILE> <CURRENT_ROUND>

<PATH_TO_DB_FILE> is the path to the lpdb.sqlite3 file used by your node. By default this will be located in ~/.lpData/mainnet when your node is connected to mainnet.

<CURRENT_ROUND> is the current round number noted in step 2.

Ex.

bash mark_expired_tickets.sh ~/.lpData/mainnet/lpdb.sqlite3 1841

DB_FILE=$1
CURRENT_ROUND=$2
last_valid_creation_round=$(expr $CURRENT_ROUND - 2)
select_query="select creationRound from ticketQueue where creationRound < $last_valid_creation_round and redeemedAt is null;"
num_tickets=$(echo $select_query | sqlite3 $DB_FILE | wc -l | xargs)
echo "$num_tickets tickets are expired"
read -p "Would you like to mark these $num_tickets tickets as unreedemable? [y/n] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "Exiting!"
exit 0
else
echo "Marking $num_tickets tickets as unredeeemable..."
mark_query="update ticketQueue set redeemedAt=datetime() where creationRound < $last_valid_creation_round and redeemedAt is null;"
echo $mark_query | sqlite3 $DB_FILE
# Check that tickets are marked
num_tickets=$(echo $select_query | sqlite3 $DB_FILE | wc -l | xargs)
echo "After marking those tickets, there are $num_tickets expired tickets"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment