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:
Forge new blocks
Verify new blocks
Figure 1 below illustrates the general steps that a stake pool goes through to create a block.
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.
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.
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.
The stake pool uses the VRF to check for slot leadership every slot.
A new block is received from our connected peers.
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:
Eurocrypt 2018: Ouroboros Praos https://eurocrypt.iacr.org/2018/Slides/Tuesday/TrackA/01-03.pdf
Ouroboros Praos: An adaptively-secure, semi-synchronous proof-of-stake blockchain https://eprint.iacr.org/2017/573.pdf