Skip to content

vm: notify engine of new block #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mini-kvvm/src/chain/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub struct Context {
pub trait Vm: avalanche_types::rpcchainvm::vm::Vm {
async fn is_bootstrapped(&self) -> bool;
async fn submit(&self, txs: Vec<Transaction>) -> Result<()>;
async fn notify_block_ready(&self);
}
23 changes: 22 additions & 1 deletion mini-kvvm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
api,
block::Block as StatefulBlock,
block::{self, state::State},
chain::{self, tx::Transaction},
chain::{self, tx::Transaction, vm::Vm},
genesis::Genesis,
};

Expand Down Expand Up @@ -133,6 +133,25 @@ impl crate::chain::vm::Vm for ChainVm {
}
Ok(())
}

/// Sends a signal to the consensus engine that a new block
/// is ready to be created.
async fn notify_block_ready(&self) {
let vm = self.inner.read().await;

if let Some(engine) = &vm.to_engine {
if let Err(_) = engine
.send(rpcchainvm::common::message::Message::PendingTxs)
.await
{
log::warn!("dropping message to consensus engine");
};
return;
}

log::error!("consensus engine channel failed to initialized");
return;
}
}

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

self.notify_block_ready().await;

Ok(Box::new(block))
}

Expand Down