Skip to content

Instantly share code, notes, and snippets.

@garethtdavies
Created Jun 28, 2021
Embed
What would you like to do?
Evaluate VRF output
# Generate the input for the epoch
for i in {49980..57120}; do echo "{\"globalSlot\": \"$i\",\"epochSeed\": \"2vb6kwsBmK8ZqJmoLeTXpofEMkXirHmtD6ixTEaiBzzqKmqyNQBD\",\"delegatorIndex\": 1276}"; done > input.txt
# Generate the batch witnesses
cat input.txt | mina advanced vrf batch-generate-witness --privkey-path ~/path-to-my-wallet > batch-generated.txt
# Add in the threshold for VRF evaluation
sed -i 's/]/],"vrfThreshold":{"delegatedStake":"1704440.324956633","totalStake":"829489852.840039300"}/g' batch-generated.txt
# Optional: Remove the using password lines if using env vars
sed -i -e 1,3d batch-generated.txt
# Generate the batch-check-witnesses
cat batch-generated.txt | mina advanced vrf batch-check-witness > batch-check.txt
# How many slots did we win
cat batch-check.txt | grep true | wc -l
# Which slots did we win
cat batch-check.txt | grep -B19 true | awk -F '\n' 'ln ~ /^$/ { ln = "matched"; print $1 } $1 ~ /^--$/ { ln = "" }'
@garethtdavies

This comment has been minimized.

Copy link
Owner Author

@garethtdavies garethtdavies commented Jun 28, 2021

The following inputs are required:

globalSlot - there are 7140 slots in an epoch
epochSeed - get from GraphQL (see query below)
totalStake - get from GraphQL
account index - get from the daemon GraphQL
delegatedStake - can get this from a staking ledger

This query will return the index for an account:

query accountIndex {
  account(publicKey: "B62qmsYXFNNE565yv7bEMPsPnpRCsMErf7J2v5jMnuKQ1jgwZS8BzXS") {
    index
  }
}

This query will return the epoch seed and total stake for the provided epoch and next epoch from https://graphql.minaexplorer.com/:

query epochData {
  blocks(query: {canonical: true, protocolState: {consensusState: {epoch: 6}}}, limit: 1, sortBy: BLOCKHEIGHT_DESC) {
    protocolState {
      consensusState {
        stakingEpochData {
          seed
          ledger {
            totalCurrency
            hash
          }
        }
        nextEpochData {
          seed
          ledger {
            totalCurrency
            hash
          }
        }
      }
    }
  }
}

This query will return the delegated stake from https://graphql.minaexplorer.com/ given a ledger hash (from above):

query epochStakingBalance {
  stake(query: {public_key: "B62qmsYXFNNE565yv7bEMPsPnpRCsMErf7J2v5jMnuKQ1jgwZS8BzXS", ledgerHash: "jwJXdYzAikMHnTsw2kYyS1WQxJrGQsy1FKT5c18eHP2wGANafKf"}) {
    balance
  }
}

If you need the next epoch ledger use nextstake rather than stake

query epochStakingBalance {
  nextstake(query: {public_key: "B62qmsYXFNNE565yv7bEMPsPnpRCsMErf7J2v5jMnuKQ1jgwZS8BzXS", ledgerHash: "jxQgtuyHp8nA2P6F9CSRrLcVeHi8Ap7wVHeNnH2UbSX15izcSHK"}) {
    balance
  }
}
@garethtdavies

This comment has been minimized.

Copy link
Owner Author

@garethtdavies garethtdavies commented Jun 29, 2021

Make a local GraphQL request to Mina daemon:

curl -d '{"query": "{
  account(publicKey: \"B62qpDpnXsUFR4TmaUYaBqcCUV1L1wsdsCcb7iRrvzJcU3ehiiUyoJd\") {
    index
  }
}"}' -H 'Content-Type: application/json' http://localhost:3085/graphql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment