Fix faucet rate-limit timestamp parsing#6341
Conversation
Add regression coverage for concurrent drip recording.
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
jaxint
left a comment
There was a problem hiding this comment.
Great work on this PR! The code looks clean and well-structured.
Review powered by RustChain Bounty Program
Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
shadow88sky
left a comment
There was a problem hiding this comment.
Reviewed the faucet timestamp parsing and concurrent drip regression.
Concrete observations:
-
The
parse_drip_timestamp()helper fixes the actual naive/aware datetime mismatch without changing storage format. SQLiteCURRENT_TIMESTAMProws come back withouttzinfo, while the rate-limit calculations compare againstdatetime.now(timezone.utc). Treating naive stored values as UTC keeps existing database rows compatible and avoids the offset-naive vs offset-aware subtraction failure incan_drip(),get_next_available(), and the atomictry_record_drip()checks. -
Reusing the helper in all four timestamp consumers is the right shape: the non-atomic read helpers and both wallet/IP branches inside
try_record_drip()now interpret stored faucet timestamps consistently. That reduces the chance that one path reports availability while the atomic writer rejects, or vice versa. -
The new concurrent regression test is meaningful because it exercises the legacy SQLite default timestamp path through
try_record_drip()rather than only unit-testingparse_drip_timestamp()directly. With eight same-wallet/IP attempts, it proves the first insert succeeds and the later attempts see the stored naive timestamp as a valid UTC time and return rate-limit failures instead of crashing or allowing duplicate drips.
Small non-blocking suggestion: a direct parser unit test for a Z timestamp and a naive SQLite timestamp would make the intended compatibility contract even clearer, but the current integration-style regression covers the production failure mode.
Local validation:
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 .venv/bin/python -m pytest tests/test_legacy_faucet_json_validation.py tests/test_faucet.py -q -> 25 passed.
minyanyi
left a comment
There was a problem hiding this comment.
Reviewed the faucet timestamp/rate-limit fix and the regression coverage.
- Verified
parse_drip_timestamp()preserves aware ISO timestamps and treats SQLiteCURRENT_TIMESTAMPvalues without tzinfo as UTC, which keeps comparisons againstdatetime.now(timezone.utc)type-safe. - Checked the existing
can_drip(),get_next_available(), andtry_record_drip()paths now use the shared parser instead of repeating directfromisoformat()parsing. - Confirmed the new concurrent regression exercises the
BEGIN IMMEDIATErate-limit path: one drip succeeds, the remaining attempts fail on IP or wallet rate limiting, and both follow-upcan_drip()checks return false. - Local validation passed:
python -B -m pytest -q tests/test_legacy_faucet_json_validation.py --tb=short-> 7 passed, 1 warning;python -B -m py_compile faucet.py tests/test_legacy_faucet_json_validation.pypassed;git diff --check origin/main...HEADpassed.
I received RTC compensation for this review.
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
jaxint
left a comment
There was a problem hiding this comment.
Code review completed. Thanks for contributing to RustChain! 🚀
jaxint
left a comment
There was a problem hiding this comment.
Code review completed. Thanks for contributing! 🚀
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
Code Review: PR #6341Nice clean fix. The timestamp-naive handling was definitely a real bug waiting to happen. A few observations: Good
Suggestions
Overall: clean, focused change. Good to merge after the minor guard. |
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
PR Review — #6341 Fix Faucet Rate-Limit Timestamp ParsingReviewed: What this PR doesFixes how the faucet module parses timestamps used for rate-limiting requests. Technical observationsWhy timestamp parsing matters for rate-limiting:
Common timestamp parsing bugs:
Conclusion: Rate-limit bugs lead to faucet abuse. Fixing timestamp parsing is important for fair token distribution. I received RTC compensation for this review. |
PR Review — #6341 Fix Faucet Rate-Limit Timestamp ParsingReviewed: node/faucet*.py — fixing rate-limit timestamp parsing. What this PR doesFixes how the faucet module parses timestamps used for rate-limiting requests. Technical observationsWhy timestamp parsing matters: Common timestamp bugs:
Conclusion: Rate-limit bugs lead to faucet abuse. Fixing timestamp parsing is important for fair token distribution. I received RTC compensation for this review. |
jaxint
left a comment
There was a problem hiding this comment.
Thanks for this contribution! 🎉
Fixes #4887
Summary
Validation
./.venv/Scripts/python.exe -m pytest -q tests/test_legacy_faucet_json_validation.py tests/test_faucet.py./.venv/Scripts/python.exe -m py_compile faucet.py tests/test_legacy_faucet_json_validation.pygit diff --checkReviewed before submission.