github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/staking/spec/05_end_block.md (about) 1 <!-- 2 order: 5 3 --> 4 5 # End-Block 6 7 Each abci end block call, the operations to update queues and validator set 8 changes are specified to execute. 9 10 ## Validator Set Changes 11 12 The staking validator set is updated during this process by state transitions 13 that run at the end of every block. As a part of this process any updated 14 validators are also returned back to Tendermint for inclusion in the Tendermint 15 validator set which is responsible for validating Tendermint messages at the 16 consensus layer. Operations are as following: 17 18 - the new validator set is taken as the top `params.MaxValidators` number of 19 validators retrieved from the ValidatorsByPower index 20 - the previous validator set is compared with the new validator set: 21 - missing validators begin unbonding and their `Tokens` are transferred from the 22 `BondedPool` to the `NotBondedPool` `ModuleAccount` 23 - new validators are instantly bonded and their `Tokens` are transferred from the 24 `NotBondedPool` to the `BondedPool` `ModuleAccount` 25 26 In all cases, any validators leaving or entering the bonded validator set or 27 changing balances and staying within the bonded validator set incur an update 28 message which is passed back to Tendermint. 29 30 ## Queues 31 32 Within staking, certain state-transitions are not instantaneous but take place 33 over a duration of time (typically the unbonding period). When these 34 transitions are mature certain operations must take place in order to complete 35 the state operation. This is achieved through the use of queues which are 36 checked/processed at the end of each block. 37 38 ### Unbonding Validators 39 40 When a validator is kicked out of the bonded validator set (either through 41 being jailed, or not having sufficient bonded tokens) it begins the unbonding 42 process along with all its delegations begin unbonding (while still being 43 delegated to this validator). At this point the validator is said to be an 44 unbonding validator, whereby it will mature to become an "unbonded validator" 45 after the unbonding period has passed. 46 47 Each block the validator queue is to be checked for mature unbonding validators 48 (namely with a completion time <= current time). At this point any mature 49 validators which do not have any delegations remaining are deleted from state. 50 For all other mature unbonding validators that still have remaining 51 delegations, the `validator.Status` is switched from `sdk.Unbonding` to 52 `sdk.Unbonded`. 53 54 ### Unbonding Delegations 55 56 Complete the unbonding of all mature `UnbondingDelegations.Entries` within the 57 `UnbondingDelegations` queue with the following procedure: 58 59 - transfer the balance coins to the delegator's wallet address 60 - remove the mature entry from `UnbondingDelegation.Entries` 61 - remove the `UnbondingDelegation` object from the store if there are no 62 remaining entries. 63 64 ### Redelegations 65 66 Complete the unbonding of all mature `Redelegation.Entries` within the 67 `Redelegations` queue with the following procedure: 68 69 - remove the mature entry from `Redelegation.Entries` 70 - remove the `Redelegation` object from the store if there are no 71 remaining entries.