Skip to content

Conversation

@fcecin
Copy link
Contributor

@fcecin fcecin commented Feb 21, 2025

The SystemContract is a new protocol contract that exposes a simple API for chain governance:

  • stake: allows any address to deposit tokens in the SystemContract (liquid)
  • unstake: opposite of stake (retrieve tokens)
  • delegate: an account locks some of its deposited stake to vote for a validator key
  • undelegate: an account unvotes from a validator key, unlocking tokens back into liquid stake
  • voteSlots: an elected validator chooses to increase or decrease the total number of active validators in the network (when 2/3+1 of active validators agree, the total number of active validators in the network changes).

The SystemContract is a privileged contract that has direct and full control of the CometBFT validator set, and so it cannot be deployed by transactions; only the BDK node itself can instantiate the singleton SystemContract, either on Blockchain::initChain() or Blockchain::loadSnapshot() (which are the only two ways to initialize a Blockchain node's machine state).

The default number of slots (number of validators on a BDK network) on a new chain is initialized to the number of validators given in the genesis.json configuration option. On genesis, the SystemContract will set the voting amount of all genesis validators to zero delegated tokens, irrespective of the voting power assigned to the CometBFT protocol in the genesis.json validator list. The default, genesis validators should either receive delegations from the chain owner after chain boot, or be replaced by some validators that actually get token votes.

The validator set is determined by the number of avaliable slots and by a simple voting contest among all validator keys that have received a nonzero amount of delegated native tokens (votes) to fill these slots. If there are more slots than voted validator keys, all the validator keys that were delegated at least 1 wei are elected.

A validator (public) key can only receive delegations (token votes) from other keys after it is "registered". For a validator key to register itself, all it needs to do is to delegate tokens to itself, that is, using the account address that is controlled by the validator (private) key.

NOTE: This PR also rolls in a few fixes, improvements and new features that were developed together with the SystemContract feature.

@fcecin fcecin marked this pull request as draft February 21, 2025 19:42
@fcecin
Copy link
Contributor Author

fcecin commented Feb 21, 2025

Need to add the final obligatory feature, which is to protect against instantiating this contract by a transaction.

I can't remove it from the ContractTypes, otherwise it doesn't dump itself. Unless I dump it manually, like it was with the old, stateful ContractManager. Hmm...

@fcecin fcecin marked this pull request as ready for review February 21, 2025 23:04
@fcecin fcecin merged commit ffc2cc1 into halley Feb 21, 2025
@fcecin fcecin deleted the chain_gov branch February 27, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants