Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

chainHead: Limit ongoing operations #14699

Merged
merged 28 commits into from
Aug 15, 2023
Merged

chainHead: Limit ongoing operations #14699

merged 28 commits into from
Aug 15, 2023

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Aug 2, 2023

This PR adds support for limiting the number of ongoing operations:

  • at most 16 operations can be executed by a chainHead_follow subscription (items in chainHead_storage count each as a operation)
  • methods return limitReached when capacity cannot be reserved (or subscription ID is invalid or stale)
  • chainHead_storage discards elements when there's not enough capacity
  • struct ChainHeadConfig is added to have granular control over the limits of the API
  • reserving capacity and permits is a slim wrapper over Arc<Mutex<usize>> with a configurable maximum and a RAII style release of capacity on drop
  • the capacity permit is propagated to the BlockGuard
  • unit-test for low-level OngoingOperations and PermitOperations
  • integration-test for limit propagation to methods via ensure_operation_limits_works()

This builds on top of: #14692
Closes: #14640

// @paritytech/subxt-team

lexnv added 19 commits July 31, 2023 18:54
@lexnv lexnv added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit B1-note_worthy Changes should be noted in the release notes T2-API This PR/Issue is related to APIs. labels Aug 2, 2023
@lexnv lexnv self-assigned this Aug 2, 2023
Base automatically changed from lexnv/chainhead_extend_resp to master August 8, 2023 18:13
@lexnv
Copy link
Contributor Author

lexnv commented Aug 10, 2023

bot rebase

@paritytech-processbot
Copy link

Rebased

Copy link
Contributor

@skunert skunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Only some small comments.

client/rpc-spec-v2/src/chain_head/subscription/inner.rs Outdated Show resolved Hide resolved
@lexnv lexnv merged commit a79a2af into master Aug 15, 2023
3 checks passed
@lexnv lexnv deleted the lexnv/chainhead_limits branch August 15, 2023 12:17
Ank4n pushed a commit that referenced this pull request Aug 20, 2023
* chainHead/api: Make storage/body/call pure RPC methods

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Add mpsc channel between RPC methods

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/subscriptions: Extract mpsc::Sender via BlockGuard

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/subscriptions: Generate and provide the method operation ID

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Generate `chainHead_body` response

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Generate `chainHead_call` response

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Generate `chainHead_storage` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Propagate responses of methods to chainHead_follow

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust `chainHead_body` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust `chainHead_call` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust `chainHead_call` responses

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Ensure unique operation IDs across methods

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/events: Remove old method events

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/subscriptions: Add limit helper

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/subscription: Expose limits to `BlockGuard`

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust testing to ongoing operations

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Make limits configurable via `ChainHeadConfig`

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Adjust testing to `ChainHeadConfig`

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/tests: Ensure operation limits discards items

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Improve documentation

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Rename `OngoingOperations` -> `LimitOperations`

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Rename reserve -> reserve_at_most

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead: Use duration const instead of u64

Signed-off-by: Alexandru Vasile <[email protected]>

* chainHead/subscription: Use tokio::sync::Semaphore for limits

Signed-off-by: Alexandru Vasile <[email protected]>

* Update client/rpc-spec-v2/src/chain_head/subscription/inner.rs

Co-authored-by: Sebastian Kunert <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: parity-processbot <>
Co-authored-by: Sebastian Kunert <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T2-API This PR/Issue is related to APIs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RPC-Spec-V2] Limit ongoing operations
3 participants