Skip to content

Commit 3008e45

Browse files
HoOngEemajecty
authored andcommitted
Remove TxOrigin::RetractedBlock from mem_pool
1 parent b14af9c commit 3008e45

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

core/src/miner/mem_pool.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl MemPool {
158158
.filter(|order| {
159159
count += 1;
160160
mem_usage += order.mem_usage;
161-
!order.origin.is_local_or_retracted() && (mem_usage > memory_limit || count > limit)
161+
!order.origin.is_local() && (mem_usage > memory_limit || count > limit)
162162
})
163163
.cloned()
164164
.collect()
@@ -985,12 +985,7 @@ pub mod test {
985985
#[test]
986986
fn origin_ordering() {
987987
assert_eq!(TxOrigin::Local.cmp(&TxOrigin::External), Ordering::Less);
988-
assert_eq!(TxOrigin::RetractedBlock.cmp(&TxOrigin::Local), Ordering::Less);
989-
assert_eq!(TxOrigin::RetractedBlock.cmp(&TxOrigin::External), Ordering::Less);
990-
991988
assert_eq!(TxOrigin::External.cmp(&TxOrigin::Local), Ordering::Greater);
992-
assert_eq!(TxOrigin::Local.cmp(&TxOrigin::RetractedBlock), Ordering::Greater);
993-
assert_eq!(TxOrigin::External.cmp(&TxOrigin::RetractedBlock), Ordering::Greater);
994989
}
995990

996991
#[test]

core/src/miner/mem_pool_types.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Kodebox, Inc.
1+
// Copyright 2019-2020 Kodebox, Inc.
22
// This file is part of CodeChain.
33
//
44
// This program is free software: you can redistribute it and/or modify
@@ -33,21 +33,17 @@ pub enum TxOrigin {
3333
Local,
3434
/// External transaction received from network
3535
External,
36-
/// Transaction from retracted blocks
37-
RetractedBlock,
3836
}
3937

4038
type TxOriginType = u8;
4139
const LOCAL: TxOriginType = 0x01;
4240
const EXTERNAL: TxOriginType = 0x02;
43-
const RETRACTEDBLOCK: TxOriginType = 0x03;
4441

4542
impl Encodable for TxOrigin {
4643
fn rlp_append(&self, s: &mut RlpStream) {
4744
match self {
4845
TxOrigin::Local => LOCAL.rlp_append(s),
4946
TxOrigin::External => EXTERNAL.rlp_append(s),
50-
TxOrigin::RetractedBlock => RETRACTEDBLOCK.rlp_append(s),
5147
};
5248
}
5349
}
@@ -57,7 +53,6 @@ impl Decodable for TxOrigin {
5753
match d.as_val().expect("rlp decode Error") {
5854
LOCAL => Ok(TxOrigin::Local),
5955
EXTERNAL => Ok(TxOrigin::External),
60-
RETRACTEDBLOCK => Ok(TxOrigin::RetractedBlock),
6156
_ => Err(DecoderError::Custom("Unexpected Txorigin type")),
6257
}
6358
}
@@ -76,8 +71,6 @@ impl Ord for TxOrigin {
7671
}
7772

7873
match (*self, *other) {
79-
(TxOrigin::RetractedBlock, _) => Ordering::Less,
80-
(_, TxOrigin::RetractedBlock) => Ordering::Greater,
8174
(TxOrigin::Local, _) => Ordering::Less,
8275
_ => Ordering::Greater,
8376
}
@@ -89,10 +82,6 @@ impl TxOrigin {
8982
self == TxOrigin::Local
9083
}
9184

92-
pub fn is_local_or_retracted(self) -> bool {
93-
self == TxOrigin::Local || self == TxOrigin::RetractedBlock
94-
}
95-
9685
pub fn is_external(self) -> bool {
9786
self == TxOrigin::External
9887
}
@@ -329,7 +318,7 @@ impl CurrentQueue {
329318

330319
pub fn insert(&mut self, order: TransactionOrder) {
331320
self.queue.insert(order);
332-
if !order.origin.is_local_or_retracted() {
321+
if !order.origin.is_local() {
333322
self.mem_usage += order.mem_usage;
334323
self.count += 1;
335324
}
@@ -338,7 +327,7 @@ impl CurrentQueue {
338327

339328
pub fn remove(&mut self, order: &TransactionOrder) {
340329
assert!(self.queue.remove(order));
341-
if !order.origin.is_local_or_retracted() {
330+
if !order.origin.is_local() {
342331
self.mem_usage -= order.mem_usage;
343332
self.count -= 1;
344333
}
@@ -388,15 +377,15 @@ impl FutureQueue {
388377

389378
pub fn insert(&mut self, order: TransactionOrder) {
390379
self.queue.insert(order);
391-
if !order.origin.is_local_or_retracted() {
380+
if !order.origin.is_local() {
392381
self.mem_usage += order.mem_usage;
393382
self.count += 1;
394383
}
395384
}
396385

397386
pub fn remove(&mut self, order: &TransactionOrder) {
398387
assert!(self.queue.remove(order));
399-
if !order.origin.is_local_or_retracted() {
388+
if !order.origin.is_local() {
400389
self.mem_usage -= order.mem_usage;
401390
self.count -= 1;
402391
}

0 commit comments

Comments
 (0)