Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/price_optimizing_algo' into…
Browse files Browse the repository at this point in the history
… feat/higher_priority_fee_when_late
  • Loading branch information
segfault-magnet committed Jan 14, 2025
2 parents d47d9a8 + ad1a711 commit 8b1c861
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 156 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 0 additions & 73 deletions packages/adapters/eth/src/fee_api_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,6 @@ mod tests {
);
}

#[test]
fn test_full_range_chunk() {
// given
let initial_range = 20..=30;
let chunk_size = 11;

// when
let result = chunk_range_inclusive(initial_range, chunk_size);

// then
let expected = vec![20..=30];
assert_eq!(
result, expected,
"Whole range should be a single chunk when chunk_size equals range size"
);
}

#[test]
fn test_unpack_fee_history_empty_base_fee() {
// given
Expand Down Expand Up @@ -502,60 +485,4 @@ mod tests {
"Expected BlockFees entries with large u64 values"
);
}

#[test]
fn test_unpack_fee_history_full_range_chunk() {
// given
let fees = FeeHistory {
oldest_block: 800,
base_fee_per_gas: vec![500, 600, 700, 800, 900], // number_of_blocks =4
base_fee_per_blob_gas: vec![550, 650, 750, 850, 950],
reward: Some(vec![vec![50], vec![60], vec![70], vec![80]]),
..Default::default()
};

// when
let result = unpack_fee_history(fees);

// then
let expected = vec![
FeesAtHeight {
height: 800,
fees: Fees {
base_fee_per_gas: 500.try_into().unwrap(),
reward: 50.try_into().unwrap(),
base_fee_per_blob_gas: 550.try_into().unwrap(),
},
},
FeesAtHeight {
height: 801,
fees: Fees {
base_fee_per_gas: 600.try_into().unwrap(),
reward: 60.try_into().unwrap(),
base_fee_per_blob_gas: 650.try_into().unwrap(),
},
},
FeesAtHeight {
height: 802,
fees: Fees {
base_fee_per_gas: 700.try_into().unwrap(),
reward: 70.try_into().unwrap(),
base_fee_per_blob_gas: 750.try_into().unwrap(),
},
},
FeesAtHeight {
height: 803,
fees: Fees {
base_fee_per_gas: 800.try_into().unwrap(),
reward: 80.try_into().unwrap(),
base_fee_per_blob_gas: 850.try_into().unwrap(),
},
},
];
assert_eq!(
result.unwrap(),
expected,
"Expected BlockFees entries matching the full range chunk"
);
}
}
50 changes: 40 additions & 10 deletions packages/adapters/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,19 @@ mod tests {
storage: impl services::block_importer::port::Storage,
range: RangeInclusive<u32>,
) {
let blocks = range
.clone()
.map(|height| CompressedFuelBlock {
height,
data: nonempty![height as u8],
})
.collect_nonempty()
.expect("shouldn't be empty");

storage.insert_blocks(blocks).await.unwrap();
// Insert blocks in chunks to enable setting up the db for a load test
let chunk_size = 10_000;
for chunk in range.chunks(chunk_size).into_iter() {
let blocks = chunk
.map(|height| CompressedFuelBlock {
height,
data: nonempty![height as u8],
})
.collect_nonempty()
.expect("chunk shouldn't be empty");

storage.insert_blocks(blocks).await.unwrap();
}
}

async fn insert_sequence_of_bundled_blocks(
Expand Down Expand Up @@ -659,6 +662,33 @@ mod tests {
assert_eq!(height_range, 0..=2);
}

#[tokio::test]
async fn load_test_for_query() {
let storage = start_db().await;

let bundled_count = 7_000_000;
insert_sequence_of_bundled_blocks(storage.clone(), 0..=bundled_count, 1).await;

let unbundled_start = bundled_count + 1;
let unbundled_end = unbundled_start + 10_000;
insert_sequence_of_unbundled_blocks(storage.clone(), unbundled_start..=unbundled_end).await;

// look back a week into the past
let start_height = unbundled_end - 604_800;
let blocks_to_retrieve = 3500;
let start_time = std::time::Instant::now();
let height_range =
lowest_unbundled_sequence(storage.clone(), start_height, blocks_to_retrieve as usize)
.await;
let elapsed_time = start_time.elapsed();

let expected_range = unbundled_start..=(unbundled_start + blocks_to_retrieve - 1);
assert_eq!(height_range, expected_range);

// assert that the query executes within an acceptable time
assert!(elapsed_time.as_secs_f64() <= 2.0);
}

// Important because sqlx panics if the bundle is too big
#[tokio::test]
async fn can_insert_big_batches() {
Expand Down
19 changes: 11 additions & 8 deletions packages/adapters/storage/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,17 @@ impl Postgres {
let response = sqlx::query_as!(
tables::DBCompressedFuelBlock,
r#"
SELECT fb.*
FROM fuel_blocks fb WHERE fb.height >= $1
AND NOT EXISTS (
SELECT 1
FROM bundles b
WHERE fb.height BETWEEN b.start_height AND b.end_height
)
ORDER BY fb.height LIMIT $2"#,
SELECT fb.*
FROM fuel_blocks fb
WHERE fb.height >= $1
AND NOT EXISTS (
SELECT 1 FROM bundles b
WHERE fb.height BETWEEN b.start_height AND b.end_height
AND b.end_height >= $1
)
ORDER BY fb.height
LIMIT $2;
"#,
i64::from(starting_height), // Parameter $1
limit // Parameter $2
)
Expand Down
18 changes: 0 additions & 18 deletions packages/services/src/fees/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,3 @@ impl PreconfiguredFeeApi {
}
}
}

pub fn incrementing_fees(num_blocks: u64) -> SequentialBlockFees {
let fees = (0..num_blocks)
.map(|i| {
let fee = u128::from(i) + 1;
FeesAtHeight {
height: i,
fees: Fees {
base_fee_per_gas: fee,
reward: fee,
base_fee_per_blob_gas: fee,
},
}
})
.collect::<Result<_, _>>();

fees.unwrap()
}
18 changes: 0 additions & 18 deletions packages/services/src/state_committer/fee_algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,24 +439,6 @@ mod tests {
}
};
"Should not send because short-term reward is higher"
)]
#[test_case(
Setup {
old_fees: Fees { base_fee_per_gas: 4000, reward: 8000, base_fee_per_blob_gas: 4000},
new_fees: Fees { base_fee_per_gas: 3000, reward: 7000, base_fee_per_blob_gas: 3500},
num_blobs: 6,
num_l2_blocks_behind: 0,
should_send: true,
},
Config {
sma_periods: SmaPeriods { short: 2.try_into().unwrap(), long: 6.try_into().unwrap()},
fee_thresholds: FeeThresholds {
max_l2_blocks_behind: 100.try_into().unwrap(),
always_acceptable_fee: 0,
..Default::default()
}
};
"Should send because multiple short-term fees are lower"
)]
#[test_case(
Setup {
Expand Down

0 comments on commit 8b1c861

Please sign in to comment.