Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc-v2: Limit transactionBroadcast calls to 16 #3772

Merged
merged 19 commits into from
Apr 19, 2024
Merged

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Mar 20, 2024

This PR limits the number of active calls to the transactionBroadcast APIs to 16.

cc @paritytech/subxt-team

Closes: #3081

@lexnv lexnv added A1-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). R0-silent Changes should not be mentioned in any release notes I5-enhancement An additional feature request. D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. labels Mar 20, 2024
@lexnv lexnv self-assigned this Mar 20, 2024
Base automatically changed from lexnv/single-chain-head-connection to master April 2, 2024 13:45
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
lexnv and others added 4 commits April 2, 2024 20:19
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This reverts commit c447ac2.

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv changed the title rpc-v2: Limit number of transaction and transactionBroadcast calls rpc-v2: Limit number transactionBroadcast calls to 4 Apr 9, 2024
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv changed the title rpc-v2: Limit number transactionBroadcast calls to 4 rpc-v2: Limit transactionBroadcast calls to 4 Apr 9, 2024
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Comment on lines +144 to +146
let mut best_block_import_stream: std::pin::Pin<
Box<dyn Stream<Item = <Pool::Block as BlockT>::Hash> + Send>,
> =
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why this type annotation needed adding!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an edge-case in the rust compiler, where the rustc cannot deduce the type of this stream.

I'm not entirely sure what is happening behind the scenes, I expect the async block cannot be properly deduced here.

The error I get is:

error[E0308]: mismatched types
   --> substrate/client/rpc-spec-v2/src/transaction/transaction_broadcast.rs:222:3
    |
146 |                 |notification| async move { notification.is_new_best.then_some(notification.hash) },
    |                                --------------------------------------------------------------------
    |                                |
    |                                the expected `async` block
    |                                the found `async` block
...
222 |         sc_rpc::utils::spawn_subscription_task(&self.executor, fut);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
    = note: expected `async` block `{async block@substrate/client/rpc-spec-v2/src/transaction/transaction_broadcast.rs:146:20: 146:88}`
               found `async` block `{async block@substrate/client/rpc-spec-v2/src/transaction/transaction_broadcast.rs:146:20: 146:88}`
note: the lifetime requirement is introduced here
   --> /home/lexnv/workspace/polkadot-sdk/substrate/client/rpc/src/utils.rs:178:34
    |
178 |     fut: impl Future<Output = ()> + Send + 'static,
    |                                     ^^^^

For more information about this error, try `rustc --explain E0308`.

Copy link
Contributor

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

A couple of small nits but all makes sense to me!

I don't mind the limit being 4 just to exercise clients and nudge them to be able to handle a max of 4, but for most other cases I wonder what an actually sensible limit would be here

…cast.rs

Co-authored-by: James Wilson <james@jsdw.me>
@github-actions github-actions bot requested a review from jsdw April 16, 2024 09:39
Copy link

Review required! Latest push from author must always be reviewed

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv changed the title rpc-v2: Limit transactionBroadcast calls to 4 rpc-v2: Limit transactionBroadcast calls to 16 Apr 16, 2024
&self,
connection_details: ConnectionDetails,
bytes: Bytes,
) -> RpcResult<Option<String>> {
Copy link
Member

@niklasad1 niklasad1 Apr 17, 2024

Choose a reason for hiding this comment

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

we could probably change the return type Option<String> because this error is never used by the impl

however, https://github.com/paritytech/jsonrpsee/blob/master/core/src/server/mod.rs#L153-#L171 IntoResponse is not implemented for Option<String> so never mind.

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv enabled auto-merge April 18, 2024 11:05
@lexnv lexnv disabled auto-merge April 18, 2024 13:23
@lexnv lexnv enabled auto-merge April 18, 2024 13:24
@lexnv lexnv added this pull request to the merge queue Apr 18, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Apr 18, 2024
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv added this pull request to the merge queue Apr 19, 2024
Merged via the queue into master with commit 98a364f Apr 19, 2024
134 of 137 checks passed
@lexnv lexnv deleted the lexnv/limit-rpc-apis branch April 19, 2024 04:59
github-merge-queue bot pushed a commit that referenced this pull request Apr 19, 2024
This PR stabilizes the txBroadcast API to version 1.

Ideally needs:
- #4050
- #3772

cc @paritytech/subxt-team

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A1-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. I5-enhancement An additional feature request. R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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