Skip to content

Commit d31e52c

Browse files
fakedev9999junha1
authored andcommitted
Remove redundancy checking commit sequence phase
1 parent c968b42 commit d31e52c

File tree

1 file changed

+14
-54
lines changed

1 file changed

+14
-54
lines changed

repository/src/lib.rs

+14-54
Original file line numberDiff line numberDiff line change
@@ -593,27 +593,24 @@ impl<T: RawRepository> DistributedRepository<T> {
593593
.map_err(|e| eyre!("verification error on commit {}: {}", hash, e))?;
594594
}
595595

596-
// Check whether the commit sequence is in the transaction phase.
596+
// Create agenda commit
597597
let mut transactions = Vec::new();
598-
599598
for (commit, _) in commits {
600599
if let Commit::Transaction(t) = commit {
601600
transactions.push(t.clone());
602-
} else {
603-
return Err(eyre!(
604-
"branch {} is not in the transaction phase",
605-
WORK_BRANCH_NAME
606-
));
607601
}
608602
}
609-
610603
let agenda = Agenda {
611604
author,
612605
timestamp: get_timestamp(),
613606
transactions_hash: Agenda::calculate_transactions_hash(&transactions),
614607
height: last_header.height + 1,
615608
};
616609
let agenda_commit = Commit::Agenda(agenda.clone());
610+
verifier.apply_commit(&agenda_commit).map_err(|_| {
611+
eyre!("agenda commit cannot be created on top of the current commit sequence")
612+
})?;
613+
617614
let semantic_commit = to_semantic_commit(&agenda_commit, reserved_state)?;
618615

619616
self.raw.checkout_clean().await?;
@@ -697,37 +694,6 @@ impl<T: RawRepository> DistributedRepository<T> {
697694
.map_err(|e| eyre!("verification error on commit {}: {}", hash, e))?;
698695
}
699696

700-
// Check whether the commit sequence is in the agenda proof phase or
701-
// extra-agenda transaction phase.
702-
// TODO: WHAT THE FUCK ARE YOU DOING HERE???
703-
let (last_commit, _) = commits
704-
.last()
705-
.ok_or_else(|| eyre!("branch doesn't contain any commit"))?
706-
.clone();
707-
match last_commit {
708-
Commit::AgendaProof(_) => (),
709-
Commit::ExtraAgendaTransaction(_) => (),
710-
x => return Err(eyre!("a block can't be made on top of a commit {:?}", x)),
711-
}
712-
713-
let mut transactions = Vec::new();
714-
715-
for (commit, _) in commits.clone() {
716-
match commit {
717-
Commit::Transaction(t) => transactions.push(t.clone()),
718-
Commit::Agenda(_) => {}
719-
Commit::AgendaProof(_) => {}
720-
Commit::ExtraAgendaTransaction(_) => {}
721-
Commit::ChatLog(_) => {}
722-
_ => {
723-
return Err(eyre!(
724-
"branch {} is not in the agenda proof phase or extra-agenda transaction phase",
725-
WORK_BRANCH_NAME
726-
))
727-
}
728-
}
729-
}
730-
731697
// Verify `finalization_proof`
732698
let fp_commit_hash = self.raw.locate_branch(FP_BRANCH_NAME.into()).await?;
733699
let fp_semantic_commit = self.raw.read_semantic_commit(fp_commit_hash).await?;
@@ -751,6 +717,10 @@ impl<T: RawRepository> DistributedRepository<T> {
751717
version: SIMPERBY_CORE_PROTOCOL_VERSION.to_string(),
752718
};
753719
let block_commit = Commit::Block(block_header.clone());
720+
verifier.apply_commit(&block_commit).map_err(|_| {
721+
eyre!("block commit cannot be created on top of the current commit sequence")
722+
})?;
723+
754724
let semantic_commit = to_semantic_commit(&block_commit, reserved_state)?;
755725

756726
self.raw.checkout_clean().await?;
@@ -797,22 +767,12 @@ impl<T: RawRepository> DistributedRepository<T> {
797767
.map_err(|e| eyre!("verification error on commit {}: {}", hash, e))?;
798768
}
799769

800-
// Check whether the commit sequence is in agenda proof phase or extra-agenda transaction phase
801-
let (last_commit, _) = commits
802-
.last()
803-
.ok_or_else(|| eyre!("work branch does not contain any commit"))?;
804-
match last_commit {
805-
Commit::AgendaProof(_) => {}
806-
Commit::ExtraAgendaTransaction(_) => {}
807-
x => {
808-
return Err(eyre!(
809-
"an extra-agenda transaction commit cannot be created on top of a commit of type {:?}",
810-
x
811-
))
812-
}
813-
}
814-
815770
let extra_agenda_tx_commit = Commit::ExtraAgendaTransaction(transaction.clone());
771+
verifier.apply_commit(&extra_agenda_tx_commit).map_err(|_| {
772+
eyre!(
773+
"extra-agenda transaction commit cannot be created on top of the current commit sequence"
774+
)
775+
})?;
816776

817777
let semantic_commit = to_semantic_commit(&extra_agenda_tx_commit, reserved_state)?;
818778

0 commit comments

Comments
 (0)