I am attending the Plutus Cohort #3 so I can better understand smart contracts on Cardano. Week 1 was a lot of struggles due to stubborn me wanting to make it easy to run through windows with windows wsl (a way to run a linux subsystem inside windows itself) (most of the cohorts seems to have gone down the route of virtual machine to run ubuntu or such) but I finally got it set up and with a good IDE with VSCode connected to the linux subsystem so I can do the workflow in windows and compile and run in Ubuntu on the same computer. Week 2 is so far great fun and I am sure Week 3 is going to be fun as well. Lars Brünjes is a great teacher and the community is already doing guides for further understanding.
The Plutus course will be a great suppliment to the Atala Prism course I finished where I learned to work with decentralized identifiers through Atala Prism and sets me up to do more building in the ecosystem in the future.
Firstly we need to go through some theory on how staking works at a protocol level, then we will look at how to delegate from wallets itself.
Time periods in Cardano: Epochs, slots and nominations.
The Cardano network has time periods called Epochs that last 432000 slots and each slot lasts 1 second. That means an epoch lasts 5 days. On average a pool node is expected to be nominated for block production every 20 seconds, and there are roughly 21600 nominations per epoch. This is determined by the active slot coefficient that currently is at 5% meaning that out of all the slots only 5% will at most be eligible for the pool to produce blocks. This is also why the network health is sometimes reported in chain density and ideally this number is close to 5% currently.
For each successful nomination there is a chance for a block to be produced on the network. Due to randomization and also pool block production issues each epoch is usually never 21600 blocks as can be seen on Cardano blockchain explorers (https://explorer.cardano.org/en) where the average hovers around 21000 blocks per epoch. This can among other reasons be caused by delays in block production due to latency issues, wrongly configured time synchronization, or hardware resources issues such as too low specs on memory or CPU power to calculate and report the block on the blockchain in time.
Timing and the delegation process: Delegation certificate, Snapshot, Active stake and Live stake, rewards calculation and rewards distribution.
Delegation certificate So let us say that we are currently in epoch N — for example epoch 307 — and you decide to delegate your ADA to a staking pool such as ADA North Pool. Your wallet will generate a staking key with a delegation certificate at a cost of a transaction currently around 0.17 ADA and a deposit of what is currently 2 ADA, meaning you need 2.17 ADA on an account to register for delegation.
Snapshot, active and live stake. Assuming you create a delegation certificate in epoch N the snapshot of your wallet ADA amount will be taken at the start of epoch N+1 with the value held at the last block of epoch N, in the example this will be epoch 308. It then become the active stake in epoch N+2. In the example this would be epoch 309. The live stake is the amount at any given snapshot you hold in your wallet, and becomes the active stake in the next epoch after the snapshot. That means that if you move founds out of your wallet and back in again before the last block of the current epoch you will still register with the same amount, or for example if you buy more ada your live stake will increase, and will be registered in the snapshot in the next epoch and become the active stake in the the epoch after this.
Reward calculation Rewards are calculated in epoch N+3, in the example this would be epoch 310. That means rewards are always calculated for the previous epoch. It will be based on such factors as blocks produced by pool during epoch N+2 (the active stake period) and the overall reward pool that is distributed will also be influenced by factors such as transaction fees collected during the epoch on the network. The pool will also collect fees before rewards are distributed. It is important here to know that there is a minimum fee of 340 (pools can choose to increase this but never under the minimum fee parameter) ADA that is a cost spread out over all delegators of a pool, and also there is a % fee that each pool will deduct from each delegators reward. You can find a reward calculator here: https://cardano.org/calculator/?calculator=delegator and at the time of writing this guide you can expect on average around 4.6% annual return on your delegation.
Reward distribution Rewards are distributed at the start of the epoch after rewards calculation (technically at the end of the last block of the rewards calculation epoch) so N+4 or. In this example this would mean epoch 311. Keep in mind these are the rewards for the stake that was active in epoch N+2 (in this example epoch 309). These rewards are automatically part of the delegation of the wallet, but you will need to claim the rewards in a transaction (0.17 ADA currently) to send them from your wallet. At this point you will keep receiving rewards every epoch as long as you have an active stake amount.