File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -14,4 +14,5 @@ pub struct Context {
14
14
pub trait Vm : avalanche_types:: rpcchainvm:: vm:: Vm {
15
15
async fn is_bootstrapped ( & self ) -> bool ;
16
16
async fn submit ( & self , txs : Vec < Transaction > ) -> Result < ( ) > ;
17
+ async fn notify_block_ready ( & self ) ;
17
18
}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ use crate::{
21
21
api,
22
22
block:: Block as StatefulBlock ,
23
23
block:: { self , state:: State } ,
24
- chain:: { self , tx:: Transaction } ,
24
+ chain:: { self , tx:: Transaction , vm :: Vm } ,
25
25
genesis:: Genesis ,
26
26
} ;
27
27
@@ -133,6 +133,25 @@ impl crate::chain::vm::Vm for ChainVm {
133
133
}
134
134
Ok ( ( ) )
135
135
}
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
+ }
136
155
}
137
156
138
157
#[ tonic:: async_trait]
@@ -466,6 +485,8 @@ impl rpcchainvm::snowman::block::ChainVm for ChainVm {
466
485
. await
467
486
. map_err ( |e| Error :: new ( ErrorKind :: Other , e. to_string ( ) ) ) ?;
468
487
488
+ self . notify_block_ready ( ) . await ;
489
+
469
490
Ok ( Box :: new ( block) )
470
491
}
471
492
You can’t perform that action at this time.
0 commit comments