Skip to content

Commit 0e45e6b

Browse files
committed
Rename views to author_view and finalized_view
author_view: view when the block was created. finalized_view: view when the block was finalized.
1 parent 5062e37 commit 0e45e6b

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

core/src/consensus/tendermint/types.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,17 @@ impl<'a> TendermintSealView<'a> {
224224
}
225225
}
226226

227-
pub fn previous_block_view(&self) -> Result<u64, DecoderError> {
227+
/// The parent block is finalized at this view.
228+
/// Signatures in the seal field is signed for this view.
229+
pub fn parent_block_finalized_view(&self) -> Result<u64, DecoderError> {
228230
let view_rlp =
229231
self.seal.get(0).expect("block went through verify_block_basic; block has .seal_fields() fields; qed");
230232
UntrustedRlp::new(view_rlp.as_slice()).as_val()
231233
}
232234

233-
pub fn consensus_view(&self) -> Result<u64, DecoderError> {
235+
/// Block is created at auth_view.
236+
/// Block verifier use other_view to verify the author
237+
pub fn author_view(&self) -> Result<u64, DecoderError> {
234238
let view_rlp =
235239
self.seal.get(1).expect("block went through verify_block_basic; block has .seal_fields() fields; qed");
236240
UntrustedRlp::new(view_rlp.as_slice()).as_val()

core/src/consensus/tendermint/worker.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,9 @@ impl Worker {
928928

929929
let height = proposal.number() as Height;
930930
let seal_view = TendermintSealView::new(proposal.seal());
931-
let prev_block_view = seal_view.previous_block_view().expect("The proposal is verified");
931+
let parent_block_finalized_view = seal_view.parent_block_finalized_view().expect("The proposal is verified");
932932
let on = VoteOn {
933-
step: VoteStep::new(height - 1, prev_block_view, Step::Precommit),
933+
step: VoteStep::new(height - 1, parent_block_finalized_view, Step::Precommit),
934934
block_hash: Some(*proposal.parent_hash()),
935935
};
936936
for (index, signature) in seal_view.signatures().expect("The proposal is verified") {
@@ -990,7 +990,7 @@ impl Worker {
990990
};
991991
} else if current_height < height {
992992
let finalized_view_of_previous_height =
993-
TendermintSealView::new(proposal.seal()).previous_block_view().unwrap();
993+
TendermintSealView::new(proposal.seal()).parent_block_finalized_view().unwrap();
994994

995995
self.jump_to_height(height, finalized_view_of_previous_height);
996996

@@ -1095,16 +1095,15 @@ impl Worker {
10951095
fn proposal_generated(&mut self, sealed_block: &SealedBlock) {
10961096
let proposal_height = sealed_block.header().number();
10971097
let proposal_seal = sealed_block.header().seal();
1098-
let proposal_view = TendermintSealView::new(proposal_seal)
1099-
.consensus_view()
1100-
.expect("Generated proposal should have a valid seal");
1098+
let proposal_author_view =
1099+
TendermintSealView::new(proposal_seal).author_view().expect("Generated proposal should have a valid seal");
11011100
assert!(proposal_height <= self.height, "A proposal cannot be generated on the future height");
1102-
if proposal_height < self.height || (proposal_height == self.height && proposal_view != self.view) {
1101+
if proposal_height < self.height || (proposal_height == self.height && proposal_author_view != self.view) {
11031102
ctrace!(
11041103
ENGINE,
11051104
"Proposal is generated on the height {} and view {}. Current height is {} and view is {}",
11061105
proposal_height,
1107-
proposal_view,
1106+
proposal_author_view,
11081107
self.height,
11091108
self.view,
11101109
);
@@ -1131,7 +1130,7 @@ impl Worker {
11311130
);
11321131
return
11331132
}
1134-
debug_assert_eq!(Ok(self.view), TendermintSealView::new(header.seal()).consensus_view());
1133+
debug_assert_eq!(Ok(self.view), TendermintSealView::new(header.seal()).author_view());
11351134

11361135
self.vote_on_header_for_proposal(&header).expect("I'm a proposer");
11371136

@@ -1152,8 +1151,8 @@ impl Worker {
11521151
}
11531152

11541153
let height = header.number();
1155-
let view = TendermintSealView::new(header.seal()).consensus_view().unwrap();
1156-
let score = calculate_score(height, view);
1154+
let author_view = TendermintSealView::new(header.seal()).author_view().unwrap();
1155+
let score = calculate_score(height, author_view);
11571156

11581157
if *header.score() != score {
11591158
return Err(BlockError::InvalidScore(Mismatch {
@@ -1168,13 +1167,13 @@ impl Worker {
11681167

11691168
fn verify_block_external(&self, header: &Header) -> Result<(), Error> {
11701169
let height = header.number() as usize;
1171-
let view = TendermintSealView::new(header.seal()).consensus_view()?;
1172-
ctrace!(ENGINE, "Verify external at {}-{}, {:?}", height, view, header);
1170+
let author_view = TendermintSealView::new(header.seal()).author_view()?;
1171+
ctrace!(ENGINE, "Verify external at {}-{}, {:?}", height, author_view, header);
11731172
let proposer = header.author();
11741173
if !self.is_authority(header.parent_hash(), proposer) {
11751174
return Err(EngineError::BlockNotAuthorized(*proposer).into())
11761175
}
1177-
self.check_view_proposer(header.parent_hash(), header.number(), view, &proposer)?;
1176+
self.check_view_proposer(header.parent_hash(), header.number(), author_view, &proposer)?;
11781177
let seal_view = TendermintSealView::new(header.seal());
11791178
let bitset_count = seal_view.bitset()?.count();
11801179
let precommits_count = seal_view.precommits().item_count()?;
@@ -1197,9 +1196,9 @@ impl Worker {
11971196
return Err(BlockError::InvalidSeal.into())
11981197
}
11991198

1200-
let previous_block_view = TendermintSealView::new(header.seal()).previous_block_view()?;
1199+
let parent_block_finalized_view = TendermintSealView::new(header.seal()).parent_block_finalized_view()?;
12011200
let precommit_vote_on = VoteOn {
1202-
step: VoteStep::new(header.number() - 1, previous_block_view, Step::Precommit),
1201+
step: VoteStep::new(header.number() - 1, parent_block_finalized_view, Step::Precommit),
12031202
block_hash: Some(*header.parent_hash()),
12041203
};
12051204

@@ -1642,7 +1641,7 @@ impl Worker {
16421641
if self.height < header.number() {
16431642
cinfo!(ENGINE, "Received a commit: {:?}.", header.number());
16441643
let finalized_view_of_previous_height = TendermintSealView::new(full_header.seal())
1645-
.previous_block_view()
1644+
.parent_block_finalized_view()
16461645
.expect("Imported block already checked");
16471646
self.jump_to_height(header.number(), finalized_view_of_previous_height);
16481647
}
@@ -1791,15 +1790,14 @@ impl Worker {
17911790
// The proposer re-proposed its locked proposal.
17921791
// If we already imported the proposal, we should set `proposal` here.
17931792
if c.block(&BlockId::Hash(header_view.hash())).is_some() {
1794-
let generated_view = TendermintSealView::new(header_view.seal())
1795-
.consensus_view()
1796-
.expect("Imported block is verified");
1793+
let author_view =
1794+
TendermintSealView::new(header_view.seal()).author_view().expect("Imported block is verified");
17971795
cdebug!(
17981796
ENGINE,
17991797
"Received a proposal({}) by a locked proposer. current view: {}, original proposal's view: {}",
18001798
header_view.hash(),
18011799
proposed_view,
1802-
generated_view
1800+
author_view
18031801
);
18041802
self.proposal = Proposal::new_imported(header_view.hash());
18051803
} else {
@@ -1975,13 +1973,14 @@ impl Worker {
19751973
let block = self.client().block(&height.into()).expect("Parent block should exist");
19761974
let block_hash = block.hash();
19771975
let seal = block.seal();
1978-
let view = TendermintSealView::new(&seal).consensus_view().expect("Block is already verified and imported");
1976+
let author_view =
1977+
TendermintSealView::new(&seal).author_view().expect("Block is already verified and imported");
19791978

19801979
let votes = self
19811980
.votes
19821981
.get_all_votes_in_round(&VoteStep {
19831982
height,
1984-
view,
1983+
view: author_view,
19851984
step: Step::Precommit,
19861985
})
19871986
.into_iter()
@@ -1994,9 +1993,10 @@ impl Worker {
19941993
let child_block = self.client().block(&(height + 1).into()).expect("Parent block should exist");
19951994
let child_block_header_seal = child_block.header().seal();
19961995
let child_block_seal_view = TendermintSealView::new(&child_block_header_seal);
1997-
let view = child_block_seal_view.previous_block_view().expect("Verified block");
1996+
let parent_block_finalized_view =
1997+
child_block_seal_view.parent_block_finalized_view().expect("Verified block");
19981998
let on = VoteOn {
1999-
step: VoteStep::new(height, view, Step::Precommit),
1999+
step: VoteStep::new(height, parent_block_finalized_view, Step::Precommit),
20002000
block_hash: Some(block.hash()),
20012001
};
20022002
let mut votes = Vec::new();

0 commit comments

Comments
 (0)