Consensus

Model peer consensus mechanisms

Outline


Introduction

This is the first version of the peer consensus mechanism used in testnet v1.0.

When running a node hosting AI Models through Petals Tensor, these actions are automatically run within the software.


Forming Consensus

In between each epoch, blockchain validators form a consensus on the epoch's consensus data submissions per model. This is done automatically through the on_initialize hook that is called at the beginning of each block through validators (read more: https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/trait.Hooks.html#method.on_initialize). In the case of forming consensus, it is called once per epoch in the form_consensus() function.

Read Info for more information.


Submit Consensus Data

Model Validators (peers) are required to submit consensus data on each epoch of each other model validator, including themselves, hosting AI models. This is a gasless transaction with no costs if successful.

pub fn submit_consensus_data(
    origin: OriginFor<T>,
    model_id: u32,
    consensus_data: Vec<ModelPeerData>,
) -> DispatchResultWithPostInfo

Parameters

  • model_id: The key of the model. This can be found through querying ModelPaths using the model path.

  • consensus_data: The required data for forming consensus per model on each peer hosting model.

    • peer_id: The peer_id for the peer in association to data being submitted.

    • score: The score of the peer based on their contribution to hosting machine learning models.

    pub struct ModelPeerData {
        pub peer_id: PeerId,
        pub score: u64,
    }

Information


Unconfirm Consensus Data

This step is not required in consensus

Model Validators (peers) can unconfirm consensus data. This should happen when a model is in an error state or when there's an error state before all other model validators have submitted consensus data. If enough model validators submit an unconfirm_consensus_data(), based on ModelConsensusUnconfirmedThreshold, then the model consensus will be skipped for that epoch. This is a gasless transaction with no costs.

This helps avoid incrementing the model validator's AccountPenaltyCount's that have not yet submitted consensus data due to a model error where they cannot query model hoster data.

pub fn unconfirm_consensus_data(
    origin: OriginFor<T>,
    model_id: u32,
) -> DispatchResultWithPostInfo

Parameters

Information


Requirements

These requirements are primarily handled automatically within the AI Model Hosting software.

Model Submission Acceptance Requirements

  1. The blockchain must not be in its consensus steps or model peer removal blocks span. During these block steps, no changes can be made to storage that impact consensus or emissions.

  2. The minimum required epochs must be met based on the model initialization block based on MinRequiredModelConsensusSubmitEpochs. This is the amount of epochs that have gone by since initialization versus the minimum required epochs.

    • By this time, the required minimum model peers must be ready to submit data or the model will generate consensus errors.

  3. The minimum required model peers must be initialized before the MinRequiredModelConsensusSubmitEpochs based on the MinModelPeers.

Model Peer Submission Requirements

  1. The required minimum epochs must be met based on the model peer initialization block based on MinRequiredPeerConsensusSubmitEpochs. This is the amount of epochs that have gone by since initialization versus the minimum required epochs.

  2. Must not have already submitted consensus data on the current epoch.

Model Peer Inclusion Requirements

  1. The required minimum epochs must be met based on the model peer initialization block based on MinRequiredPeerConsensusInclusionEpochs. This is the amount of epochs that have gone by since initialization versus the minimum required epochs.

Parameter Requirements

  • The vector length of ModelPeerData must be less than or equal to the count of peers of the model stored on the blockchain based on the TotalModelPeers of the model_id being submitted.

  • The ModelPeerData should only include each model validator hosting the model and stored on the blockchain based on the MinRequiredPeerConsensusInclusionEpochs.

    • If a peer_id is submitted that isn't stored on the blockchain, it will be skipped from being included in the ModelPeerConsensusResults.

  • The score per model validator must be between 1 - 1e4.

Rewards Absented Conditions

Peers who don't conform to consensus or do not submit consensus data will not receive rewards on that epoch.


Penalties

Account Penalties

There are multiple scenarios where an account will generate penalties that can get them removed from the blockchain and thus from receiving rewards. The accounts AccountPenaltyCount will increment on the following scenarios:

  1. Being against other peers that conclude another peer is out of consensus based on the PeerRemovalThreshold.

  2. Being against other peers that conclude another peer is in consensus based on the PeerRemovalThreshold.

  3. The score delta is too high on consensus data submission.

    • Each peer has a score submitted, by every other peer, including themselves. These scores undergo an interquartile algorithm that removes outliers and then forms the average of the non-outlier score submissions. If a peer submits a score surpassing the allowed delta based on the MaximumOutlierDeltaPercent, their AccountPenaltyCount will increment.

  4. Not having submitted consensus data.


Model Peer Removal

A model peer can be removed in the following scenarios:

  1. The AccountPenaltyCount surpasses the MaxAccountPenaltyCount.

    • This will remove all model peers under all models an account has.

    • The count doesn't reset on removal and the account must manually unstake and cannot be a model peer using that account.

  2. Being against other peers that conclude another peer is in consensus or out of consensus based on the PeerRemovalThreshold too many times on a single epoch based on the PeerAgainstConsensusRemovalThreshold.

    • This will remove the model peer under the specified model.


Note

For a peer to not be in consensus, enough peers must keep that peer absent from their consensus data. If the amount of peers that didn't include the peer versus peers who did include the peer surpasses the PeerRemovalThreshold, the peer is removed from the blockchain storage and no longer eligible to generate emissions, be included in consensus data, and submit consensus data. This peer can then manually remove their stake balance towards that model they were removed from.

Last updated