From 9f9de0fab96712761944806120b1764cf1bee0eb Mon Sep 17 00:00:00 2001 From: Delweng Date: Tue, 15 Oct 2024 01:24:20 +0800 Subject: [PATCH] fix(rpc/trace): return empty if after >= traces (#11715) Signed-off-by: jsvisa Co-authored-by: Matthias Seitz --- crates/rpc/rpc/src/trace.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/rpc/rpc/src/trace.rs b/crates/rpc/rpc/src/trace.rs index 05588d4dabea..0cd94ef15b89 100644 --- a/crates/rpc/rpc/src/trace.rs +++ b/crates/rpc/rpc/src/trace.rs @@ -322,13 +322,18 @@ where } } - // apply after and count to traces if specified, this allows for a pagination style. - // only consider traces after - if let Some(after) = after.map(|a| a as usize).filter(|a| *a < all_traces.len()) { - all_traces = all_traces.split_off(after); + // Skips the first `after` number of matching traces. + // If `after` is greater than or equal to the number of matched traces, it returns an empty + // array. + if let Some(after) = after.map(|a| a as usize) { + if after < all_traces.len() { + all_traces.drain(..after); + } else { + return Ok(vec![]) + } } - // at most, return count of traces + // Return at most `count` of traces if let Some(count) = count { let count = count as usize; if count < all_traces.len() {