Skip to content

Commit 31d5959

Browse files
authored
Merge pull request #51 from ava-labs/mempool-fifo
vm: mempool fifo
2 parents 516c073 + 763c5dd commit 31d5959

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

mini-kvvm/src/vm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
collections::HashMap,
2+
collections::{HashMap, VecDeque},
33
io::{Error, ErrorKind, Result},
44
sync::Arc,
55
time,
@@ -55,7 +55,7 @@ impl Default for ChainVmInterior {
5555
#[derive(Clone)]
5656
pub struct ChainVm {
5757
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>>>,
5959
pub inner: Arc<RwLock<ChainVmInterior>>,
6060
pub verified_blocks: Arc<RwLock<HashMap<ids::Id, crate::block::Block>>>,
6161
}
@@ -65,7 +65,7 @@ impl ChainVm {
6565
pub fn new() -> Box<dyn rpcchainvm::vm::Vm + Send + Sync> {
6666
let inner = Arc::new(RwLock::new(ChainVmInterior::default()));
6767
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()));
6969
let verified_blocks = Arc::new(RwLock::new(HashMap::new()));
7070

7171
Box::new(ChainVm {
@@ -77,7 +77,7 @@ impl ChainVm {
7777
}
7878

7979
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()));
8181
let verified_blocks = &Arc::new(RwLock::new(HashMap::new()));
8282
let inner = ChainVmInterior {
8383
ctx: None,
@@ -125,7 +125,7 @@ impl crate::chain::vm::Vm for ChainVm {
125125
.await
126126
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;
127127
let mut mempool = self.mempool.write().await;
128-
mempool.push(tx.to_owned());
128+
mempool.push_front(tx.to_owned());
129129
}
130130
Ok(())
131131
}
@@ -397,7 +397,7 @@ impl rpcchainvm::snowman::block::ChainVm for ChainVm {
397397
let mut txs = Vec::new();
398398

399399
loop {
400-
match mempool.pop() {
400+
match mempool.pop_back() {
401401
Some(tx) => {
402402
log::debug!("writing tx{:?}\n", tx);
403403
// verify

0 commit comments

Comments
 (0)