-
Notifications
You must be signed in to change notification settings - Fork 2k
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
don't increment counters for outgoing messages blocked by the rate limit #3518
Conversation
bf4d609
to
c3de1da
Compare
…mit. This was causing a problem where outbound messages, blocked by the rate limiter, would still increment the counters as-if they had been sent. This, in turn, could cause other message types to get blocked becuase the rate limiter thought we had sent a lot of the other (blocked) message type.
@@ -116,7 +133,7 @@ def process_msg_and_check(self, message: Message) -> bool: | |||
Returns True if message can be processed successfully, false if a rate limit is passed. | |||
""" | |||
|
|||
current_minute = time.time() // self.reset_seconds | |||
current_minute = int(time.time() // self.reset_seconds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason, integer division returns a float (according to mypy)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because //
is really floor( div (x) )
new_cumulative_size: int = self.message_cumulative_sizes[message_type] + len(message.data) | ||
new_non_tx_count: int = self.non_tx_message_counts | ||
new_non_tx_size: int = self.non_tx_cumulative_size | ||
proportion_of_limit: float = self.percentage_of_limit / 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the key part of this patch. Rather than updating the counters immediately, compute the new counters if this message were to be sent. Check rates against these counters and if we end up accepting sending the message, then commit the new values to the counters (see the finally
block)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would make a kick ass comment, as it perfectly describes the intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping the comment in the finally
block would suffice
ret = True | ||
return True | ||
finally: | ||
if self.incoming or ret: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only commit the new counters if we're returning True
or if this was an incoming rate limiter, and we already received the message. In the latter case we should always increment the counters.
@@ -217,3 +217,49 @@ async def test_percentage_limits(self): | |||
if not response: | |||
saw_disconnect = True | |||
assert saw_disconnect | |||
|
|||
@pytest.mark.asyncio | |||
async def test_too_many_outgoing_messages(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two tests demonstrate the problem. Prior to this patch, we would have the "incoming" behavior in both cases, both incoming and outgoing messages.
else: | ||
blocked += 1 | ||
|
||
assert passed == 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is passed == 10 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, the rate limit for this type of message is 10 (per the unit of time specified in the RateLimit
constructor)
* 2 harvesting features (#3331) * 3 harvesting features: - Debug level shows the time for every quality lookup - Warning level if takes longer than 5 seconds - Allow configuration of plot loading interval (default 2 minutes) * Comment out super logging * Improve wallet consistency (#3305) * Improve wallet consistency * Improve CLI significantly, and fix self-tx balances * Fix await * Fix deadlock and test * Remove spam.sh * Changelog for 1.1.3 (#3345) * Changelog for 1.1.3 * minor updates * updates part 3 * Those engineers who don't update changelogs... :) * Apologies to @Chida82 who added log rotate count! (#3369) * Rust parse serialized (#3444) * use rust implementation for finding length of a serialized clvm program * bump clvm_rs version * Don't retry respond_peers message (#3508) * don't increment counters for outgoing messages blocked by the rate limit. (#3518) This was causing a problem where outbound messages, blocked by the rate limiter, would still increment the counters as-if they had been sent. This, in turn, could cause other message types to get blocked becuase the rate limiter thought we had sent a lot of the other (blocked) message type. Co-authored-by: Mariano Sorgente <3069354+mariano54@users.noreply.github.com> Co-authored-by: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Co-authored-by: Arvid Norberg <arvid@libtorrent.org>
* 2 harvesting features (#3331) * 3 harvesting features: - Debug level shows the time for every quality lookup - Warning level if takes longer than 5 seconds - Allow configuration of plot loading interval (default 2 minutes) * Comment out super logging * Improve wallet consistency (#3305) * Improve wallet consistency * Improve CLI significantly, and fix self-tx balances * Fix await * Fix deadlock and test * Remove spam.sh * Changelog for 1.1.3 (#3345) * Changelog for 1.1.3 * minor updates * updates part 3 * Those engineers who don't update changelogs... :) * Apologies to @Chida82 who added log rotate count! (#3369) * Rust parse serialized (#3444) * use rust implementation for finding length of a serialized clvm program * bump clvm_rs version * Don't retry respond_peers message (#3508) * don't increment counters for outgoing messages blocked by the rate limit. (#3518) This was causing a problem where outbound messages, blocked by the rate limiter, would still increment the counters as-if they had been sent. This, in turn, could cause other message types to get blocked becuase the rate limiter thought we had sent a lot of the other (blocked) message type. * hide secret wallet key by default with 'chia keys show' (#3565) Co-authored-by: Adam Kelly <aqk@aqk.im> Co-authored-by: Mariano Sorgente <3069354+mariano54@users.noreply.github.com> Co-authored-by: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Co-authored-by: Arvid Norberg <arvid@libtorrent.org> Co-authored-by: Adam Kelly <338792+aqk@users.noreply.github.com> Co-authored-by: Adam Kelly <aqk@aqk.im>
* 2 harvesting features (#3331) * 3 harvesting features: - Debug level shows the time for every quality lookup - Warning level if takes longer than 5 seconds - Allow configuration of plot loading interval (default 2 minutes) * Comment out super logging * Improve wallet consistency (#3305) * Improve wallet consistency * Improve CLI significantly, and fix self-tx balances * Fix await * Fix deadlock and test * Remove spam.sh * Changelog for 1.1.3 (#3345) * Changelog for 1.1.3 * minor updates * updates part 3 * Those engineers who don't update changelogs... :) * Apologies to @Chida82 who added log rotate count! (#3369) * Rust parse serialized (#3444) * use rust implementation for finding length of a serialized clvm program * bump clvm_rs version * Don't retry respond_peers message (#3508) * don't increment counters for outgoing messages blocked by the rate limit. (#3518) This was causing a problem where outbound messages, blocked by the rate limiter, would still increment the counters as-if they had been sent. This, in turn, could cause other message types to get blocked becuase the rate limiter thought we had sent a lot of the other (blocked) message type. * hide secret wallet key by default with 'chia keys show' (#3565) Co-authored-by: Adam Kelly <aqk@aqk.im> * brake if end of ses list (#3583) * brake if end of ses list * log * throw if wp peak is not heavier * comment * handle sync from scratch * comment Co-authored-by: Mariano Sorgente <3069354+mariano54@users.noreply.github.com> Co-authored-by: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Co-authored-by: Arvid Norberg <arvid@libtorrent.org> Co-authored-by: Adam Kelly <338792+aqk@users.noreply.github.com> Co-authored-by: Adam Kelly <aqk@aqk.im> Co-authored-by: Almog De Paz <almogdepaz@gmail.com>
* 2 harvesting features (#3331) * 3 harvesting features: - Debug level shows the time for every quality lookup - Warning level if takes longer than 5 seconds - Allow configuration of plot loading interval (default 2 minutes) * Comment out super logging * Improve wallet consistency (#3305) * Improve wallet consistency * Improve CLI significantly, and fix self-tx balances * Fix await * Fix deadlock and test * Remove spam.sh * Changelog for 1.1.3 (#3345) * Changelog for 1.1.3 * minor updates * updates part 3 * Those engineers who don't update changelogs... :) * Apologies to @Chida82 who added log rotate count! (#3369) * Rust parse serialized (#3444) * use rust implementation for finding length of a serialized clvm program * bump clvm_rs version * Don't retry respond_peers message (#3508) * don't increment counters for outgoing messages blocked by the rate limit. (#3518) This was causing a problem where outbound messages, blocked by the rate limiter, would still increment the counters as-if they had been sent. This, in turn, could cause other message types to get blocked becuase the rate limiter thought we had sent a lot of the other (blocked) message type. * hide secret wallet key by default with 'chia keys show' (#3565) Co-authored-by: Adam Kelly <aqk@aqk.im> * brake if end of ses list (#3583) * brake if end of ses list * log * throw if wp peak is not heavier * comment * handle sync from scratch * comment * fix indentation issue in message send retry logic. factor out retry coroutine (#3629) * Fix test (#3350) * Mempool sorting and accept reverted pending transactions (#3683) * Sort by fee/cost, and fix pending tx issue in reorgs * Fix test name * Bring the seen list size back to normal. Co-authored-by: Mariano Sorgente <3069354+mariano54@users.noreply.github.com> Co-authored-by: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Co-authored-by: Arvid Norberg <arvid@libtorrent.org> Co-authored-by: Adam Kelly <338792+aqk@users.noreply.github.com> Co-authored-by: Adam Kelly <aqk@aqk.im> Co-authored-by: Almog De Paz <almogdepaz@gmail.com>
This is best reviewed with white space changed hidden, as there's indentation changes.
This was causing a problem where outbound messages, blocked by the rate limiter,
would still increment the counters as-if they had been sent. This, in turn,
could cause other message types to get blocked becuase the rate limiter thought
we had sent a lot of the other (blocked) message type.