Skip to content

Commit

Permalink
Remove outdated code and added a new test on deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Jan 10, 2025
1 parent ba1825d commit 1bbd716
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 126 deletions.
1 change: 0 additions & 1 deletion crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ type GasCosts {

enum GasCostsVersion {
V1
V2
}

type Genesis {
Expand Down
124 changes: 0 additions & 124 deletions crates/client/src/client/schema/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ pub struct GasCosts {
#[cynic(schema_path = "./assets/schema.sdl")]
pub enum GasCostsVersion {
V1,
V2,
#[cynic(fallback)]
Unknown,
}
Expand Down Expand Up @@ -473,129 +472,6 @@ impl TryFrom<GasCosts> for fuel_core_types::fuel_tx::GasCosts {
}
.into(),
)),
GasCostsVersion::V2 => {
Ok(fuel_core_types::fuel_tx::GasCosts::new(
fuel_core_types::fuel_tx::consensus_parameters::gas::GasCostsValuesV5 {
add: value.add.into(),
addi: value.addi.into(),
and: value.and.into(),
andi: value.andi.into(),
bal: value.bal.into(),
bhei: value.bhei.into(),
bhsh: value.bhsh.into(),
burn: value.burn.into(),
cb: value.cb.into(),
cfsi: value.cfsi.into(),
div: value.div.into(),
divi: value.divi.into(),
eck1: value.eck1.into(),
ecr1: value.ecr1.into(),
eq: value.eq.into(),
exp: value.exp.into(),
expi: value.expi.into(),
flag: value.flag.into(),
gm: value.gm.into(),
gt: value.gt.into(),
gtf: value.gtf.into(),
ji: value.ji.into(),
jmp: value.jmp.into(),
jne: value.jne.into(),
jnei: value.jnei.into(),
jnzi: value.jnzi.into(),
jmpf: value.jmpf.into(),
jmpb: value.jmpb.into(),
jnzf: value.jnzf.into(),
jnzb: value.jnzb.into(),
jnef: value.jnef.into(),
jneb: value.jneb.into(),
lb: value.lb.into(),
log: value.log.into(),
lt: value.lt.into(),
lw: value.lw.into(),
mint: value.mint.into(),
mlog: value.mlog.into(),
mod_op: value.mod_op.into(),
modi: value.modi.into(),
move_op: value.move_op.into(),
movi: value.movi.into(),
mroo: value.mroo.into(),
mul: value.mul.into(),
muli: value.muli.into(),
mldv: value.mldv.into(),
noop: value.noop.into(),
not: value.not.into(),
or: value.or.into(),
ori: value.ori.into(),
poph: value.poph.into(),
popl: value.popl.into(),
pshh: value.pshh.into(),
pshl: value.pshl.into(),
ret: value.ret.into(),
rvrt: value.rvrt.into(),
sb: value.sb.into(),
sll: value.sll.into(),
slli: value.slli.into(),
srl: value.srl.into(),
srli: value.srli.into(),
srw: value.srw.into(),
sub: value.sub.into(),
subi: value.subi.into(),
sw: value.sw.into(),
sww: value.sww.into(),
time: value.time.into(),
tr: value.tr.into(),
tro: value.tro.into(),
wdcm: value.wdcm.into(),
wqcm: value.wqcm.into(),
wdop: value.wdop.into(),
wqop: value.wqop.into(),
wdml: value.wdml.into(),
wqml: value.wqml.into(),
wddv: value.wddv.into(),
wqdv: value.wqdv.into(),
wdmd: value.wdmd.into(),
wqmd: value.wqmd.into(),
wdam: value.wdam.into(),
wqam: value.wqam.into(),
wdmm: value.wdmm.into(),
wqmm: value.wqmm.into(),
xor: value.xor.into(),
xori: value.xori.into(),
ecop: value.ecop.map(Into::into).unwrap_or(0),

aloc: value.aloc_dependent_cost.into(),
bsiz: value.bsiz.map(Into::into).unwrap_or(fuel_core_types::fuel_tx::consensus_parameters::DependentCost::free()),
bldd: value.bldd.map(Into::into).unwrap_or(fuel_core_types::fuel_tx::consensus_parameters::DependentCost::free()),
cfe: value.cfe.into(),
cfei: value.cfei_dependent_cost.into(),
call: value.call.into(),
ccp: value.ccp.into(),
croo: value.croo.into(),
csiz: value.csiz.into(),
ed19: value.ed19_dependent_cost.into(),
k256: value.k256.into(),
ldc: value.ldc.into(),
logd: value.logd.into(),
mcl: value.mcl.into(),
mcli: value.mcli.into(),
mcp: value.mcp.into(),
mcpi: value.mcpi.into(),
meq: value.meq.into(),
retd: value.retd.into(),
s256: value.s256.into(),
scwq: value.scwq.into(),
smo: value.smo.into(),
srwq: value.srwq.into(),
swwq: value.swwq.into(),
epar: value.epar.map(Into::into).unwrap_or(fuel_core_types::fuel_tx::consensus_parameters::DependentCost::free()),
contract_root: value.contract_root.into(),
state_root: value.state_root.into(),
vm_initialization: value.vm_initialization.into(),
new_storage_per_byte: value.new_storage_per_byte.into(),
}
.into(),
))
}
_ => Err(ConversionError::UnknownVariant("GasCostsVersion")),
}
}
Expand Down
104 changes: 103 additions & 1 deletion crates/services/txpool_v2/src/tests/tests_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use fuel_core_types::{
block::Block,
consensus::Sealed,
},
fuel_tx::UniqueIdentifier,
fuel_tx::{
UniqueIdentifier,
UtxoId,
},
fuel_types::ChainId,
services::{
block_importer::ImportResult,
Expand Down Expand Up @@ -335,6 +338,105 @@ async fn prune_expired_transactions() {
service.stop_and_await().await.unwrap();
}

#[tokio::test]
async fn prune_expired_doesnt_trigger_twice() {
let mut universe = TestPoolUniverse::default();
let (sender, receiver) = tokio::sync::mpsc::channel(10);

let (output_1, input_1) = universe.create_output_and_input();
let (output_2, input_2) = universe.create_output_and_input();
let tx1 = universe.build_script_transaction(None, Some(vec![output_1]), 10);
let tx2 = universe.build_script_transaction(None, Some(vec![output_2]), 20);

let service =
universe.build_service(None, Some(MockImporter::with_block_provider(receiver)));
service.start_and_await().await.unwrap();

let ids = vec![tx1.id(&Default::default()), tx2.id(&Default::default())];
service
.shared
.try_insert(vec![tx1.clone(), tx2.clone()])
.unwrap();

universe
.waiting_txs_insertion(service.shared.new_tx_notification_subscribe(), ids)
.await;

let tx3 = universe.build_script_transaction(
Some(vec![
input_1.into_input(UtxoId::new(tx1.id(&ChainId::default()), 0)),
input_2.into_input(UtxoId::new(tx2.id(&ChainId::default()), 0)),
]),
None,
30,
);

let ids = vec![tx3.id(&Default::default())];
service.shared.try_insert(vec![tx3.clone()]).unwrap();

universe
.waiting_txs_insertion(service.shared.new_tx_notification_subscribe(), ids)
.await;

// Given
let expiration_block = Sealed {
entity: {
let mut block = Block::default();
let header = block.header_mut();
header.set_block_height(DEFAULT_EXPIRATION_HEIGHT);
block
},
consensus: Default::default(),
};

assert_eq!(
service
.shared
.find(vec![
tx1.id(&Default::default()),
tx2.id(&Default::default()),
tx3.id(&Default::default()),
])
.await
.unwrap()
.iter()
.filter(|x| x.is_some())
.count(),
3
);

// When
let mut update_1 = service
.shared
.tx_update_subscribe(tx1.id(&ChainId::default()))
.unwrap();
let mut update_2 = service
.shared
.tx_update_subscribe(tx2.id(&ChainId::default()))
.unwrap();
let mut update_3 = service
.shared
.tx_update_subscribe(tx3.id(&ChainId::default()))
.unwrap();
sender
.send(Arc::new(ImportResult::new_from_local(
expiration_block,
vec![],
vec![],
)))
.await
.unwrap();
update_1.next().await.expect("tx1 should be pruned");
update_2.next().await.expect("tx2 should be pruned");
update_3.next().await.expect("tx3 should be pruned");

// Then
// Verify that their no new messages on `update_3`
assert!(update_3.next().await.is_none());

service.stop_and_await().await.unwrap();
}

#[tokio::test]
async fn simple_insert_removal_subscription() {
const TIMEOUT: u64 = 2;
Expand Down

0 comments on commit 1bbd716

Please sign in to comment.