Repository: MystenLabs/sui
File: crates/sui-core/src/consensus_handler.rs (Rust)

Code before:
            assigned_versions.0[0].0 = TransactionKey::Digest(*consensus_commit_prologue.digest());
            schedulables[0] = Schedulable::Transaction(consensus_commit_prologue);
        }

        self.epoch_store
            .process_user_signatures(schedulables.iter().chain(randomness_schedulables.iter()));

        (schedulables, randomness_schedulables, assigned_versions)
    }

    // Adds the consensus commit prologue transaction to the beginning of input `transactions` to update
    // the system clock used in all transactions in the current consensus commit.
    // Returns the root of the consensus commit prologue transaction if it was added to the input.
    fn add_consensus_commit_prologue_transaction<'a>(
        &'a self,
        state: &'a mut CommitHandlerState,
        commit_info: &'a ConsensusCommitInfo,
        assigned_versions: &AssignedTxAndVersions,
    ) -> Option<VerifiedExecutableTransaction> {
        {
            if commit_info.skip_consensus_commit_prologue_in_test {
                return None;
            }
        }

        let mut version_assignment = Vec::new();

        let protocol_config = self.epoch_store.protocol_config();

        for (txn_key, assigned_versions) in assigned_versions.0.iter() {
            let Some(d) = txn_key.as_digest() else {
                continue;
            };

            if !protocol_config.include_cancelled_randomness_txns_in_prologue()
                && assigned_versions
                    .shared_object_versions
                    .iter()
                    .any(|((id, _), _)| *id == SUI_RANDOMNESS_STATE_OBJECT_ID)
            {
                continue;
            }

            if assigned_versions
                .shared_object_versions
                .iter()
                .any(|(_, version)| version.is_cancelled())
            {
                assert_reachable!("cancelled transactions");
                version_assignment.push((*d, assigned_versions.shared_object_versions.clone()));
            }

Review comment (suggestion):
`create_consensus_commit_prologue_transaction` names this `cancelled_txn_version_assignment` which makes this section easier to reason about.

Code after:
            self.add_consensus_commit_prologue_transaction(state, commit_info, &assigned_versions);

        let mut schedulables = schedulables;
        let mut assigned_versions = assigned_versions;
        if let Some(consensus_commit_prologue) = consensus_commit_prologue {
            assert!(matches!(
                schedulables[0],
                Schedulable::ConsensusCommitPrologue(..)
            ));
            assert!(matches!(
                assigned_versions.0[0].0,
                TransactionKey::ConsensusCommitPrologue(..)
            ));
            assigned_versions.0[0].0 = TransactionKey::Digest(*consensus_commit_prologue.digest());
            schedulables[0] = Schedulable::Transaction(consensus_commit_prologue);
        }

        self.epoch_store
            .process_user_signatures(schedulables.iter().chain(randomness_schedulables.iter()));

        (schedulables, randomness_schedulables, assigned_versions)
    }

    // Adds the consensus commit prologue transaction to the beginning of input `transactions` to update
    // the system clock used in all transactions in the current consensus commit.
    // Returns the root of the consensus commit prologue transaction if it was added to the input.
    fn add_consensus_commit_prologue_transaction<'a>(
        &'a self,
        state: &'a mut CommitHandlerState,
        commit_info: &'a ConsensusCommitInfo,
        assigned_versions: &AssignedTxAndVersions,
    ) -> Option<VerifiedExecutableTransaction> {
        {
            if commit_info.skip_consensus_commit_prologue_in_test {
                return None;
            }
        }

        let mut cancelled_txn_version_assignment = Vec::new();

        let protocol_config = self.epoch_store.protocol_config();

        for (txn_key, assigned_versions) in assigned_versions.0.iter() {
            let Some(d) = txn_key.as_digest() else {
                continue;
            };

            if !protocol_config.include_cancelled_randomness_txns_in_prologue()
                && assigned_versions
                    .shared_object_versions
                    .iter()