Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces adaptive batch sizing for the relayer's block submission process, implementing an AIMD (Additive Increase, Multiplicative Decrease) strategy combined with proactive gas-based sizing. Instead of using fixed batch sizes from configuration, the relayer now dynamically adjusts the number of blocks per transaction based on observed gas consumption and error feedback from the NEAR network.
Changes:
- Added a new
AdaptiveBatchSizermodule that dynamically adjusts submit batch size and fetch size based on gas telemetry and gas-exceeded errors, using AIMD with configurable cooldown periods. - Modified
NearClient::submit_blocksto return aSubmitResultwith gas telemetry and detect "gas exceeded" errors as a newCustomError::GasExceededvariant. - Updated configuration to support new
min_batch_sizeandbatch_size_cooldown_secparameters, and changedsubmit_batch_sizetype fromusizetou64.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
relayer/src/adaptive_batch.rs |
New module implementing AdaptiveBatchSizer with AIMD algorithm, gas-based sizing, and comprehensive unit tests. |
relayer/src/near_client.rs |
Added GasExceeded error variant, SubmitResult struct with gas telemetry, and updated response parsing to extract gas metrics. |
relayer/src/main.rs |
Integrated AdaptiveBatchSizer into Synchronizer, using dynamic batch/fetch sizes and handling GasExceeded errors. |
relayer/src/config.rs |
Added min_batch_size and batch_size_cooldown_sec config fields, changed submit_batch_size to u64. |
relayer/src/lib.rs |
Exported the new adaptive_batch module. |
relayer/config.toml.example |
Added default values for new config parameters. |
relayer/configs/btc_testnet.toml |
Added new adaptive batch config settings. |
relayer/configs/btc_mainnet.toml |
Added new adaptive batch config settings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
c3895c3 to
884bc49
Compare
| impl AdaptiveBatchSizer { | ||
| /// Create a new `AdaptiveBatchSizer` from config. | ||
| /// | ||
| /// `num_parallel_txs` (N) is computed as `config.fetch_batch_size / config.submit_batch_size` |
There was a problem hiding this comment.
I wonder if the opposite approach is clearer? submit_batch_size and num_parallel_txs are chosen parameters and fetch size is derived
There was a problem hiding this comment.
I see it's the current behavior so it's okay not to change
| } | ||
| } | ||
|
|
||
| /// Current submit batch size. |
There was a problem hiding this comment.
Such comments don't really say anything
| 'main_loop: loop { | ||
| let (current_fetch_size, current_batch_size) = { | ||
| let mut sizer = self.batch_sizer.lock().await; | ||
| sizer.try_recover(); |
There was a problem hiding this comment.
I don't get why try_recover is needed if we straight up calculate the optimal batch size on successful submission?
No description provided.