1
1
use std:: {
2
- collections:: HashMap ,
2
+ collections:: { HashMap , VecDeque } ,
3
3
io:: { Error , ErrorKind , Result } ,
4
4
sync:: Arc ,
5
5
time,
@@ -55,7 +55,7 @@ impl Default for ChainVmInterior {
55
55
#[ derive( Clone ) ]
56
56
pub struct ChainVm {
57
57
pub db : Box < dyn rpcchainvm:: database:: Database + Sync + Send > ,
58
- pub mempool : Arc < RwLock < Vec < chain:: tx:: tx:: Transaction > > > ,
58
+ pub mempool : Arc < RwLock < VecDeque < chain:: tx:: tx:: Transaction > > > ,
59
59
pub inner : Arc < RwLock < ChainVmInterior > > ,
60
60
pub verified_blocks : Arc < RwLock < HashMap < ids:: Id , crate :: block:: Block > > > ,
61
61
}
@@ -65,7 +65,7 @@ impl ChainVm {
65
65
pub fn new ( ) -> Box < dyn rpcchainvm:: vm:: Vm + Send + Sync > {
66
66
let inner = Arc :: new ( RwLock :: new ( ChainVmInterior :: default ( ) ) ) ;
67
67
let db = rpcchainvm:: database:: memdb:: Database :: new ( ) ;
68
- let mempool = Arc :: new ( RwLock :: new ( Vec :: new ( ) ) ) ;
68
+ let mempool = Arc :: new ( RwLock :: new ( VecDeque :: new ( ) ) ) ;
69
69
let verified_blocks = Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ;
70
70
71
71
Box :: new ( ChainVm {
@@ -77,7 +77,7 @@ impl ChainVm {
77
77
}
78
78
79
79
pub fn new_with_state ( db : & Box < dyn rpcchainvm:: database:: Database + Sync + Send > ) -> Self {
80
- let mempool = Arc :: new ( RwLock :: new ( Vec :: new ( ) ) ) ;
80
+ let mempool = Arc :: new ( RwLock :: new ( VecDeque :: new ( ) ) ) ;
81
81
let verified_blocks = & Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ;
82
82
let inner = ChainVmInterior {
83
83
ctx : None ,
@@ -125,7 +125,7 @@ impl crate::chain::vm::Vm for ChainVm {
125
125
. await
126
126
. map_err ( |e| Error :: new ( ErrorKind :: Other , e. to_string ( ) ) ) ?;
127
127
let mut mempool = self . mempool . write ( ) . await ;
128
- mempool. push ( tx. to_owned ( ) ) ;
128
+ mempool. push_front ( tx. to_owned ( ) ) ;
129
129
}
130
130
Ok ( ( ) )
131
131
}
@@ -397,7 +397,7 @@ impl rpcchainvm::snowman::block::ChainVm for ChainVm {
397
397
let mut txs = Vec :: new ( ) ;
398
398
399
399
loop {
400
- match mempool. pop ( ) {
400
+ match mempool. pop_back ( ) {
401
401
Some ( tx) => {
402
402
log:: debug!( "writing tx{:?}\n " , tx) ;
403
403
// verify
0 commit comments