Outline
General Methods
↑ Back to Outline To express the error conditions, the following specification of the sub-protocols uses the exception system of the host state machine, which is exposed through two functions (as defined in ICS 24):abortTransactionUnless and abortSystemUnless.
BeginBlock and EndBlock
↑ Back to Outline The functionsBeginBlock() and EndBlock() (see Implemented Interfaces) are split across the CCV sub-protocols.
[CCV-PCF-BBLOCK.1]
- Caller
- The ABCI application.
- Trigger Event
- A
BeginBlockmessage is received from the consensus engine;BeginBlockmessages are sent once per block.
- A
- Precondition
- True.
- Postcondition
BeginBlockInit()is invoked (see [CCV-PCF-BBLOCK-INIT.1], i.e., it contains theBeginBlock()logic needed for the Initialization sub-protocol).BeginBlockCCR()is invoked (see [CCV-PCF-BBLOCK-CCR.1], i.e., it contains theBeginBlock()logic needed for the Consumer Chain Removal sub-protocol).
- Error Condition
- None.
[CCV-PCF-EBLOCK.1]
- Caller
- The ABCI application.
- Trigger Event
- An
EndBlockmessage is received from the consensus engine;EndBlockmessages are sent once per block.
- An
- Precondition
- True.
- Postcondition
EndBlockCIS()is invoked (see [CCV-PCF-EBLOCK-CIS.1], i.e., it contains theEndBlock()logic needed for the Consumer Initiated Slashing sub-protocol).EndBlockCCR()is invoked (see [CCV-PCF-EBLOCK-CCR.1], i.e., it contains theEndBlock()logic needed for the Consumer Chain Removal sub-protocol).EndBlockVSU()is invoked (see [CCV-PCF-EBLOCK-VSU.1], i.e., it contains theEndBlock()logic needed for the Validator Set Update sub-protocol).
- Error Condition
- None.
Note: The provider CCV module expects the provider Staking module to update its view of the validator set before theEndBlock()of the provider CCV module is invoked. A solution is for the provider Staking module to update its view duringEndBlock()and then, theEndBlock()of the provider Staking module to be executed before theEndBlock()of the provider CCV module.
[CCV-CCF-BBLOCK.1]
- Caller
- The ABCI application.
- Trigger Event
- A
BeginBlockmessage is received from the consensus engine;BeginBlockmessages are sent once per block.
- A
- Precondition
- True.
- Postcondition
BeginBlockInit()is invoked (see [CCV-CCF-BBLOCK-INIT.1], i.e., it contains theBeginBlock()logic needed for the Channel Initialization sub-protocol).BeginBlockCCR()is invoked (see [CCV-CCF-BBLOCK-CCR.1], i.e., it contains theBeginBlock()logic needed for the Consumer Chain Removal sub-protocol).BeginBlockCIS()is invoked (see [CCV-CCF-BBLOCK-CIS.1], i.e., it contains theBeginBlock()logic needed for the Consumer Initiated Slashing sub-protocol).
- Error Condition
- None.
[CCV-CCF-EBLOCK.1]
- Caller
- The ABCI application.
- Trigger Event
- An
EndBlockmessage is received from the consensus engine;EndBlockmessages are sent once per block.
- An
- Precondition
- True. x
- Postcondition
EndBlockRD()is invoked (see [CCV-PCF-EBLOCK-RD.1], i.e., it contains theEndBlock()logic needed for the Reward Distribution sub-protocol).EndBlockVSU()is invoked and the return value is returned to the consensus engine (see [CCV-CCF-EBLOCK-VSU.1], i.e., it contains theEndBlock()logic needed for the Validator Set Update sub-protocol).
- Error Condition
- None.
Packet Relay
↑ Back to Outline[CCV-PCF-RCVP.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives a packet on a channel owned by the provider CCV module.
- Precondition
- True.
- Postcondition
- If the packet is a
VSCMaturedPacket, the acknowledgement obtained from invoking theonRecvVSCMaturedPacketmethod is returned. - If the packet is a
SlashPacket, the acknowledgement obtained from invoking theonRecvSlashPacketmethod is returned. - Otherwise, an error acknowledgement is returned.
- If the packet is a
- Error Condition
- None.
[CCV-PCF-ACKP.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives an acknowledgement on a channel owned by the provider CCV module.
- Precondition
- True.
- Postcondition
- If the acknowledgement is for a
VSCPacket, theonAcknowledgeVSCPacketmethod is invoked. - Otherwise, the transaction is aborted.
- If the acknowledgement is for a
- Error Condition
- None.
[CCV-PCF-TOP.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- A packet sent on a channel owned by the provider CCV module timed out as a result of either
- Precondition
- The Correct Relayer assumption is violated (see the Assumptions section).
- Postcondition
- If the timeout is for a
VSCPacket, theonTimeoutVSCPacketmethod is invoked. - Otherwise, the transaction is aborted.
- If the timeout is for a
- Error Condition
- None.
[CCV-CCF-RCVP.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives a packet on a channel owned by the consumer CCV module.
- Precondition
- True.
- Postcondition
- If the packet is a
VSCPacket, the acknowledgement obtained from invoking theonRecvVSCPacketmethod is returned. - Otherwise, an error acknowledgement is returned.
- If the packet is a
- Error Condition
- None.
[CCV-CCF-ACKP.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives an acknowledgement on a channel owned by the consumer CCV module.
- Precondition
- True.
- Postcondition
- If the acknowledgement is for a
VSCMaturedPacket, theonAcknowledgeVSCMaturedPacketmethod is invoked. - If the acknowledgement is for a
SlashPacket, theonAcknowledgeSlashPacketmethod is invoked. - Otherwise, the transaction is aborted.
- If the acknowledgement is for a
- Error Condition
- None.
[CCV-CCF-TOP.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- A packet sent on a channel owned by the consumer CCV module timed out as a result of either
- Precondition
- The Correct Relayer assumption is violated (see the Assumptions section).
- Postcondition
- If the timeout is for a
VSCMaturedPacket, theonTimeoutVSCMaturedPacketmethod is invoked. - If the timeout is for a
SlashPacket, theonTimeoutSlashPacketmethod is invoked. - Otherwise, the transaction is aborted.
- If the timeout is for a
- Error Condition
- None.
Sub-protocols
Initialization
↑ Back to Outline The initialization sub-protocol enables a provider chain and a consumer chain to create a CCV channel — a unique, ordered IBC channel for exchanging packets. As a prerequisite, the initialization sub-protocol MUST create two IBC clients, one on the provider chain to the consumer chain and one on the consumer chain to the provider chain. This is necessary to verify the identity of the two chains (as long as the clients are trusted).[CCV-PCF-INITG.1]
- Caller
- The ABCI application.
- Trigger Event
- An
InitChainmessage is received from the consensus engine; theInitChainmessage is sent when the provider chain is first started.
- An
- Precondition
- The provider CCV module is in the initial state.
- Postcondition
- The capability for the port
ProviderPortIdis claimed. - For each consumer state in the
ProviderGenesisState, the initial state is set, i.e., the following mappingschainToChannel,channelToChainare set.
- The capability for the port
- Error Condition
- The capability for the port
ProviderPortIdcannot be claimed. - For any consumer state in the
ProviderGenesisState, the channel ID is not valid (cf. the validation function defined in ICS 4).
- The capability for the port
[CCV-PCF-HCAPROP.1]
- Caller
EndBlock()method of Governance module.
- Trigger Event
- A governance proposal
ConsumerAdditionProposalhas passed (i.e., it got the necessary votes).
- A governance proposal
- Precondition
- True.
- Postcondition
- The proposal is appended to the list of pending addition proposals, i.e.,
pendingConsumerAdditionProposals.
- The proposal is appended to the list of pending addition proposals, i.e.,
- Error Condition
- None.
[CCV-PCF-BBLOCK-INIT.1]
- Caller
- The
BeginBlock()method.
- The
- Trigger Event
- A
BeginBlockmessage is received from the consensus engine;BeginBlockmessages are sent once per block.
- A
- Precondition
- True.
- Postcondition
- For each
ConsumerAdditionProposalpin the list of pending addition proposalspendingConsumerAdditionProposals, ifcurrentTimestamp() > p.spawnTime, thenCreateConsumerClient(p)is invoked;pis removed frompendingConsumerAdditionProposals.
- For each
- Error Condition
- None.
[CCV-PCF-CRCLIENT.1]
- Caller
- Either
HandleConsumerAdditionProposal(see CCV-PCF-HCAPROP.1) orBeginBlockInit()(see CCV-PCF-BBLOCK-INIT.1).
- Either
- Trigger Event
- A governance proposal
ConsumerAdditionProposalphas passed (i.e., it got the necessary votes).
- A governance proposal
- Precondition
currentTimestamp() > p.spawnTime.
- Postcondition
- If a client for
p.chainIdalready exists, the state is not changed. - Otherwise,
- the validator set of the provider chain own consensus state at current height is set as the initial validator set of the consumer chain;
- if
p.connIdis set, then- if a connection end with ID
p.connIdcannot be found, the state is not changed; - otherwise,
- if the connection with ID
p.connIdis not to the chain with IDp.chainId, the state is not changed; - otherwise,
- both the client ID and connection ID are stored;
- a
ConsumerGenesisStateis created and stored;
- if the connection with ID
- if a connection end with ID
- otherwise,
- otherwise,
- a client state is created with
chainId = p.chainIdandunbondingPeriod = p.unbondingPeriod; - a consensus state is created with
validatorSetset to the initial validator set of the consumer chain; - a client of the consumer chain is created and the client ID is stored;
- a
ConsumerGenesisStateis created and stored;
- a client state is created with
- otherwise,
lockUnbondingOnTimeout[p.chainId]is set top.lockUnbondingOnTimeout.- The init timeout timestamp is computed and stored in
initTimeoutTimestamps[p.chainId].
- If a client for
- Error Condition
- None.
Note: For the case when theclientIdfield of theConsumerAdditionProposalis not set, creating a client of a remote chain requires aClientStateand aConsensusState(for an example, take a look at ICS 7).ConsensusStaterequires setting a validator set of the remote chain. The provider chain uses the fact that the validator set of the consumer chain is the same as its own validator set. Note: Bootstrapping the consumer CCV module requires aConsumerGenesisState(see the CCV Data Structures section). The provider CCV module creates such aConsumerGenesisStatewhen handling a governance proposalConsumerAdditionProposal. Note: If the channel initialization for a consumer chain exceeds theinitTimeoutperiod, then the provider chain removes that consumer. As a result, all further attempts on the consumer side to established the CCV channel will fail. This means that the consumer chain requires some sort of social consensus to either restart the process of becoming a consumer chain or transitioning back to a sovereign chain.
[CCV-PCF-COINIT.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives a
ChanOpenInitmessage on a port the provider CCV module is bounded to.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is always aborted; hence, the state is not changed.
- Error Condition
- None.
[CCV-PCF-COTRY.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives a
ChanOpenTrymessage on a port the provider CCV module is bounded to.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is aborted if any of the following conditions are true:
- the channel is not ordered;
portIdentifier != ProviderPortId;counterpartyPortIdentifier != ConsumerPortId;counterpartyVersion != ccvVersion;- no channel with
portIdentifierandchannelIdentifierexists; - the channel has more than one connection hop;
- a connection is stored for this consumer chain and doesn’t match the underlying connection of this channel;
- the channel is not built on top of the client created for this consumer chain;
- another CCV channel for this consumer chain already exists.
- A
CCVHandshakeMetadatais returned, withproviderDistributionAccountset to the address of the distribution module account on the provider chain andversionset toccvVersion. - The state is not changed.
- The transaction is aborted if any of the following conditions are true:
- Error Condition
- None.
[CCV-PCF-COACK.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives a
ChanOpenAckmessage on a port the provider CCV module is bounded to.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is always aborted; hence, the state is not changed.
- Error Condition
- None.
[CCV-PCF-COCONFIRM.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives a
ChanOpenConfirmmessage on a port the provider CCV module is bounded to.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is aborted if any of the following conditions are true:
- no channel with
portIdentifierandchannelIdentifierexists; - the channel has more than one connection hop;
- another CCV channel for this consumer chain already exists.
- no channel with
- The connection mapping is set, i.e.,
chainToConnection. - The channel mappings are set, i.e.,
chainToChannelandchannelToChain. initialHeights[chainId]is set to the current height.- The init timeout timestamp for the consumer chain with ID
clientState.chainIdis removed.
- The transaction is aborted if any of the following conditions are true:
- Error Condition
- None.
[CCV-CCF-INITG.1]
- Caller
- The ABCI application.
- Trigger Event
- An
InitChainmessage is received from the consensus engine; theInitChainmessage is sent when the consumer chain is first started.
- An
- Precondition
- The consumer CCV module is in the initial state.
- Postcondition
- The capability for the port
ConsumerPortIdis claimed. preCCVis set togs.preCCV.- If
preCCV == true, the ID of the client on which the connection withgs.connIdis built is stored intoproviderClientId. - Otherwise, a client of the provider chain is created and the client ID is stored into
providerClientId. ConsumerUnbondingPeriodis set togs.unbondingPeriod.HtoVSCfor the current block is set to0.- The
ccvValidatorSetmapping is populated with the initial validator set. - The ID of the distribution token transfer channel is set to
gs.transferChannelId. - If
preCCV == true, the CCV channel opening handshake is initialized. - Otherwise, the connection opening handshake is initialized.
- The initial validator set is returned to the consensus engine.
- The capability for the port
- Error Condition
- The genesis state contains an empty initial validator set.
- If the genesis state
preCCVfield is set totrue, then the genesis state contains no valid connection ID. - Otherwise,
- the genesis state contains no valid provider client state, where the validity is defined in the corresponding client specification (e.g., ICS 7;
- the genesis state contains no valid provider consensus state, where the validity is defined in the corresponding client specification (e.g., ICS 7);
- the genesis state contains an initial validator set that does not match the validator set in the provider consensus state;
- The genesis state contains an invalid distribution channel ID.
- The capability for the port
ConsumerPortIdcannot be claimed.
Note: CCV assumes that all the correct validators in the initial validator set of the consumer chain receive the same consumer chain binary and consumer chain genesis state. Although the mechanism of disseminating the binary and the genesis state is outside the scope of this specification, a possible approach would entail including this information in the governance proposal on the provider chain.
[CCV-CCF-COINIT.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives a
ChanOpenInitmessage on a port the consumer CCV module is bounded to.
- The consumer IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is aborted if any of the following conditions are true:
providerChannelis already set;portIdentifier != ConsumerPortId;versionis set but not to the expected version;counterpartyPortIdentifier != ProviderPortId;- the client associated with this channel is not the expected provider client.
ccvVersionis returned.- The state is not changed.
- The transaction is aborted if any of the following conditions are true:
- Error Condition
- None.
[CCV-CCF-COTRY.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives a
ChanOpenTrymessage on a port the consumer CCV module is bounded to.
- The consumer IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is always aborted; hence, the state is not changed.
- Error Condition
- None.
[CCV-CCF-COACK.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives a
ChanOpenAckmessage on a port the consumer CCV module is bounded to.
- The consumer IBC routing module receives a
- Precondition
- True.
- Postcondition
counterpartyVersionis unmarshaled into aCCVHandshakeMetadatastructuremd.- The transaction is aborted if any of the following conditions are true:
providerChannelis already set;md.version != ccvVersion.
- The address of the distribution module account on the provider chain is set to
md.providerDistributionAccount. - If
distributionChannelIdis not set, the distribution token transfer channel opening handshake is initiated anddistributionChannelIdis set to the resulting channel ID. - The CCV channel is marked as established, i.e.,
providerChannelis set to this channel. - The pending slash requests are sent to the provider chain (see [CCV-CCF-SNDPESLASH.1]).
Note that this can happen only if
preCCV == false, as the ABCI application can invokeSendSlashRequestonly once the chain is upgraded to a consumer chain (see [CCV-CCF-BBLOCK-INIT.1]). - If
preCCV == true, the valset in the staking module is replaced with theccvValidatorSet, i.e., the initial validator set.
- Error Condition
- None.
[CCV-CCF-COCONFIRM.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives a
ChanOpenConfirmmessage on a port the consumer CCV module is bounded to.
- The consumer IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is always aborted; hence, the state is not changed.
- Error Condition
- None.
[CCV-CCF-BBLOCK-INIT.1]
- Caller
- The
BeginBlock()method.
- The
- Trigger Event
- A
BeginBlockmessage is received from the consensus engine;BeginBlockmessages are sent once per block.
- A
- Precondition
- True.
- Postcondition
- If
preCCV == trueand the current validator set matches theccvValidatorSet(i.e., the initial validator set), then the chain MUST be upgraded to a full consumer chain. The upgrade mechanism is outside the scope of this specification.
- If
- Error Condition
- None.
Consumer Chain Removal
↑ Back to Outline[CCV-PCF-HCRPROP.1]
- Caller
EndBlock()method of Governance module.
- Trigger Event
- A governance proposal
ConsumerRemovalProposalhas passed (i.e., it got the necessary votes).
- A governance proposal
- Precondition
- True.
- Postcondition
- The proposal is appended to the list of pending removal proposals, i.e.,
pendingConsumerRemovalProposals.
- The proposal is appended to the list of pending removal proposals, i.e.,
- Error Condition
- None.
[CCV-PCF-BBLOCK-CCR.1]
- Caller
- The
BeginBlock()method.
- The
- Trigger Event
- A
BeginBlockmessage is received from the consensus engine;BeginBlockmessages are sent once per block.
- A
- Precondition
- True.
- Postcondition
- For each
ConsumerRemovalProposalpin the list of pending removal proposalspendingConsumerRemovalProposals, ifcurrentTimestamp() > p.stopTime, thenStopConsumerChain(p.chainId, false)is invoked;pis removed frompendingConsumerRemovalProposals.
- For each
- Error Condition
- None.
[CCV-PCF-STCC.1]
- Caller
HandleConsumerRemovalProposal(see CCV-PCF-HCRPROP.1) orBeginBlockCCR()(see CCV-PCF-BBLOCK-CCR.1) oronTimeoutVSCPacket()(see CCV-PCF-TOVSC.1) orEndBlockCCR()(see CCV-PCF-EBLOCK-CCR.1).
- Trigger Event
- One of the following events:
- a governance proposal to stop the consumer chain with
chainIdhas passed (i.e., it got the necessary votes); - a
VSCPacketsent on the CCV channel to the consumer chain withchainIdhas timed out; - the channel initialization has timed out.
- a governance proposal to stop the consumer chain with
- One of the following events:
- Precondition
- True.
- Postcondition
- If a client for
p.chainIddoes not exist, the state is not changed. - Otherwise,
- the client ID mapped to
chainIdinchainToClientis removed; - the value mapped to
chainIdinlockUnbondingOnTimeoutis removed; - if the CCV channel to the consumer chain with
chainIdis established, then- the chain ID mapped to
chainToChannel[chainId]inchannelToChainis removed; - the channel closing handshake is initiated for the CCV channel;
- the channel ID mapped to
chainIdinchainToChannelis removed.
- the chain ID mapped to
- all the
VSCPacketDatamapped tochainIdinpendingVSCPacketsare removed; - the height mapped to
chainIdininitialHeightsis removed; downtimeSlashRequests[chainId]is emptied;- if
lockUnbonding == false, thenchainIdis removed from all outstanding unbonding operations;- if an outstanding unbonding operation has matured on all consumer chains,
- the matured unbonding operation is added to
maturedUnbondingOps; - the matured unbonding operation is removed from
unbondingOps; - all the entries with
chainIdare removed from thevscToUnbondingOpsmapping.
- the client ID mapped to
- If a client for
- Error Condition
- None
Note: InvokingStopConsumerChain(chainId, lockUnbonding)withlockUnbonding == FALSEentails that all outstanding unbonding operations can complete beforeConsumerUnbondingPeriodelapses on the consumer chain withchainId. Thus, invokingStopConsumerChain(chainId, false)for anychainIdMAY violate the Bond-Based Consumer Voting Power and Slashable Consumer Misbehavior properties (see the System Properties section).StopConsumerChain(chainId, false)is invoked in two scenarios (see Trigger Event above).
- In the first scenario (i.e., a governance proposal to stop the consumer chain with
chainId), the validators on the provider chain MUST make sure that it is safe to stop the consumer chain. Since a governance proposal needs a majority of the voting power to pass, the safety of invokingStopConsumerChain(chainId, false)is ensured by the Safe Blockchain assumption (see the Assumptions section).- The second scenario (i.e., a timeout) is only possible if the Correct Relayer assumption is violated (see the Assumptions section), which is necessary to guarantee both the Bond-Based Consumer Voting Power and Slashable Consumer Misbehavior properties (see the Assumptions section).
[CCV-PCF-EBLOCK-CCR.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine;EndBlockmessages are sent once per block.
- An
- Precondition
- True.
- Postcondition
- For each consumer chain ID
chainIdinvscSendTimestamps.Keys(),- if
vscSendTimestamps[(chainId, vscId)] + vscTimeoutis smaller than the current timestamp, then the consumer chain with IDchainIdis stopped.
- if
- For each consumer chain ID
chainIdininitTimeoutTimestamps.Keys(),- if the timestamp in
initTimeoutTimestamps[chainId]is smaller than the current timestamp, then the consumer chain with IDchainIdis stopped.
- if the timestamp in
- For each consumer chain ID
- Error Condition
- None.
Note: To avoid false positives where a consumer chain is unnecessarily removed,vscTimeoutMUST be larger thanconsumerUnbondingPeriodand SHOULD account for the time needed to relay theVSCPacketto the consumer and the correspondingVSCMaturedPacketback to the provider.
[CCV-PCF-CCINIT.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives a
ChanCloseInitmessage on a port the provider CCV module is bounded to.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is always aborted; hence, the state is not changed.
- Error Condition
- None.
[CCV-PCF-CCCONFIRM.1]
- Caller
- The provider IBC routing module.
- Trigger Event
- The provider IBC routing module receives a
ChanCloseConfirmmessage on a port the provider CCV module is bounded to.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- The state is not changed.
- Error Condition
- None.
[CCV-CCF-BBLOCK-CCR.1]
- Caller
- The
BeginBlock()method.
- The
- Trigger Event
- A
BeginBlockmessage is received from the consensus engine;BeginBlockmessages are sent once per block.
- A
- Precondition
- True.
- Postcondition
- If the CCV was established, but then was moved to the
CLOSEDstate, then the state of the consumer CCV module is cleaned up, e.g., theproviderChannelis unset.
- If the CCV was established, but then was moved to the
- Error Condition
- If the CCV was established, but then was moved to the
CLOSEDstate.
- If the CCV was established, but then was moved to the
Note: Once the CCV channel is closed, the provider chain can no longer provider security. As a result, the consumer chain MUST be shut down. For an example of how to do this in practice, see the Cosmos SDK implementation.
[CCV-CCF-CCINIT.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives a
ChanCloseInitmessage on a port the consumer CCV module is bounded to.
- The consumer IBC routing module receives a
- Precondition
- True.
- Postcondition
- If
providerChannelis not set orproviderChannelmatches the ID of the channel theChanCloseInitmessage was received on, then the transaction is aborted. - The state is not changed.
- If
- Error Condition
- None.
[CCV-CCF-CCCONFIRM.1]
- Caller
- The consumer IBC routing module.
- Trigger Event
- The consumer IBC routing module receives a
ChanCloseConfirmmessage on a port the consumer CCV module is bounded to.
- The consumer IBC routing module receives a
- Precondition
- True.
- Postcondition
- The state is not changed.
- Error Condition
- None.
Validator Set Update
↑ Back to Outline The validator set update sub-protocol enables the provider chain- to update the consumer chain on the voting power granted to validators on the provider chain
- and to ensure the correct completion of unbonding operations for validators that produce blocks on the consumer chain.
[CCV-PCF-EBLOCK-VSU.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine;EndBlockmessages are sent once per block.
- An
- Precondition
- True.
- Postcondition
- For every matured unbonding operation in
maturedUnbondingOps, the Staking module is notified that the unbonding can complete. - All unbonding operation in
maturedUnbondingOpsare removed. - A list of validator updates
valUpdatesis obtained from the provider Staking module. - For every consumer chain with
chainId- If either
valUpdatesis not empty or there were unbonding operations initiated during this block, then- a
VSCPacketdatadatais created such thatdata.id = vscId,data.updates = valUpdates, anddata.downtimeSlashAcks = downtimeSlashRequests[chainId]; downtimeSlashRequests[chainId]is emptied;packetDatais appended to the list of pendingVSCPackets associated tochainId, i.e.,pendingVSCPackets[chainId].
- a
- If there is an established CCV channel for the consumer chain with
chainId, then- for each
VSCPacketDatain the list of pending VSCPackets associated tochainId- a packet with the
VSCPacketDatais sent on the channel associated with the consumer chain withchainId; vscSendTimestamps[(vscId, chainId)]is set to the current timestamp;
- a packet with the
- all the pending VSCPackets associated to
chainIdare removed.
- for each
- If either
vscIdis incremented.
- For every matured unbonding operation in
- Error Condition
- None.
[CCV-PCF-ACKVSC.1]
- Caller
- The
onAcknowledgePacket()method.
- The
- Trigger Event
- The provider IBC routing module receives an acknowledgement of a
VSCPacketon a channel owned by the provider CCV module.
- The provider IBC routing module receives an acknowledgement of a
- Precondition
- True.
- Postcondition
- The state is not changed.
- Error Condition
- The acknowledgement is
VSCPacketError.
- The acknowledgement is
[CCV-PCF-TOVSC.1]
- Caller
- The
onTimeoutPacket()method.
- The
- Trigger Event
- A
VSCPacketsent on a channel owned by the provider CCV module timed out as a result of either
- A
- Precondition
- The Correct Relayer assumption is violated (see the Assumptions section).
- Postcondition
- The transaction is aborted if the ID of the channel on which the packet was sent is not mapped to a chain ID (in
channelToChain). StopConsumerChain(chainId, lockUnbondingOnTimeout[chainId])is invoked, wherechainId = channelToChain[packet.getDestinationChannel()].
- The transaction is aborted if the ID of the channel on which the packet was sent is not mapped to a chain ID (in
- Error Condition
- None
[CCV-PCF-RCVMAT.1]
- Caller
- The
onRecvPacket()method.
- The
- Trigger Event
- The provider IBC routing module receives a
VSCMaturedPacketon a channel owned by the provider CCV module.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- The transaction is aborted if the channel on which the packet was received is not an established CCV channel (i.e., not in
channelToChain). chainIdis set to the ID of the consumer chain mapped to the channel on which the packet was received.- For each unbonding operation
opreturned byGetUnbondingsFromVSC(chainId, packet.data.id)chainIdis removed fromop.unbondingChainIds;- if
op.unbondingChainIdsis empty,op.idis added tomaturedUnbondingOps;op.idis removed fromunbondingOps.
(chainId, vscId)is removed fromvscToUnbondingOps.(chainId, vscId)is removed fromvscSendTimestamps.- A successful acknowledgment is returned.
- The transaction is aborted if the channel on which the packet was received is not an established CCV channel (i.e., not in
- Error Condition
- None.
[CCV-PCF-GETUBS.1]
- Caller
- The
onRecvVSCMaturedPacket()method.
- The
- Trigger Event
- The provider IBC routing module receives a
VSCMaturedPacketon a channel owned by the provider CCV module.
- The provider IBC routing module receives a
- Precondition
- The provider CCV module received a
VSCMaturedPacketPfrom a consumer chain with IDchainId, such thatP.data.id == _vscId.
- The provider CCV module received a
- Postcondition
- Return the list of unbonding operations mapped to
(chainId, _vscId).
- Return the list of unbonding operations mapped to
- Error Condition
- None.
[CCV-PCF-HOOK-AFUBOPCR.1]
- Caller
- The Staking module.
- Trigger Event
- An unbonding operation with id
opIdis initiated.
- An unbonding operation with id
- Precondition
- True.
- Postcondition
chainIdsis set to the list of all consumer chains registered with this provider chain, i.e.,chainToClient.Keys().- If there is at least one consumer chain in
chainIds, then- an
UnbondingOperationopis created and added tounbondingOps, such thatop.id = opIdandop.unbondingChainIds = chainIds. opIdis appended to every list invscToUnbondingOps[(chainId, vscId)], wherechainIdis an ID of a consumer chains registered with this provider chain andvscIdis the current VSC ID.- the
PutUnbondingOnHold(opId)of the Staking module is invoked.
- an
- Error Condition
- None.
[CCV-CCF-RCVVSC.1]
- Caller
- The
onRecvPacket()method.
- The
- Trigger Event
- The consumer IBC routing module receives a
VSCPacketon a channel owned by the consumer CCV module.
- The consumer IBC routing module receives a
- Precondition
- True.
- Postcondition
- If
providerChannelis set and does not match the channel (with IDpacket.getDestinationChannel()) on which the packet was received, then an error acknowledgement is returned. - Otherwise,
- the height of the subsequent block is mapped to
packet.data.id(i.e., theHtoVSCmapping) ; packet.datais appended toreceivedVSCs.- a successful acknowledgement is returned.
- the height of the subsequent block is mapped to
- If
- Error Condition
- None.
[CCV-CCF-ACKMAT.1]
- Caller
- The
onAcknowledgePacket()method.
- The
- Trigger Event
- The consumer IBC routing module receives an acknowledgement of a
VSCMaturedPacketon a channel owned by the consumer CCV module.
- The consumer IBC routing module receives an acknowledgement of a
- Precondition
- True.
- Postcondition
- The state is not changed.
- Error Condition
- The acknowledgement is
VSCMaturedPacketError.
- The acknowledgement is
[CCV-CCF-TOMAT.1]
- Caller
- The
onTimeoutPacket()method.
- The
- Trigger Event
- A
VSCMaturedPacketsent on a channel owned by the consumer CCV module timed out as a result of either
- A
- Precondition
- The Correct Relayer assumption is violated (see the Assumptions section).
- Postcondition
- The state is not changed.
- Error Condition
- None
[CCV-CCF-EBLOCK-VSU.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine;EndBlockmessages are sent once per block.
- An
- Precondition
- True.
- Postcondition
- If
providerChannel != "",UnbondMaturePackets()is invoked; - If
preCCV == true, the state is not changed. - Otherwise,
- the data items in
receivedVSCsare handled (see [CCV-CCF-HAREVSC.1]), which results in a listchangesof validator updates; UpdateValidatorSet(changes)is invoked;changesis returned.
- the data items in
- If
- Error Condition
- None.
[CCV-CCF-HAREVSC.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine.
- An
- Precondition
preCCV == false.
- Postcondition
- For each
dataitem in the listreceivedVSCs,data.updatesare appended tochanges, wherechangesis initially an empty list of validator updates;(data.id, maturityTimestamp)is added tomaturingVSCs, wherematurityTimestamp = currentTimestamp() + ConsumerUnbondingPeriod;- for each
valAddrin the slash acknowledgments received from the provider chain,outstandingDowntime[valAddr]is set to false.
receivedVSCsis emptied.- The updates in
changesare aggregated, i.e., only the latest update per validator is kept, and returned.
- For each
- Error Condition
- None.
[CCV-CCF-UPVALS.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine.
- An
- Precondition
preCCV == false.
- Postcondition
- For each validator
updateinchanges,- if the validator is not in the validator set and
update.power > 0, then- a new validator is added to
ccvValidatorSet; - the
AfterCCValidatorBondedhook is called;
- a new validator is added to
- otherwise, if the validator’s new power is
0, then,- the validator is removed from
ccvValidatorSet; - the
AfterCCValidatorBeginUnbondinghook is called;
- the validator is removed from
- otherwise, the validator’s power is updated.
- if the validator is not in the validator set and
- For each validator
- Error Condition
- None.
[CCV-CCF-UMP.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine.
- An
- Precondition
- The CCV channel to the provider chain is established, i.e.,
providerChannel != "".
- The CCV channel to the provider chain is established, i.e.,
- Postcondition
- For each
(id, ts)in the list of maturing VSCs sorted by maturity timestamps- if
currentTimestamp() < ts, the loop is stopped; - a
VSCMaturedPacketDatapacket data is created; - a packet with the created
VSCMaturedPacketDatais sent to the provider chain; - the tuple
(id, ts)is removed frommaturingVSCs.
- if
- For each
- Error Condition
- None.
Consumer Initiated Slashing
↑ Back to Outline[CCV-PCF-EBLOCK-CIS.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine;EndBlockmessages are sent once per block.
- An
- Precondition
- True.
- Postcondition
vscIdis mapped to the height of the subsequent block.
- Error Condition
- None.
[CCV-PCF-RCVSLASH.1]
- Caller
- The
onRecvPacket()method.
- The
- Trigger Event
- The provider IBC routing module receives a
SlashPacketon a channel owned by the provider CCV module.
- The provider IBC routing module receives a
- Precondition
- True.
- Postcondition
- If the channel the packet was received on is not an established CCV channel, then an error acknowledgment is returned.
- Otherwise,
- if
packet.data.vscId == 0,infractionHeightis set toinitialHeights[chainId], withchainId = channelToChain[packet.getDestinationChannel()], i.e., the height when the CCV channel to this consumer chain is established; - otherwise,
infractionHeightis set toVSCtoH[packet.data.vscId], i.e., the height at which the voting power was last updated by the validator updates in the VSC with IDpacket.data.vscId; - a request is made to the Slashing module to slash
slashFactorof the tokens bonded atinfractionHeightby the validator with addresspacket.data.valAddress, whereslashFactoris the slashing factor set on the provider chain; - a request is made to the Slashing module to jail the validator with address
packet.data.valAddressfor a periodjailTime, wherejailTimeis the jailing time set on the provider chain; - if the slash request is for downtime, the validator’s address
packet.data.valAddressis added to the list of downtime slash requests from thischainId; - a successful acknowledgment is returned.
- if
- Error Condition
- None.
[CCV-CCF-BBLOCK-CIS.1]
- Caller
- The
BeginBlock()method.
- The
- Trigger Event
- A
BeginBlockmessage is received from the consensus engine;BeginBlockmessages are sent once per block.
- A
- Precondition
- True.
- Postcondition
HtoVSCfor the subsequent block height is set to the same VSC ID as the current block height.
- Error Condition
- None.
[CCV-CCF-ACKSLASH.1]
- Caller
- The
onAcknowledgePacket()method.
- The
- Trigger Event
- The consumer IBC routing module receives an acknowledgement of a
SlashPacketon a channel owned by the consumer CCV module.
- The consumer IBC routing module receives an acknowledgement of a
- Precondition
- True.
- Postcondition
- The state is not changed.
- Error Condition
- The acknowledgement is
SlashPacketError.
- The acknowledgement is
[CCV-CCF-TOSLASH.1]
- Caller
- The
onTimeoutPacket()method.
- The
- Trigger Event
- A
SlashPacketsent on a channel owned by the consumer CCV module timed out as a result of either
- A
- Precondition
- The Correct Relayer assumption is violated (see the Assumptions section).
- Postcondition
- The state is not changed.
- Error Condition
- None
[CCV-CCF-SNDSLASH.1]
- Caller
- The ABCI application (e.g., the Slashing module).
- Trigger Event
- Evidence of misbehavior for a validator with address
valAddresswas received.
- Evidence of misbehavior for a validator with address
- Precondition
- True.
- Postcondition
- If the request is for downtime and there is an outstanding request to slash this validator for downtime, then the state is not changed.
- Otherwise,
- a
SlashPacketdatapacketDatais created, such thatpacketData.vscId = VSCtoH[infractionHeight]; - if the CCV channel to the provider chain is established, then
- a packet with the
packetDatais sent to the provider chain; - if the request is for downtime,
outstandingDowntime[data.valAddress]is set to true;
- a packet with the
- otherwise
SlashRequest{data: packetData, downtime: downtime}is appended topendingSlashRequests.
- a
- Error Condition
- None.
Note: The ABCI application MUST subtractValidatorUpdateDelayfrom the infraction height before invokingSendSlashRequest, whereValidatorUpdateDelayis a delay (in blocks) between when validator updates are returned to the consensus-engine and when they are applied. For example, ifValidatorUpdateDelay = xand a validator set update is returned with new validators at the end of block10, then the new validators are expected to sign blocks beginning at block11+x(for more details, take a look at the ABCI specification). Consequently, the consumer CCV module expects theinfractionHeightparameter of theSendSlashRequest()to be set accordingly. Note: In the context of single-chain validation, slashing for downtime is an atomic operation, i.e., once the downtime is detected, the misbehaving validator is slashed and jailed immediately. Consequently, once a validator is punished for downtime, it is removed from the validator set and cannot be punished again for downtime. Since validators are not automatically added back to the validator set, it entails that the validator is aware of the punishment before it can rejoin and be potentially punished again. In the context of CCV, slashing for downtime is no longer atomic, i.e., downtime is detected on the consumer chain, but the jailing happens on the provider chain. To avoid sending multiple slash requests for the same downtime infraction, the consumer CCV module uses anoutstandingDowntimeflag per validator. CCV assumes that the consumer ABCI application (e.g., the slashing module) is not including the downtime of a validator withoutstandingDowntime == TRUEin the evidence for downtime.
[CCV-CCF-SNDPESLASH.1]
- Caller
- The
onRecvVSCPacket()method (see CCV-CCF-RCVVSC.1).
- The
- Trigger Event
- The first
VSCPacketis received from the provider chain.
- The first
- Precondition
providerChannel != "".
- Postcondition
- For each slash request
reqinpendingSlashRequestsin reverse order, such that either the slash request is not for downtime or there is no outstanding slash request for downtime,- a packet with the data
req.datais sent to the provider chain; - if the request is for downtime,
outstandingDowntime[req.data.valAddress]is set to true.
- a packet with the data
- All the pending
SlashRequests are removed.
- For each slash request
- Error Condition
- None.
Note: Iterating over pending SlashRequests in reverse order ensures that validators that are down for multiple blocks during channel initialization will be slashed for the latest downtime evidence.
Reward Distribution
↑ Back to Outline[CCV-CCF-EBLOCK-RD.1]
- Caller
- The
EndBlock()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine;EndBlockmessages are sent once per block.
- An
- Precondition
- True.
- Postcondition
- If
getCurrentHeight() - lastDistributionTransferHeight >= BlocksPerDistributionTransfer, theDistributeRewards()method is invoked.
- If
- Error Condition
- None.
[CCV-CCF-DISTRREW.1]
- Caller
- The
EndBlockRD()method.
- The
- Trigger Event
- An
EndBlockmessage is received from the consensus engine.
- An
- Precondition
getCurrentHeight() - lastDistributionTransferHeight >= BlocksPerDistributionTransfer
- Postcondition
- For each token type defined as a pair
(denomination, amount)inccvAccount, a transfer token (as defined in ICS 20) is initiated. lastDistributionTransferHeightis set to the current height.
- For each token type defined as a pair
- Error Condition
- None.