Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions crates/iota-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2859,15 +2859,8 @@ impl AuthorityPerEpochStore {
let mut checkpoint_roots: Vec<TransactionKey> = Vec::with_capacity(roots.len() + 1);

if let Some(consensus_commit_prologue_root) = consensus_commit_prologue_root {
if self
.protocol_config()
.prepend_prologue_tx_in_consensus_commit_in_checkpoints()
{
// Put consensus commit prologue root at the beginning of the checkpoint roots.
checkpoint_roots.push(consensus_commit_prologue_root);
} else {
roots.insert(consensus_commit_prologue_root);
}
// Put consensus commit prologue root at the beginning of the checkpoint roots.
checkpoint_roots.push(consensus_commit_prologue_root);
}
checkpoint_roots.extend(roots.into_iter());
let pending_checkpoint = PendingCheckpointV2::V2(PendingCheckpointV2Contents {
Expand Down Expand Up @@ -2992,11 +2985,8 @@ impl AuthorityPerEpochStore {
}
);

let transaction = consensus_commit_info.create_consensus_commit_prologue_transaction(
self.epoch(),
self.protocol_config(),
version_assignment,
);
let transaction = consensus_commit_info
.create_consensus_commit_prologue_transaction(self.epoch(), version_assignment);
let consensus_commit_prologue_root = match self
.process_consensus_system_transaction(&transaction)
{
Expand Down
47 changes: 9 additions & 38 deletions crates/iota-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,19 +1092,15 @@ impl CheckpointBuilder {

let _scope = monitored_scope("CheckpointBuilder");

let consensus_commit_prologue = if self
.epoch_store
.protocol_config()
.prepend_prologue_tx_in_consensus_commit_in_checkpoints()
{
let consensus_commit_prologue = {
// If the roots contains consensus commit prologue transaction, we want to
// extract it, and put it to the front of the checkpoint.

let consensus_commit_prologue = self
.extract_consensus_commit_prologue(&root_digests, &root_effects)
.await?;

// Get the unincluded depdnencies of the consensus commit prologue. We should
// Get the un-included dependencies of the consensus commit prologue. We should
// expect no other dependencies that haven't been included in any
// previous checkpoints.
if let Some((ccp_digest, ccp_effects)) = &consensus_commit_prologue {
Expand All @@ -1119,8 +1115,6 @@ impl CheckpointBuilder {
assert_eq!(unsorted_ccp[0].transaction_digest(), ccp_digest);
}
consensus_commit_prologue
} else {
None
};

let unsorted =
Expand Down Expand Up @@ -1152,8 +1146,6 @@ impl CheckpointBuilder {

// This function is used to extract the consensus commit prologue digest and
// effects from the root transactions.
// This function can only be used when
// prepend_prologue_tx_in_consensus_commit_in_checkpoints is enabled.
// The consensus commit prologue is expected to be the first transaction in the
// roots.
async fn extract_consensus_commit_prologue(
Expand All @@ -1168,8 +1160,7 @@ impl CheckpointBuilder {

// Reads the first transaction in the roots, and checks whether it is a
// consensus commit prologue transaction.
// When prepend_prologue_tx_in_consensus_commit_in_checkpoints is enabled, the
// consensus commit prologue transaction should be the first transaction
// The consensus commit prologue transaction should be the first transaction
// in the roots written by the consensus handler.
let first_tx = self
.state
Expand All @@ -1178,9 +1169,7 @@ impl CheckpointBuilder {
.expect("Transaction block must exist");

Ok(match first_tx.transaction_data().kind() {
TransactionKind::ConsensusCommitPrologue(_)
| TransactionKind::ConsensusCommitPrologueV2(_)
| TransactionKind::ConsensusCommitPrologueV3(_) => {
TransactionKind::ConsensusCommitPrologueV1(_) => {
assert_eq!(first_tx.digest(), root_effects[0].transaction_digest());
Some((*first_tx.digest(), root_effects[0].clone()))
}
Expand Down Expand Up @@ -1386,9 +1375,7 @@ impl CheckpointBuilder {
let (transaction, size) = transaction_and_size
.unwrap_or_else(|| panic!("Could not find executed transaction {:?}", effects));
match transaction.inner().transaction_data().kind() {
TransactionKind::ConsensusCommitPrologue(_)
| TransactionKind::ConsensusCommitPrologueV2(_)
| TransactionKind::ConsensusCommitPrologueV3(_)
TransactionKind::ConsensusCommitPrologueV1(_)
| TransactionKind::AuthenticatorStateUpdate(_) => {
// ConsensusCommitPrologue and AuthenticatorStateUpdate
// are guaranteed to be
Expand Down Expand Up @@ -1712,14 +1699,6 @@ impl CheckpointBuilder {
root_digests: &[TransactionDigest],
sorted: &[TransactionEffects],
) {
if !self
.epoch_store
.protocol_config()
.prepend_prologue_tx_in_consensus_commit_in_checkpoints()
{
return;
}

// Gets all the consensus commit prologue transactions from the roots.
let root_txs = self
.state
Expand All @@ -1732,9 +1711,7 @@ impl CheckpointBuilder {
if let Some(tx) = tx {
if matches!(
tx.transaction_data().kind(),
TransactionKind::ConsensusCommitPrologue(_)
| TransactionKind::ConsensusCommitPrologueV2(_)
| TransactionKind::ConsensusCommitPrologueV3(_)
TransactionKind::ConsensusCommitPrologueV1(_)
) {
Some(tx)
} else {
Expand Down Expand Up @@ -1770,9 +1747,7 @@ impl CheckpointBuilder {
if let Some(tx) = tx {
assert!(!matches!(
tx.transaction_data().kind(),
TransactionKind::ConsensusCommitPrologue(_)
| TransactionKind::ConsensusCommitPrologueV2(_)
| TransactionKind::ConsensusCommitPrologueV3(_)
TransactionKind::ConsensusCommitPrologueV1(_)
));
}
}
Expand All @@ -1781,9 +1756,7 @@ impl CheckpointBuilder {
// checkpoint.
assert!(matches!(
txs[0].as_ref().unwrap().transaction_data().kind(),
TransactionKind::ConsensusCommitPrologue(_)
| TransactionKind::ConsensusCommitPrologueV2(_)
| TransactionKind::ConsensusCommitPrologueV3(_)
TransactionKind::ConsensusCommitPrologueV1(_)
));

assert_eq!(ccps[0].digest(), txs[0].as_ref().unwrap().digest());
Expand All @@ -1792,9 +1765,7 @@ impl CheckpointBuilder {
if let Some(tx) = tx {
assert!(!matches!(
tx.transaction_data().kind(),
TransactionKind::ConsensusCommitPrologue(_)
| TransactionKind::ConsensusCommitPrologueV2(_)
| TransactionKind::ConsensusCommitPrologueV3(_)
TransactionKind::ConsensusCommitPrologueV1(_)
));
}
}
Expand Down
32 changes: 3 additions & 29 deletions crates/iota-core/src/consensus_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,31 +817,12 @@ impl ConsensusCommitInfo {
self.skip_consensus_commit_prologue_in_test
}

fn consensus_commit_prologue_transaction(&self, epoch: u64) -> VerifiedExecutableTransaction {
let transaction =
VerifiedTransaction::new_consensus_commit_prologue(epoch, self.round, self.timestamp);
VerifiedExecutableTransaction::new_system(transaction, epoch)
}

fn consensus_commit_prologue_v2_transaction(
&self,
epoch: u64,
) -> VerifiedExecutableTransaction {
let transaction = VerifiedTransaction::new_consensus_commit_prologue_v2(
epoch,
self.round,
self.timestamp,
self.consensus_commit_digest,
);
VerifiedExecutableTransaction::new_system(transaction, epoch)
}

fn consensus_commit_prologue_v3_transaction(
fn consensus_commit_prologue_v1_transaction(
&self,
epoch: u64,
cancelled_txn_version_assignment: Vec<(TransactionDigest, Vec<(ObjectID, SequenceNumber)>)>,
) -> VerifiedExecutableTransaction {
let transaction = VerifiedTransaction::new_consensus_commit_prologue_v3(
let transaction = VerifiedTransaction::new_consensus_commit_prologue_v1(
epoch,
self.round,
self.timestamp,
Expand All @@ -854,16 +835,9 @@ impl ConsensusCommitInfo {
pub fn create_consensus_commit_prologue_transaction(
&self,
epoch: u64,
protocol_config: &ProtocolConfig,
cancelled_txn_version_assignment: Vec<(TransactionDigest, Vec<(ObjectID, SequenceNumber)>)>,
) -> VerifiedExecutableTransaction {
if protocol_config.record_consensus_determined_version_assignments_in_prologue() {
self.consensus_commit_prologue_v3_transaction(epoch, cancelled_txn_version_assignment)
} else if protocol_config.include_consensus_digest_in_prologue() {
self.consensus_commit_prologue_v2_transaction(epoch)
} else {
self.consensus_commit_prologue_transaction(epoch)
}
self.consensus_commit_prologue_v1_transaction(epoch, cancelled_txn_version_assignment)
}
}

Expand Down
18 changes: 5 additions & 13 deletions crates/iota-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4805,14 +4805,6 @@ async fn test_consensus_commit_prologue_generation() {
let processed_consensus_transactions =
send_batch_consensus_no_execution(&authority_state, &certificates, false).await;

// Consensus commit prologue V2 should be turned on everywhere.
assert!(
authority_state
.epoch_store_for_testing()
.protocol_config()
.include_consensus_digest_in_prologue()
);

// Tests that new consensus commit prologue transaction is added to the batch,
// and it is the first transaction.
assert_eq!(processed_consensus_transactions.len(), 3);
Expand All @@ -4821,7 +4813,7 @@ async fn test_consensus_commit_prologue_generation() {
.data()
.transaction_data()
.kind(),
TransactionKind::ConsensusCommitPrologueV3(..)
TransactionKind::ConsensusCommitPrologueV1(..)
));

// Tests that the system clock object is updated by the new consensus commit
Expand Down Expand Up @@ -6173,15 +6165,15 @@ async fn test_consensus_handler_congestion_control_transaction_cancellation() {
// transaction, and it must be the first one.
assert!(matches!(
scheduled_txns[0].data().transaction_data().kind(),
TransactionKind::ConsensusCommitPrologueV3(..)
TransactionKind::ConsensusCommitPrologueV1(..)
));
assert!(scheduled_txns[1].data().transaction_data().gas_price() == 2000);

let scheduled_txns = send_batch_consensus_no_execution(&authority, &[], false).await;
assert_eq!(scheduled_txns.len(), 2);
assert!(matches!(
scheduled_txns[0].data().transaction_data().kind(),
TransactionKind::ConsensusCommitPrologueV3(..)
TransactionKind::ConsensusCommitPrologueV1(..)
));
assert!(scheduled_txns[1].data().transaction_data().gas_price() == 2000);

Expand Down Expand Up @@ -6246,7 +6238,7 @@ async fn test_consensus_handler_congestion_control_transaction_cancellation() {

// Consensus commit prologue contains cancelled txn shared object version
// assignment.
if let TransactionKind::ConsensusCommitPrologueV3(prologue_txn) =
if let TransactionKind::ConsensusCommitPrologueV1(prologue_txn) =
scheduled_txns[0].data().transaction_data().kind()
{
assert!(matches!(
Expand All @@ -6261,7 +6253,7 @@ async fn test_consensus_handler_congestion_control_transaction_cancellation() {
)]
));
} else {
panic!("First scheduled transaction must be a ConsensusCommitPrologueV3 transaction.");
panic!("First scheduled transaction must be a ConsensusCommitPrologueV1 transaction.");
}
}

Expand Down
44 changes: 11 additions & 33 deletions crates/iota-core/src/unit_tests/transaction_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ macro_rules! assert_matches {

use fastcrypto::traits::AggregateAuthenticator;
use iota_types::{
digests::ConsensusCommitDigest,
messages_consensus::{
ConsensusCommitPrologue, ConsensusCommitPrologueV2, ConsensusCommitPrologueV3,
},
digests::ConsensusCommitDigest, messages_consensus::ConsensusCommitPrologueV1,
programmable_transaction_builder::ProgrammableTransactionBuilder,
};

Expand Down Expand Up @@ -214,34 +211,9 @@ async fn test_user_sends_genesis_transaction() {
}

#[tokio::test]
async fn test_user_sends_consensus_commit_prologue() {
test_user_sends_system_transaction_impl(TransactionKind::ConsensusCommitPrologue(
ConsensusCommitPrologue {
epoch: 0,
round: 0,
commit_timestamp_ms: 42,
},
))
.await;
}

#[tokio::test]
async fn test_user_sends_consensus_commit_prologue_v2() {
test_user_sends_system_transaction_impl(TransactionKind::ConsensusCommitPrologueV2(
ConsensusCommitPrologueV2 {
epoch: 0,
round: 0,
commit_timestamp_ms: 42,
consensus_commit_digest: ConsensusCommitDigest::default(),
},
))
.await;
}

#[tokio::test]
async fn test_user_sends_consensus_commit_prologue_v3() {
test_user_sends_system_transaction_impl(TransactionKind::ConsensusCommitPrologueV3(
ConsensusCommitPrologueV3 {
async fn test_user_sends_consensus_commit_prologue_v1() {
test_user_sends_system_transaction_impl(TransactionKind::ConsensusCommitPrologueV1(
ConsensusCommitPrologueV1 {
epoch: 0,
round: 0,
sub_dag_index: None,
Expand Down Expand Up @@ -1576,7 +1548,13 @@ async fn test_handle_certificate_errors() {

let committee = epoch_store.committee().deref().clone();

let tx = VerifiedTransaction::new_consensus_commit_prologue(0, 0, 42);
let tx = VerifiedTransaction::new_consensus_commit_prologue_v1(
0,
0,
42,
ConsensusCommitDigest::default(),
Vec::new(),
);
let ct = CertifiedTransaction::new(
tx.data().clone(),
vec![signed_transaction.auth_sig().clone()],
Expand Down
26 changes: 3 additions & 23 deletions crates/iota-core/tests/staged/iota.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,7 @@ CongestedObjects:
ConsensusCommitDigest:
NEWTYPESTRUCT:
TYPENAME: Digest
ConsensusCommitPrologue:
STRUCT:
- epoch: U64
- round: U64
- commit_timestamp_ms: U64
ConsensusCommitPrologueV2:
STRUCT:
- epoch: U64
- round: U64
- commit_timestamp_ms: U64
- consensus_commit_digest:
TYPENAME: ConsensusCommitDigest
ConsensusCommitPrologueV3:
ConsensusCommitPrologueV1:
STRUCT:
- epoch: U64
- round: U64
Expand Down Expand Up @@ -1023,9 +1011,9 @@ TransactionKind:
NEWTYPE:
TYPENAME: GenesisTransaction
3:
ConsensusCommitPrologue:
ConsensusCommitPrologueV1:
NEWTYPE:
TYPENAME: ConsensusCommitPrologue
TYPENAME: ConsensusCommitPrologueV1
4:
AuthenticatorStateUpdate:
NEWTYPE:
Expand All @@ -1039,14 +1027,6 @@ TransactionKind:
RandomnessStateUpdate:
NEWTYPE:
TYPENAME: RandomnessStateUpdate
7:
ConsensusCommitPrologueV2:
NEWTYPE:
TYPENAME: ConsensusCommitPrologueV2
8:
ConsensusCommitPrologueV3:
NEWTYPE:
TYPENAME: ConsensusCommitPrologueV3
TypeArgumentError:
ENUM:
0:
Expand Down
Loading
Loading