Skip to content

Commit 7d95965

Browse files
authored
Merge pull request #847 from openmina/feat/block_producer/start_production_sooner
Block Producer: start production earlier
2 parents 5e2eeba + 2f04124 commit 7d95965

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

node/src/block_producer/block_producer_actions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub enum BlockProducerAction {
6161
proof: Box<MinaBaseProofStableV2>,
6262
},
6363
BlockProduced,
64-
#[action_event(level = trace)]
6564
BlockInject,
6665
BlockInjected,
6766
}

node/src/block_producer/block_producer_state.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,19 @@ impl BlockProducerCurrentState {
293293
}
294294

295295
pub fn won_slot_should_produce(&self, now: redux::Timestamp) -> bool {
296+
// TODO(binier): maybe have runtime estimate
297+
#[cfg(not(target_arch = "wasm32"))]
298+
const BLOCK_PRODUCTION_ESTIMATE: u64 = Duration::from_secs(5).as_nanos() as u64;
299+
#[cfg(target_arch = "wasm32")]
300+
const BLOCK_PRODUCTION_ESTIMATE: u64 = Duration::from_secs(20).as_nanos() as u64;
301+
296302
let slot_interval = Duration::from_secs(3 * 60).as_nanos() as u64;
297303
match self {
298304
Self::WonSlot { won_slot, .. } | Self::WonSlotWait { won_slot, .. } => {
299305
// Make sure to only producer blocks when in the slot interval
300306
let slot_upper_bound = won_slot.slot_time + slot_interval;
301-
now >= won_slot.slot_time && now < slot_upper_bound
307+
let estimated_produced_time = now + BLOCK_PRODUCTION_ESTIMATE;
308+
estimated_produced_time >= won_slot.slot_time && now < slot_upper_bound
302309
}
303310
_ => false,
304311
}

node/src/consensus/consensus_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl redux::EnablingCondition<crate::State> for ConsensusAction {
161161
state.transition_frontier.sync.best_tip(),
162162
])
163163
.flatten()
164-
.all(|b| b.hash() == best_tip.hash()
164+
.any(|b| b.hash() == best_tip.hash()
165165
|| !consensus_take(b.consensus_state(), best_tip.consensus_state(), b.hash(), best_tip.hash())) {
166166
return false;
167167
}

node/src/snark_pool/candidate/snark_pool_candidate_actions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub enum SnarkPoolCandidateAction {
2020
peer_id: PeerId,
2121
info: SnarkInfo,
2222
},
23+
#[action_event(level = trace)]
2324
WorkFetchAll,
2425
WorkFetchInit {
2526
peer_id: PeerId,
@@ -34,6 +35,7 @@ pub enum SnarkPoolCandidateAction {
3435
peer_id: PeerId,
3536
work: Snark,
3637
},
38+
#[action_event(level = trace)]
3739
WorkVerifyNext,
3840
WorkVerifyPending {
3941
peer_id: PeerId,

node/src/snark_pool/snark_pool_actions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub enum SnarkPoolAction {
3636
snark: Snark,
3737
sender: PeerId,
3838
},
39+
#[action_event(level = trace)]
3940
P2pSendAll,
4041
P2pSend {
4142
peer_id: PeerId,
@@ -78,6 +79,8 @@ impl redux::EnablingCondition<crate::State> for SnarkPoolAction {
7879
SnarkPoolAction::P2pSend { peer_id } => state
7980
.p2p
8081
.get_ready_peer(peer_id)
82+
// can't propagate empty snarkpool
83+
.filter(|_| !state.snark_pool.is_empty())
8184
// Only send commitments/snarks if peer has the same best tip,
8285
// or its best tip is extension of our best tip. In such case
8386
// no commitment/snark will be dropped by peer, because it

node/src/snark_pool/snark_pool_state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ impl SnarkPoolState {
7171
}
7272
}
7373

74+
pub fn is_empty(&self) -> bool {
75+
self.list.is_empty()
76+
}
77+
7478
pub fn last_index(&self) -> u64 {
7579
self.list.last_key_value().map_or(0, |(k, _)| *k)
7680
}

0 commit comments

Comments
 (0)