Categories
cardano

What does a Cardano Stake Pool do?

This article is copy of https://www.beaver-stake-pool.net/post/what-does-a-cardano-stake-pool-do

Simple put, a Cardano Stake Pool is a participant in the Proof-of-Stake consensus algorithm, Ouroboros.

During the Shelley phase, the Cardano network utilizes Ouroboros Praos. A stake pool’s main functions are:

  1. Forge new blocks
  2. Verify new blocks
  3. Confirm transactions

Figure 1 below illustrates the general steps that a stake pool goes through to create a block.

Figure 1: How a Stake Pool Forges Blocks

  1. At every slot, which is every second, the stake pool uses the Verified Random Function (VRF) to check if it is the slot leader. The function takes the slot ID, Nonce, and VRF signing key as inputs to generate a random output value. If the output value is less than the threshold, which is determined by the stake pool’s relative stake, then you are crowned the slot leader for this particular slot. The higher the pool’s stake, the higher probability that the stake pool becomes the slot leader.
  2. If a stake pool is assigned as leader, it signs a new block using the Key Evolving Signature (KES) signing key, along with the computed VRF output and proof, and transactions waiting for confirmation by the network.
  3. This stake pool’s new block is then broadcasted to other nodes to the network.

Since a stake pool is checking for slot leadership every second, it is imperative that stake pools have 100% up-time to ensure they don’t miss being elected slot leader.

The Nonce value used in the VRF is used as a seeding value for random number generation. It is created by hashing the first 2/3s of the VRF outputs from the previous epoch’s blocks.

If a stake pool is not forging blocks, it still plays a role by verifying blocks and confirming transactions. Figure 2 illustrates how blocks are verified while the stake pool is waiting to be a slot leader.

Figure 2: How a stake pool verifies incoming blocks

  1. The stake pool uses the VRF to check for slot leadership every slot.
  2. A new block is received from our connected peers.
  3. The stake pool verifies the block’s VRF proof using the VRF verification (public) key from the corresponding stake pool that signed the block. If it is valid, it gets added to the local block chain.

An interesting property of Ouroboros Praos is that each stake pool independently tries to determine whether or not they are the slot leader with the VRF. The slot leadership schedule is not known in advance and pools will only know who a slot leader was when a block is received and verified.

This also means that two or more stake pools could determine themselves as the slot leader for a single slot. This is what’s called a slot battle. Slot battles are now resolved by the VRF. Whichever block has a lower VRF output value is determined to be the winner of that slot.

The cardano-node code developed by IOHK performs all these actions after a stake pool owner has configured the program to operate for their own pool(s).

For more details on Ouroboros Praos:

  1. Eurocrypt 2018: Ouroboros Praos https://eurocrypt.iacr.org/2018/Slides/Tuesday/TrackA/01-03.pdf
  2. Ouroboros Praos: An adaptively-secure, semi-synchronous proof-of-stake blockchain https://eprint.iacr.org/2017/573.pdf
Categories
cardano

Get all cardano testnet relay node details

 cardano-cli query ledger-state --testnet-magic 1097911063 --allegra-era 

#Get specific stakepool details

 cardano-cli query ledger-state --testnet-magic 1097911063 --allegra-era | grep -C 30 $(cat stakepoolid.txt)
Categories
cardano Uncategorized

Cardano simple transaction – Testnet

payment2.addr = TO address (addr_test1qqr585tvlc7ylnqvz8pyqwauzrdu0mxag3m7q56grgmgu7sxu2hyfhlkwuxupa9d5085eunq2qywy7hvmvej456flknswgndm3)
payment.addr = FROM address(addr_test1qzvvw5j2636y3r0cg3spu94htzjxupmt2hxld5gxzsp873lpqqmdlvg6k2sfdnzjz8q3pr3q8meydx05q4cacmnzxxesawnv76)

#Draft transaction

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment2.addr)+0 \
--tx-out $(cat payment.addr)+0 \
--ttl 0 \
--fee 0 \
--out-file tx.draft

#Minimum fee

cardano-cli shelley transaction calculate-min-fee \
--tx-in-count 1 \
--tx-out-count 2 \
--tx-body-file tx.draft \
--testnet-magic 1097911063 \
--witness-count 3 \
--protocol-params-file protocol.json

minimum fee : 189481

#Calculation

497452809 – 100000000 – 189481 = 397263328
payment.addr – payment2.addr – fee = 397263328

#Get updated slot

currentSlot=$(cardano-cli query tip --testnet-magic 1097911063 | jq -r '.slotNo')
echo Current Slot: $currentSlot
updated_currentSlot=$(($currentSlot+1000))
echo Updated Slot: $updated_currentSlot

#Build raw transaction

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment2.addr)+100000000 \
--tx-out $(cat payment.addr)+397263328 \
--ttl 14949695 \
--fee 189481 \
--out-file tx.raw

#Sign transaction

cardano-cli shelley transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--testnet-magic 1097911063 \
--out-file tx.signed

#Submit transaction

cardano-cli shelley transaction submit \
--tx-file tx.signed \
--testnet-magic 1097911063

root@core:~/cardano-my-node# cat protocol.json | grep minUTxOValue
minUTxOValue“: 1000000,

Shelley command failed: transaction submit Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (UtxoFailure (OutputTooSmallUTxO [(Addr Mainnet (KeyHashObj (KeyHash “6ccf7afbb2f916c52aa01eeffaa71b500d903ef2421c9b40343a5145”)) (StakeRefBase (KeyHashObj (KeyHash “61ffb9726ac8436bdecfe9b94b9f18d51ce26672452808019212cfdd”))),Coin 472257)])))]

Categories
cardano

Retire cardano stake pool – Testnet

#Current EPOC

cat testnet-shelley-genesis.json | grep epoch
#"epochLength": 432000

cardano-cli shelley query tip --testnet-magic 1097911063 | grep slotNo
#"slotNo": 14711760

expr 14711760 / 432000
#34
#34+1 = earliest epoch for retirement 

cardano-cli shelley query protocol-parameters \
--testnet-magic 1097911063 \
--allegra-era \
--out-file protocol.json

cat protocol.json | grep eMax

#"eMax": 18

#Create deregistration certificate

cardano-cli shelley stake-pool deregistration-certificate \
--cold-verification-key-file node.vkey \
--epoch 35 \
--out-file pool.deregistration

#Draft the transaction

cardano-cli shelley query utxo \
    --address $(cat payment.addr) \
    --testnet-magic 1097911063 \
    --allegra-era

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment.addr)+0 \
--ttl 0 \
--fee 0 \
--out-file tx.draft \
--certificate-file pool.deregistration

#Calculate the fees

cardano-cli shelley transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 1 \
--witness-count 1 \
--byron-witness-count 0 \
--testnet-magic 1097911063 \
--protocol-params-file protocol.json

#172761

expr 497452809 - 172761 = 497280048

#Build, sign and submit the transaction

#TTL

currentSlot=$(cardano-cli query tip --testnet-magic 1097911063 | jq -r '.slotNo')
echo Current Slot: $currentSlot

updated_currentSlot=$(($currentSlot+10000))
echo Updated Slot: $updated_currentSlot
#14721760

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment.addr)+497280048 \
--ttl 14721760 \
--fee 172761 \
--out-file tx.raw \
--certificate-file pool.deregistration

#sign
cardano-cli shelley transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--signing-key-file node.skey \
--testnet-magic 1097911063 \
--out-file tx.signed

#submit

cardano-cli shelley transaction submit \
--tx-file tx.signed \
--testnet-magic 1097911063 

#stackpool status:

cardano-cli stake-pool id --cold-verification-key-file $HOME/cold-keys/node.vkey --output-format hex > stakepoolid.txt
cat stakepoolid.txt

cardano-cli query ledger-state --testnet-magic 1097911063 --allegra-era | grep -C 20 $(cat stakepoolid.txt)

Check status

cardano-cli query ledger-state --testnet-magic 1097911063 --allegra-era --out-file ledger-state.json

jq -r '.esLState._delegationState._pstate._pParams."'"$(cat stakepoolid.txt)"'"  // empty' ledger-state.json

Reward status:

cardano-cli query stake-address-info \
    --testnet-magic 1097911063 \
    --allegra-era \
    --address $(cat stake.addr) | jq -r ".[0].rewardAccountBalance"

Refrences:
https://www.coincashew.com/coins/overview-ada/guide-how-to-build-a-haskell-stakepool-node#19-retire-your-stake-pool

https://docs.cardano.org/projects/cardano-node/en/latest/stake-pool-operations/retire_stakepool.html

Categories
cardano

Submit cardano transaction – Testnet

#Get protocol parameters

cardano-cli shelley query protocol-parameters \
--testnet-magic 1097911063 \
--allegra-era \
--out-file protocol.json

#Get the transaction hash and index of the UTXO to spend

cardano-cli shelley query utxo \
  --address $(cat payment.addr) \
  --testnet-magic 1097911063 \
  --allegra-era

Output:

#Draft the transaction

cardano-cli shelley transaction build-raw \
--tx-in 03ed78363f5d715302d84bbc79cfcdd7a7e92eaa1511a8ed87e45b2b07c5713e#0 \
--tx-out $(cat payment.addr)+0 \
--ttl 0 \
--fee 0 \
--out-file tx.draft

TxId = transaction hash
TxIx = transaction index
tx-out = TxOut+Lovelace
TxOut = hex encoded address
Lovelace = Amount of ADA*1000000

#Calculate the fee

cardano-cli shelley transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 2 \
--witness-count 1 \
--byron-witness-count 0 \
--testnet-magic 1097911063 \
--protocol-params-file protocol.json

Output:
175621

#Calculate the change to send back to payment.addr

expr <UTXO BALANCE> - <AMOUNT TO SEND> - <TRANSACTION FEE>

//Exmaple
expr 497628430 - 497452809 - 175621

#Determine the TTL (time to Live) for the transaction

– TTL = slotNo + N slots
– N = Amount of slots you want to add to give the transaction a window to be included in a block

currentSlot=$(cardano-cli query tip --testnet-magic 1097911063 | jq -r '.slotNo')
echo Current Slot: $currentSlot

updated_currentSlot=$(($currentSlot+1000))
echo Updated Slot: $updated_currentSlot

#Build the transaction

cardano-cli shelley transaction build-raw \
--tx-in 03ed78363f5d715302d84bbc79cfcdd7a7e92eaa1511a8ed87e45b2b07c5713e#0 \
--tx-out $(cat payment.addr)+497452809 \
--ttl 14689800 \
--fee 175621 \
--out-file tx.raw

#Build transaction2

cardano-cli shelley transaction build-raw \
--tx-in 03ed78363f5d715302d84bbc79cfcdd7a7e92eaa1511a8ed87e45b2b07c5713e#0 \
--tx-out $(cat payment2.addr)+100000000 \
--tx-out $(cat payment.addr)+397454217 \
--ttl 14689800 \
--fee 175621 \
--out-file tx.raw

-payment.addr = FROM address
-payment2.addr = TO address

#Sign the transaction

cardano-cli shelley transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--signing-key-file node.skey \
--testnet-magic 1097911063  \
--out-file tx.signed

#Submit the transaction

cardano-cli shelley transaction submit \
--tx-file tx.signed \
--testnet-magic 1097911063

#Check the balances

cardano-cli shelley query utxo \
    --address $(cat payment.addr) \
    --testnet-magic 1097911063 \
    --allegra-era

References :
https://docs.cardano.org/projects/cardano-node/en/1.18.0/reference/transactions.html

https://docs.cardano.org/projects/cardano-node/en/latest/stake-pool-operations/simple_transaction.html

Categories
cardano Uncategorized

Cardano-DevOps

Help cardano community to automate