Skip to content

Commit 1f2ce74

Browse files
feat: Add clear_db option
If true (default), clears the DB and re syncs from start. If not: - for the ranged test, it skips indexing and uses the current state - for the full test, it starts syncing from the last block in the db #time 18m
1 parent 857040c commit 1f2ce74

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

protocol-testing/Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol-testing/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl FullTestCommand {
5555
args.db_url,
5656
args.rpc_url,
5757
args.vm_simulation_traces,
58-
args.skip_indexing,
58+
args.clear_db,
5959
)?
6060
.run()
6161
}
@@ -83,7 +83,7 @@ impl RangeTestCommand {
8383
args.db_url,
8484
args.rpc_url,
8585
args.vm_simulation_traces,
86-
args.skip_indexing,
86+
args.clear_db,
8787
)?
8888
.run()
8989
}
@@ -122,9 +122,11 @@ struct CommonArgs {
122122
#[arg(long, default_value_t = false)]
123123
execution_traces: bool,
124124

125-
/// Skip indexing and run directly against the database
126-
#[arg(long, default_value_t = false)]
127-
skip_indexing: bool,
125+
/// If true (default), clears the DB and re-syncs from start. If false:
126+
// - for the ranged test, it skips indexing and uses the current state
127+
// - for the full test, it starts syncing from the last block in the db
128+
#[arg(long, default_value_t = true)]
129+
clear_db: bool,
128130
}
129131

130132
impl CommonArgs {

protocol-testing/src/test_runner.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct TestRunner {
9797
runtime: Runtime,
9898
rpc_provider: RPCProvider,
9999
protocol_components: Arc<RwLock<HashMap<String, ProtocolComponentModel>>>,
100-
skip_indexing: bool,
100+
clear_db: bool,
101101
}
102102

103103
impl TestRunner {
@@ -110,7 +110,7 @@ impl TestRunner {
110110
db_url: String,
111111
rpc_url: String,
112112
vm_simulation_traces: bool,
113-
skip_indexing: bool,
113+
clear_db: bool,
114114
) -> miette::Result<Self> {
115115
let base_protocol = CLONE_TO_BASE_PROTOCOL
116116
.get(protocol.as_str())
@@ -150,7 +150,7 @@ impl TestRunner {
150150
adapter_contract_builder,
151151
runtime,
152152
rpc_provider,
153-
skip_indexing,
153+
clear_db,
154154
protocol_components: Arc::new(RwLock::new(HashMap::new())),
155155
})
156156
}
@@ -497,7 +497,7 @@ impl TestRunner {
497497
let tycho_runner = self
498498
.runtime
499499
.block_on(self.tycho_runner(initialized_accounts))?;
500-
if !self.skip_indexing {
500+
if self.clear_db {
501501
let spkg_path = build_spkg(substreams_yaml_path, test.start_block)
502502
.wrap_err("Failed to build spkg")?;
503503
tycho_runner
@@ -511,7 +511,7 @@ impl TestRunner {
511511
)
512512
.wrap_err("Failed to run Tycho")?;
513513
} else {
514-
info!("Skipping indexing")
514+
info!("Skipping indexing and using existent DB")
515515
}
516516
let rpc_server = tycho_runner.start_rpc_server()?;
517517
match self.run_test(test, &config, test.stop_block) {
@@ -638,10 +638,10 @@ impl TestRunner {
638638
}
639639

640640
async fn tycho_runner(&self, initialized_accounts: Vec<String>) -> miette::Result<TychoRunner> {
641-
// If we skip indexing, reuse current db state
642-
if !self.skip_indexing {
641+
// If we want to clear db, reuse current db state
642+
if self.clear_db {
643643
self.empty_database()
644-
.await
644+
.await
645645
.into_diagnostic()
646646
.wrap_err("Failed to empty the database")?;
647647
}

protocol-testing/src/tycho_rpc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ impl TychoClient {
6767
) -> Result<Vec<ProtocolComponent>, RpcError> {
6868
let request = ProtocolComponentsRequestBody::system_filtered(protocol_system, None, chain);
6969

70+
let chunk_size = 100;
7071
let concurrency = 1;
7172

7273
let response = self
7374
.http_client
74-
.get_protocol_components_paginated(&request, None, concurrency)
75+
.get_protocol_components_paginated(&request, Some(chunk_size), concurrency)
7576
.await?;
7677

7778
Ok(response.protocol_components)
@@ -90,7 +91,7 @@ impl TychoClient {
9091
#[allow(clippy::mutable_key_type)]
9192
let res = self
9293
.http_client
93-
.get_all_tokens(chain, min_quality, max_days_since_last_trade, None, concurrency)
94+
.get_all_tokens(chain, min_quality, max_days_since_last_trade, Some(3_000), concurrency)
9495
.await?
9596
.into_iter()
9697
.map(|token| {
@@ -147,11 +148,12 @@ impl TychoClient {
147148
SnapshotParameters::new(chain, protocol_system, components, contract_ids, block_number)
148149
.entrypoints(entrypoints);
149150

151+
let chunk_size = 100;
150152
let concurrency = 1;
151153

152154
let response = self
153155
.http_client
154-
.get_snapshots(&params, None, concurrency)
156+
.get_snapshots(&params, Some(chunk_size), concurrency)
155157
.await?;
156158

157159
Ok(response)

0 commit comments

Comments
 (0)