Skip to content

Commit abf4d2b

Browse files
authored
feat(starfish): improving transaction synchronizer (#8157)
# Description of change In this PR, we improve the transaction synchronizer in Starfish. Main changes: - we join fetching and processing transactions into one method `fetch_and_process_transactions_from_authorities` to reuse this for live and periodic syncing - we make at most one fetch request to a given authority in one call of `fetch_and_process_transactions_from_authorities` - we track the number of concurrent requests to each authority and limit that value using a new struct in synchronizer called `active_requests` - we process transactions after fetching for each authority individually. While this creates much more calls to the core thread, this improves the syncing process significantly since it was slowed down by the slowest response in the previous implementation. Later on we can add one/a few active thread(s) that will take all fetched bytes and process them, removing duplicates and sending processed transactions to the core thread on a regular basis. - we changed some parameters for fetching transactions, but they might require further changes once the protocol is tested on a larger network with longer discrepancies. ## Links to any relevant issues Fixes #8147 ## How the change has been tested - [x] Basic tests (linting, compilation, formatting, unit/integration tests) - [x] Patch-specific tests (correctness, functionality coverage) - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have checked that new and existing unit tests pass locally with my changes ### Release Notes - [x] Protocol: Improvements in Starfish tx synchronizer - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API:
1 parent 0186068 commit abf4d2b

File tree

5 files changed

+540
-450
lines changed

5 files changed

+540
-450
lines changed

crates/starfish/config/src/parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Parameters {
151151

152152
// Maximum number of block headers to fetch per periodic or live sync request.
153153
pub(crate) fn default_max_transactions_per_fetch() -> usize {
154-
if cfg!(msim) { 10 } else { 1000 }
154+
if cfg!(msim) { 10 } else { 100 }
155155
}
156156

157157
pub(crate) fn default_sync_last_known_own_block_timeout() -> Duration {

crates/starfish/config/tests/snapshots/parameters_test__parameters.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ max_forward_time_drift:
1313
nanos: 500000000
1414
max_headers_per_commit_sync_fetch: 1000
1515
max_headers_per_regular_sync_fetch: 100
16-
max_transactions_per_fetch: 1000
16+
max_transactions_per_fetch: 100
1717
sync_last_known_own_block_timeout:
1818
secs: 5
1919
nanos: 0

crates/starfish/core/src/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub(crate) struct NodeMetrics {
165165
pub(crate) transactions_synchronizer_fetched_transactions_by_authority: IntCounterVec,
166166
pub(crate) transactions_synchronizer_missing_transactions_by_authority: IntCounterVec,
167167
pub(crate) transactions_synchronizer_current_missing_transactions_by_authority: IntGaugeVec,
168-
pub(crate) transactions_synchronizer_scheduler_inflight: IntGauge,
168+
pub(crate) transactions_synchronizer_periodic_inflight: IntGauge,
169169
pub(crate) transactions_synchronizer_fetch_latency: HistogramVec,
170170
pub(crate) transactions_synchronizer_success_by_peer: IntCounterVec,
171171
pub(crate) transactions_synchronizer_failure_by_peer: IntCounterVec,
@@ -598,7 +598,7 @@ impl NodeMetrics {
598598
&["authority"],
599599
registry,
600600
).unwrap(),
601-
transactions_synchronizer_scheduler_inflight: register_int_gauge_with_registry!(
601+
transactions_synchronizer_periodic_inflight: register_int_gauge_with_registry!(
602602
"fetch_transactions_scheduler_inflight",
603603
"Designates whether the transaction synchronizer scheduler task to fetch transactions is currently running",
604604
registry,

crates/starfish/core/src/synchronizer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,8 @@ impl<C: NetworkClient, V: BlockVerifier, D: CoreThreadDispatcher> Synchronizer<C
13751375
},
13761376
_ = &mut fetcher_timeout => {
13771377
debug!("Timed out while fetching missing block headers");
1378+
// Drop all pending requests immediately — frees all block guards
1379+
drop(request_futures);
13781380
break;
13791381
}
13801382
}

0 commit comments

Comments
 (0)