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

Stop accepting transactions when number of delayed receipts is large #9222

Merged
merged 14 commits into from
Jul 27, 2023

Conversation

akashin
Copy link
Collaborator

@akashin akashin commented Jun 20, 2023

This PR introduces a soft limit on the number of delayed receipts in each shard. The limit is around 20000 delayed receipts to make sure this is enough to saturate the capacity of two chunks even if receipts are very small. The largest number of delayed receipts that we've seen in the last 3 months is around 400 and it stays at 0 most of the time.

In the future, we would be also using other signals like the size of delayed receipts, but this information will have to be first computed and stored in the chunk headers/trie store and will be done in #9228.

Addresses: #8877

@akashin akashin force-pushed the delayed_receipts_limit branch 3 times, most recently from 3e38b3f to 3e15d78 Compare June 21, 2023 14:08
@akashin akashin changed the title WIP: Stop accepting transactions when number of delayed receipts is large Stop accepting transactions when number of delayed receipts is large Jul 24, 2023
@akashin akashin marked this pull request as ready for review July 24, 2023 15:16
@akashin akashin requested a review from a team as a code owner July 24, 2023 15:16
@akashin akashin self-assigned this Jul 24, 2023
Copy link
Contributor

@robin-near robin-near left a comment

Choose a reason for hiding this comment

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

This looks good, but how do we test this stuff?

@akashin
Copy link
Collaborator Author

akashin commented Jul 25, 2023

This looks good, but how do we test this stuff?

I did test this with the Locust congestion workload with a much smaller limit of 50 receipts and didn't see any difference in the throughput of the system.

The limit set in the PR most likely will be effective only against non-adverserial receipts as it is based on the count, not on size or gas, but we have to start somewhere.

@robin-near
Copy link
Contributor

I guess I mean, we ideally should have some automated test coverage. Would it be much additional work to introduce a setting and then write a test against a very small limit?

// a bound of at most 10000 receipts processed in a chunk.
let delayed_receipts_indices: DelayedReceiptIndices =
near_store::get(&state_update, &TrieKey::DelayedReceiptIndices)?.unwrap_or_default();
let min_fee = runtime_config.fees.fee(ActionCosts::new_action_receipt).exec_fee();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the correct fee to look at, it's what an empty receipt would cost to execute. (Today, one can submit receipts with an empty action list. Probably we shouldn't allow it as it's useless for users. The smallest gas consumption of a useful receipt would be that of a transfer, which adds another 115 Ggas, so it would give us a factor of ~2 here.)

Anyway, back to the topic :)
I'm not sure if it's a good pattern to use config parameters in the actual code. We are doing it quite a bit, best example is a few lines below where we use storage_write_value_byte to limit the tx sizes. But it means changing those parameter values has sometimes unexpected effect on other parts of the code.

If it wasn't for the existing pattern, I'd say we should either use a hard-coded constant or add a new parameter. Where would we add the parameter? I'd probably put it in config.json. But hard coding it seems fine too.

But because we have precedence, I am also completely okay with this as it is. I'll let you decide with what you want to go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with you that these unexpected dependencies on config parameters make code more complex. However, I think we do have this dependency even if we use a constant/new parameter here (as the chosen value need to take into account gas parameters) - it is just tracked more implicitly and not in the code. In the near future, we plan for this limit to be enforced by the protocol (at least the upper bound), so it can't be a part of the per-node config either.

@akashin
Copy link
Collaborator Author

akashin commented Jul 27, 2023

I guess I mean, we ideally should have some automated test coverage. Would it be much additional work to introduce a setting and then write a test against a very small limit?

It took me some effort, but I think I managed to come up with a test that is not fragile. I also rewrote the refunds test to be less fragile. PTAL

@akashin akashin added S-automerge A-congestion Work aimed at ensuring good system performance under congestion labels Jul 27, 2023
@near-bulldozer near-bulldozer bot merged commit 661ea24 into near:master Jul 27, 2023
1 check passed
nikurt pushed a commit that referenced this pull request Jul 28, 2023
…9222)

This PR introduces a soft limit on the number of delayed receipts in each shard. The limit is around 10000 delayed receipts to make sure this is enough to saturate the chunk capacity even if receipts are very small. The largest number of delayed receipts that we've seen in the last 3 months is around 400 and it stays at 0 most of the time.

In the future, we would be also using other signals like the size of delayed receipts, but this information will have to be first computed and stored in the chunk headers/trie store and will be done in #9228.

Addresses: #8877
nikurt pushed a commit that referenced this pull request Aug 24, 2023
…9222)

This PR introduces a soft limit on the number of delayed receipts in each shard. The limit is around 10000 delayed receipts to make sure this is enough to saturate the chunk capacity even if receipts are very small. The largest number of delayed receipts that we've seen in the last 3 months is around 400 and it stays at 0 most of the time.

In the future, we would be also using other signals like the size of delayed receipts, but this information will have to be first computed and stored in the chunk headers/trie store and will be done in #9228.

Addresses: #8877
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Aug 24, 2023
…ear#9222)

This PR introduces a soft limit on the number of delayed receipts in each shard. The limit is around 10000 delayed receipts to make sure this is enough to saturate the chunk capacity even if receipts are very small. The largest number of delayed receipts that we've seen in the last 3 months is around 400 and it stays at 0 most of the time.

In the future, we would be also using other signals like the size of delayed receipts, but this information will have to be first computed and stored in the chunk headers/trie store and will be done in near#9228.

Addresses: near#8877
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-congestion Work aimed at ensuring good system performance under congestion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants