Skip to content

Commit ddfe237

Browse files
committed
vm: notify engine of new block
Signed-off-by: Sam Batschelet <[email protected]>
1 parent 0b9557d commit ddfe237

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

mini-kvvm/src/chain/vm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ pub struct Context {
1414
pub trait Vm: avalanche_types::rpcchainvm::vm::Vm {
1515
async fn is_bootstrapped(&self) -> bool;
1616
async fn submit(&self, txs: Vec<Transaction>) -> Result<()>;
17+
async fn notify_block_ready(&self);
1718
}

mini-kvvm/src/vm.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
api,
2222
block::Block as StatefulBlock,
2323
block::{self, state::State},
24-
chain::{self, tx::Transaction},
24+
chain::{self, tx::Transaction, vm::Vm},
2525
genesis::Genesis,
2626
};
2727

@@ -133,6 +133,25 @@ impl crate::chain::vm::Vm for ChainVm {
133133
}
134134
Ok(())
135135
}
136+
137+
/// Sends a signal to the consensus engine that a new block
138+
/// is ready to be created.
139+
async fn notify_block_ready(&self) {
140+
let vm = self.inner.read().await;
141+
142+
if let Some(engine) = &vm.to_engine {
143+
if let Err(_) = engine
144+
.send(rpcchainvm::common::message::Message::PendingTxs)
145+
.await
146+
{
147+
log::warn!("dropping message to consensus engine");
148+
};
149+
return;
150+
}
151+
152+
log::error!("consensus engine channel failed to initialized");
153+
return;
154+
}
136155
}
137156

138157
#[tonic::async_trait]
@@ -466,6 +485,8 @@ impl rpcchainvm::snowman::block::ChainVm for ChainVm {
466485
.await
467486
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;
468487

488+
self.notify_block_ready().await;
489+
469490
Ok(Box::new(block))
470491
}
471492

0 commit comments

Comments
 (0)