<aside> 💡 WARNING. THIS DOCUMENTATION IS NOT UP-TO-DATE, AND MIGHT BE MAJORLY DIFFERENT FROM THE CURRENT IMPLEMENTATION. USING THIS DOCUMENTATION FOR REFERENCE PURPOSE ONLY.

</aside>

Overall flow

sequenceDiagram
  actor C as coinbase
	participant I as SlashIndicator
  participant V as ValidatorSet
  participant S as Staking

  loop (I) on each block
    C->>+V: submitReward
	  V->>-S: recordReward for delegators
		activate S
		deactivate S
  end

	loop (II) epoch end
    C->>+V: wrapUpEpoch
    V->>S: settleReward for validators
		activate S
		deactivate S
  alt (III) period end
    V->>-I: resetSlashCounter
		activate I
		deactivate I
	end
  end

  opt (IV) at anytime
    C->>+I: slash
    I->>+V: slash (according to slashing type)
		deactivate I
		V->>-S: slash (according to slashing type)
		activate S
		deactivate S
  end

(I) Actions on each block

A. Submit block reward

sequenceDiagram
  actor C as coinbase
	participant I as SlashIndicator
  participant V as ValidatorSet
  participant S as Staking

  autonumber

  Note over C,S: on each block
  C->>+V: Submit block reward
	V->>V: Check slash status of the coinbase
  alt is slashed
		V->>V: Deprecate deposit
	else is not slashed
		V->>-V: Update validators' pending reward for current epoch		 
	end
 

(II) Actions at the end of each epoch

B. Update validator set

sequenceDiagram
  actor C as coinbase
	participant I as SlashIndicator
  participant V as ValidatorSet
  participant S as Staking

  autonumber

  Note over C,S: at end of epoch
  C->>+V: Update validator set
  V->>+S: Get balance info of candidates
  S-->>-V: (Candidates' balance)
	V->>V: Get jailed candidates
	V->>V: Drop jailed candidates out of sorting list
  V->>V: Sort candidates
  V->>V: Pick top N candidates
  alt is at end of period
	  Note over C,S: at end of period
		rect rgb(191, 223, 255)
	  V-)-V: <See Clean Up Slashing>
		end
	end

C. Distribute rewards

sequenceDiagram
  actor C as coinbase
	participant I as SlashIndicator
  participant V as ValidatorSet
  participant S as Staking

  autonumber

  Note over C,S: at end of epoch
  C->>+V: Distribute reward
	V->>+S: Send validators' reward of previous epoch
	S->>-S: Update pending reward for validators and delegators
  V->>-V: Reset pending rewards