Skip to content

Commit 17f983b

Browse files
committed
Do not wait when empty block is proposed
We don't need to wait additional times because in case an empty block is generated. Because the nodes should wait fixed timeout in the next proposal step.
1 parent 6b13d96 commit 17f983b

File tree

4 files changed

+6
-103
lines changed

4 files changed

+6
-103
lines changed

core/src/consensus/tendermint/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ use crate::ChainNotify;
4545

4646
/// Timer token representing the consensus step timeouts.
4747
const ENGINE_TIMEOUT_TOKEN_NONCE_BASE: TimerToken = 23;
48-
/// Timer token for empty proposal blocks.
49-
const ENGINE_TIMEOUT_EMPTY_PROPOSAL: TimerToken = 22;
5048
/// Timer token for broadcasting step state.
5149
const ENGINE_TIMEOUT_BROADCAST_STEP_STATE: TimerToken = 21;
52-
5350
/// Unit: second
5451
const ENGINE_TIMEOUT_BROADCAT_STEP_STATE_INTERVAL: u64 = 1;
5552

core/src/consensus/tendermint/network.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ use super::worker;
3838
use crate::consensus::EngineError;
3939

4040
use super::{
41-
ENGINE_TIMEOUT_BROADCAST_STEP_STATE, ENGINE_TIMEOUT_BROADCAT_STEP_STATE_INTERVAL, ENGINE_TIMEOUT_EMPTY_PROPOSAL,
42-
ENGINE_TIMEOUT_TOKEN_NONCE_BASE,
41+
ENGINE_TIMEOUT_BROADCAST_STEP_STATE, ENGINE_TIMEOUT_BROADCAT_STEP_STATE_INTERVAL, ENGINE_TIMEOUT_TOKEN_NONCE_BASE,
4342
};
4443

4544
pub struct TendermintExtension {
@@ -204,19 +203,11 @@ impl TendermintExtension {
204203
}
205204

206205
fn set_timer_step(&self, step: Step, view: View, expired_token_nonce: TimerToken) {
207-
self.api.clear_timer(ENGINE_TIMEOUT_EMPTY_PROPOSAL).expect("Timer clear succeeds");
208206
self.api.clear_timer(expired_token_nonce).expect("Timer clear succeeds");
209207
self.api
210208
.set_timer_once(expired_token_nonce + 1, self.timeouts.timeout(step, view))
211209
.expect("Timer set succeeds");
212210
}
213-
214-
fn set_timer_empty_proposal(&self, view: View) {
215-
self.api.clear_timer(ENGINE_TIMEOUT_EMPTY_PROPOSAL).expect("Timer clear succeeds");
216-
self.api
217-
.set_timer_once(ENGINE_TIMEOUT_EMPTY_PROPOSAL, self.timeouts.timeout(Step::Propose, view) / 2)
218-
.expect("Timer set succeeds");
219-
}
220211
}
221212

222213
impl NetworkExtension<Event> for TendermintExtension {
@@ -403,11 +394,7 @@ impl NetworkExtension<Event> for TendermintExtension {
403394
}
404395

405396
fn on_timeout(&mut self, token: TimerToken) {
406-
debug_assert!(
407-
token >= ENGINE_TIMEOUT_TOKEN_NONCE_BASE
408-
|| token == ENGINE_TIMEOUT_EMPTY_PROPOSAL
409-
|| token == ENGINE_TIMEOUT_BROADCAST_STEP_STATE
410-
);
397+
debug_assert!(token >= ENGINE_TIMEOUT_TOKEN_NONCE_BASE || token == ENGINE_TIMEOUT_BROADCAST_STEP_STATE);
411398
self.inner.send(worker::Event::OnTimeout(token)).unwrap();
412399
}
413400

@@ -443,11 +430,6 @@ impl NetworkExtension<Event> for TendermintExtension {
443430
view,
444431
expired_token_nonce,
445432
} => self.set_timer_step(step, view, expired_token_nonce),
446-
Event::SetTimerEmptyProposal {
447-
view,
448-
} => {
449-
self.set_timer_empty_proposal(view);
450-
}
451433
Event::BroadcastProposalBlock {
452434
signature,
453435
view,
@@ -482,9 +464,6 @@ pub enum Event {
482464
view: View,
483465
expired_token_nonce: TimerToken,
484466
},
485-
SetTimerEmptyProposal {
486-
view: View,
487-
},
488467
BroadcastProposalBlock {
489468
signature: SchnorrSignature,
490469
view: View,

core/src/consensus/tendermint/types.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ pub enum TendermintState {
3838
ProposeWaitImported {
3939
block: Box<SealedBlock>,
4040
},
41-
ProposeWaitEmptyBlockTimer {
42-
block: Box<SealedBlock>,
43-
},
4441
Prevote,
4542
Precommit,
4643
Commit {
@@ -63,9 +60,6 @@ impl TendermintState {
6360
TendermintState::ProposeWaitImported {
6461
..
6562
} => Step::Propose,
66-
TendermintState::ProposeWaitEmptyBlockTimer {
67-
..
68-
} => Step::Propose,
6963
TendermintState::Prevote => Step::Prevote,
7064
TendermintState::Precommit => Step::Precommit,
7165
TendermintState::Commit {
@@ -77,15 +71,6 @@ impl TendermintState {
7771
}
7872
}
7973

80-
pub fn is_propose_wait_empty_block_timer(&self) -> bool {
81-
match self {
82-
TendermintState::ProposeWaitEmptyBlockTimer {
83-
..
84-
} => true,
85-
_ => false,
86-
}
87-
}
88-
8974
pub fn is_commit(&self) -> bool {
9075
match self {
9176
TendermintState::Commit {
@@ -124,9 +109,6 @@ impl TendermintState {
124109
TendermintState::ProposeWaitImported {
125110
..
126111
} => None,
127-
TendermintState::ProposeWaitEmptyBlockTimer {
128-
..
129-
} => None,
130112
TendermintState::Prevote => None,
131113
TendermintState::Precommit => None,
132114
}
@@ -143,9 +125,6 @@ impl fmt::Debug for TendermintState {
143125
TendermintState::ProposeWaitImported {
144126
block,
145127
} => write!(f, "TendermintState::ProposeWaitImported({})", block.header().hash()),
146-
TendermintState::ProposeWaitEmptyBlockTimer {
147-
block,
148-
} => write!(f, "TendermintState::ProposeWaitEmptyBlockTimer({})", block.header().hash()),
149128
TendermintState::Prevote => write!(f, "TendermintState::Prevote"),
150129
TendermintState::Precommit => write!(f, "TendermintState::Precommit"),
151130
TendermintState::Commit {

core/src/consensus/tendermint/worker.rs

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ use super::stake::CUSTOM_ACTION_HANDLER_ID;
3939
use super::types::{Height, Proposal, Step, TendermintSealView, TendermintState, TwoThirdsMajority, View};
4040
use super::vote_collector::{DoubleVote, VoteCollector};
4141
use super::vote_regression_checker::VoteRegressionChecker;
42-
use super::{
43-
ENGINE_TIMEOUT_BROADCAST_STEP_STATE, ENGINE_TIMEOUT_EMPTY_PROPOSAL, ENGINE_TIMEOUT_TOKEN_NONCE_BASE, SEAL_FIELDS,
44-
};
42+
use super::{ENGINE_TIMEOUT_BROADCAST_STEP_STATE, ENGINE_TIMEOUT_TOKEN_NONCE_BASE, SEAL_FIELDS};
4543
use crate::account_provider::AccountProvider;
4644
use crate::block::*;
4745
use crate::client::ConsensusClient;
@@ -999,25 +997,10 @@ impl Worker {
999997
TendermintState::ProposeWaitImported {
1000998
block,
1001999
} => {
1002-
if !block.transactions().is_empty() {
1003-
cinfo!(ENGINE, "Submitting proposal block {}", block.header().hash());
1004-
self.move_to_step(TendermintState::Prevote, false);
1005-
self.broadcast_proposal_block(self.view, encoded::Block::new(block.rlp_bytes()));
1006-
} else {
1007-
ctrace!(ENGINE, "Empty proposal is generated, set timer");
1008-
self.step = TendermintState::ProposeWaitEmptyBlockTimer {
1009-
block,
1010-
};
1011-
self.extension
1012-
.send(network::Event::SetTimerEmptyProposal {
1013-
view: self.view,
1014-
})
1015-
.unwrap();
1016-
}
1000+
cinfo!(ENGINE, "Submitting proposal block {}", block.header().hash());
1001+
self.move_to_step(TendermintState::Prevote, false);
1002+
self.broadcast_proposal_block(self.view, encoded::Block::new(block.rlp_bytes()));
10171003
}
1018-
TendermintState::ProposeWaitEmptyBlockTimer {
1019-
..
1020-
} => unreachable!(),
10211004
_ => {}
10221005
};
10231006
} else if current_height < height {
@@ -1287,35 +1270,6 @@ impl Worker {
12871270
}
12881271

12891272
fn on_timeout(&mut self, token: usize) {
1290-
// Timeout from empty block generation
1291-
if token == ENGINE_TIMEOUT_EMPTY_PROPOSAL {
1292-
let block = if self.step.is_propose_wait_empty_block_timer() {
1293-
let previous = mem::replace(&mut self.step, TendermintState::Propose);
1294-
match previous {
1295-
TendermintState::ProposeWaitEmptyBlockTimer {
1296-
block,
1297-
} => block,
1298-
_ => unreachable!(),
1299-
}
1300-
} else {
1301-
cwarn!(ENGINE, "Empty proposal timer was not cleared.");
1302-
return
1303-
};
1304-
1305-
// When self.height != block.header().number() && "propose timeout" is already called,
1306-
// the state is stuck and can't move to Prevote. We should change the step to Prevote.
1307-
self.move_to_step(TendermintState::Prevote, false);
1308-
if self.height == block.header().number() {
1309-
cdebug!(ENGINE, "Empty proposal timer is finished, go to the prevote step and broadcast the block");
1310-
cinfo!(ENGINE, "Submitting proposal block {}", block.header().hash());
1311-
self.broadcast_proposal_block(self.view, encoded::Block::new(block.rlp_bytes()));
1312-
} else {
1313-
cwarn!(ENGINE, "Empty proposal timer was for previous height.");
1314-
}
1315-
1316-
return
1317-
}
1318-
13191273
if token == ENGINE_TIMEOUT_BROADCAST_STEP_STATE {
13201274
if let Some(votes_received) = self.votes_received.borrow_if_mutated() {
13211275
self.broadcast_state(
@@ -1350,12 +1304,6 @@ impl Worker {
13501304
cwarn!(ENGINE, "Propose timed out but still waiting for the block imported");
13511305
return
13521306
}
1353-
TendermintState::ProposeWaitEmptyBlockTimer {
1354-
..
1355-
} => {
1356-
cwarn!(ENGINE, "Propose timed out but still waiting for the empty block");
1357-
return
1358-
}
13591307
TendermintState::Prevote if self.has_enough_any_votes() => {
13601308
cinfo!(ENGINE, "Prevote timeout.");
13611309
TendermintState::Precommit

0 commit comments

Comments
 (0)