Skip to content

Commit 18001f6

Browse files
remagpieforiequal0
authored andcommitted
Introduce on_open_block
`on_open_block` is called when the block is created, before processing any transactions included in the block.
1 parent 4292086 commit 18001f6

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

core/src/block.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ impl<'x> OpenBlock<'x> {
313313
self.block.header.set_seal(seal);
314314
Ok(())
315315
}
316+
317+
pub fn inner_mut(&mut self) -> &mut ExecutedBlock {
318+
&mut self.block
319+
}
316320
}
317321

318322
/// Just like `OpenBlock`, except that we've applied `Engine::on_close_block`, finished up the non-seal header fields.
@@ -492,6 +496,7 @@ pub fn enact<C: ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo>(
492496
let mut b = OpenBlock::try_new(engine, db, parent, Address::default(), vec![])?;
493497

494498
b.populate_from(header);
499+
engine.on_open_block(b.inner_mut())?;
495500
b.push_transactions(transactions, client, parent.number(), parent.timestamp())?;
496501

497502
let term_common_params = client.term_common_params(BlockId::Hash(*header.parent_hash()));

core/src/consensus/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ pub trait ConsensusEngine: Sync + Send {
221221
/// Stops any services that the may hold the Engine and makes it safe to drop.
222222
fn stop(&self) {}
223223

224+
/// Block transformation functions, before the transactions.
225+
fn on_open_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> {
226+
Ok(())
227+
}
228+
224229
/// Block transformation functions, after the transactions.
225230
fn on_close_block(
226231
&self,

core/src/consensus/tendermint/engine.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ impl ConsensusEngine for Tendermint {
134134

135135
fn stop(&self) {}
136136

137+
/// Block transformation functions, before the transactions.
138+
fn on_open_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
139+
let metadata = block.state().metadata()?.expect("Metadata must exist");
140+
if block.header().number() == metadata.last_term_finished_block_num() + 1 {
141+
// FIXME: on_term_open
142+
}
143+
Ok(())
144+
}
145+
137146
fn on_close_block(
138147
&self,
139148
block: &mut ExecutedBlock,

core/src/miner/miner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ impl Miner {
527527
return Ok(None)
528528
}
529529
}
530+
self.engine.on_open_block(open_block.inner_mut())?;
530531

531532
let mut invalid_transactions = Vec::new();
532533

0 commit comments

Comments
 (0)