-
Notifications
You must be signed in to change notification settings - Fork 1.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
backport: Merge bitcoin/bitcoin#23418, 25144, 25480, 25492 #6519
base: develop
Are you sure you want to change the base?
Conversation
ecb05bf
to
fb70100
Compare
a2257de
to
3941a52
Compare
f391a48
to
fea3f61
Compare
…tion RPC fa07f84 Fix signed integer overflow in prioritisetransaction RPC (MarcoFalke) fa52cf8 refactor: Replace feeDelta by m_modified_fee (MarcoFalke) Pull request description: Signed integer overflow is UB in theory, but not in practice. Still, it would be nice to avoid this UB to allow Bitcoin Core to be compiled with sanitizers such as `-ftrapv` or ubsan. It is impossible to predict when and if an overflow occurs, since the overflow caused by a prioritisetransaction RPC might only be later hit when descendant txs are added to the mempool. Since it is impossible to predict reliably, leave it up to the user to use the RPC endpoint responsibly, considering their mempool limits and usage patterns. Fixes: bitcoin#20626 Fixes: bitcoin#20383 Fixes: bitcoin#19278 Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34146 / https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47132 ## Steps to reproduce Build the code without the changes in this pull. Make sure to pass the sanitizer flag: ``` ./autogen.sh && ./configure --with-sanitizers=signed-integer-overflow && make clean && make -j $(nproc) ``` ### Reproduce on RPC ``` ./src/bitcoind -chain=regtest -noprinttoconsole & ./src/bitcoin-cli -chain=regtest prioritisetransaction 00000000deadbeef00000000deadbeef00000000deadbeef00000000deadbeef 0 9123456789123456789 ./src/bitcoin-cli -chain=regtest prioritisetransaction 00000000deadbeef00000000deadbeef00000000deadbeef00000000deadbeef 0 9123456789123456789 |> txmempool.cpp:920:15: runtime error: signed integer overflow: 9123456789123456789 + 9123456789123456789 cannot be represented in type 'long int' ./src/bitcoin-cli -chain=regtest stop ``` ### By fuzzing ``` wget https://github.com/bitcoin/bitcoin/files/8921302/clusterfuzz-testcase-minimized-validation_load_mempool-5599531390074880.bin.txt FUZZ=validation_load_mempool ./src/test/fuzz/fuzz ./clusterfuzz-testcase-minimized-validation_load_mempool-5599531390074880.bin.txt |> txmempool.cpp:920:15: runtime error: signed integer overflow: 7214801925397553184 + 2314885530818453536 cannot be represented in type 'long int' |> validation_load_mempool: succeeded against 1 files in 0s. ACKs for top commit: vasild: ACK fa07f84 dunxen: ACK fa07f84 LarryRuane: ACK fa07f84 Tree-SHA512: 4a357950af55a49c9113da0a50c2e743c5b752f0514dd8d16cd92bfde2f77dd0ef56aa98452626df6f7f7a5b51d1227021f6bc94091201a179f0d488ee32a0df
7227b85
to
4bf1a22
Compare
fa8aa0a Pass Peer& to Misbehaving() (MacroFake) Pull request description: `Misbehaving` has several coding related issues (ignoring the conceptual issues here for now): * It is public, but it is not supposed to be called from outside of net_processing. Fix that by making it private and creating a public `UnitTestMisbehaving` method for unit testing only. * It doesn't do anything if a `nullptr` is passed. It would be less confusing to just skip the call instead. Fix that by passing `Peer&` to `Misbehaving()`. * It calls `GetPeerRef`, causing `!m_peer_mutex` lock annotations to be propagated. This is harmless, but verbose. Fix it by removing the no longer needed call to `GetPeerRef` and the no longer needed lock annotations. ACKs for top commit: vasild: ACK fa8aa0a w0xlt: Code Review ACK bitcoin@fa8aa0a Tree-SHA512: e60a6b317f2b826f9e0724285d00b632d3e2a91ded9fa5ba01c80766c5d39270b719be234c01302d46eaba600910032693836aa116ff05ee1b590c7530881cd3
…ble> fa956e7 Replace CountSecondsDouble with Ticks<SecondsDouble> (MacroFake) Pull request description: Seems odd to have two ways to say exactly the same thing when one is sufficient. ACKs for top commit: fanquake: ACK fa956e7 shaavan: ACK fa956e7 w0xlt: ACK bitcoin@fa956e7 Tree-SHA512: b599470e19b693da1ed1102d1e86b08cb03adaddf2048752b6d050fdf86055be117ff0ae10b6953d03e00eaaf7b0cfa350137968b67d6c5b3ca68c5aa50ca6aa
d8f8f78 util: remove MSVC warning pragmas (fanquake) Pull request description: 4786 - I don't think this exists any more? 4805 - Is already defined (globally) there. Dropped 4717 and 4804, as it seems they are no-longer supressing anything. See: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-c4000-c5999. ACKs for top commit: hebasto: ACK d8f8f78, build [log](https://api.cirrus-ci.com/v1/task/6088784285532160/logs/build.log) is free of warnings. Tree-SHA512: c8ac4585799996960ea099b2c5337e7bb577152eec2e9543cc459c56f42f7a36fc4dcd7faec2fa4ac159a4ae27859650ccfd96bbf94b94dbd1cbea638560a24f
4bf1a22
to
3847b1a
Compare
WalkthroughThe pull request introduces a series of modifications across multiple files in the codebase, focusing on three primary areas: peer management, transaction memory pool handling, and testing infrastructure. The changes include refactoring the misbehavior tracking mechanism in peer management, updating fee calculation methods in the transaction memory pool, and removing specific compiler warning suppressions. The peer management changes involve replacing the These modifications aim to improve code clarity, testing capabilities, and potentially address specific performance or safety considerations in the system's core components. Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/rpc/net.cpp (1)
231-231
: LGTM: Completed modernization of time handlingThe change completes the consistent update of time handling across all ping-related measurements.
These changes are part of a broader improvement in time handling across the codebase, moving towards type-safe chrono-based time calculations. This reduces the risk of time-related bugs and improves code maintainability.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
src/llmq/dkgsessionhandler.cpp
(1 hunks)src/llmq/instantsend.cpp
(1 hunks)src/llmq/signing.cpp
(1 hunks)src/llmq/signing_shares.cpp
(1 hunks)src/net_processing.cpp
(27 hunks)src/net_processing.h
(1 hunks)src/rpc/net.cpp
(1 hunks)src/test/denialofservice_tests.cpp
(4 hunks)src/txmempool.cpp
(7 hunks)src/txmempool.h
(2 hunks)src/util/system.cpp
(0 hunks)src/util/time.h
(0 hunks)test/sanitizer_suppressions/ubsan
(1 hunks)
💤 Files with no reviewable changes (2)
- src/util/time.h
- src/util/system.cpp
✅ Files skipped from review due to trivial changes (1)
- src/llmq/signing_shares.cpp
🔇 Additional comments (31)
src/rpc/net.cpp (3)
225-225
: LGTM: Improved time handling using modern C++ chronoThe change from
CountSecondsDouble
toTicks<SecondsDouble>
represents a move towards more type-safe time handling using the C++ chrono library.
228-228
: LGTM: Consistent time handling for minimum ping timeThe change maintains consistency with the modern time handling approach.
225-231
: Verify complete migration of time handling methodsLet's verify that all instances of
CountSecondsDouble
have been migrated to the newTicks<SecondsDouble>
approach in the codebase.✅ Verification successful
Time handling migration successfully completed
The codebase shows complete adoption of
Ticks<SecondsDouble>
with no remaining instances ofCountSecondsDouble
, confirming successful migration of the time handling methods.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining instances of CountSecondsDouble echo "Checking for remaining CountSecondsDouble usage..." rg "CountSecondsDouble" --type cpp # Search for consistent usage of Ticks<SecondsDouble> echo "Verifying Ticks<SecondsDouble> usage..." rg "Ticks<SecondsDouble>" --type cppLength of output: 685
src/txmempool.cpp (5)
104-104
: LGTM: Member variable initializationThe initialization of
m_modified_fee
withnFee
in the constructor is correct and matches the new fee handling approach.
458-458
: LGTM: Consistent use of SaturatingAdd for fee updatesThe use of
SaturatingAdd
is consistently applied to both descendant and ancestor fee updates, maintaining the overflow protection throughout the codebase.Also applies to: 467-467
1465-1468
: LGTM: Fee delta handling with overflow protectionThe changes correctly apply
SaturatingAdd
to fee delta calculations and properly update the modified fees through the mempool entry modification mechanism.
515-516
: Verify assumption about fee modification stateThe code assumes that the initial fee matches the modified fee. While this is likely true for new entries, we should verify this assumption holds in all code paths.
✅ Verification successful
Assumption about fee modification state is valid
The assumption is correct by design. The code makes this assertion right after inserting a new entry and applying any potential fee delta from PrioritiseTransaction, which are the only two operations that could affect the fees at this point.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Look for places where fees might be modified before reaching this point rg -B 5 'GetModifiedFee|UpdateModifiedFee' src/Length of output: 9042
112-116
: Verify overflow protection in fee updatesThe use of
SaturatingAdd
for fee updates provides protection against integer overflow, which is important for fee calculations. The changes look correct but we should verify that all fee-related calculations are consistently using this protection.✅ Verification successful
Fee calculations have appropriate overflow protection
The codebase consistently uses proper overflow protection for fee calculations:
- Consensus-critical paths validate fees using
MoneyRange
checks- Memory pool modifications use
SaturatingAdd
- Transaction validation enforces fee range limits
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for any remaining direct fee additions that might need overflow protection rg -A 2 '\+= .*[Ff]ee' src/Length of output: 4250
Script:
#!/bin/bash # Check for MoneyRange usage near fee calculations rg -B 2 -A 2 'MoneyRange.*fee|fee.*MoneyRange' src/ # Check for other potential overflow protections rg -B 2 -A 2 'Saturating(Add|Sub).*fee|fee.*Saturating(Add|Sub)' src/Length of output: 2694
src/net_processing.cpp (11)
635-635
: LGTM: Unit test misbehavior handlingThe
UnitTestMisbehaving
method provides a clean way to test misbehavior handling in unit tests while maintaining encapsulation of the actual implementation.
676-681
: Improved misbehavior tracking with peer referenceThe new
Misbehaving
method signature usingPeer&
provides better encapsulation and direct access to peer state. This change improves code organization and maintainability.
740-740
: LGTM: Updated SendBlockTransactions signatureThe addition of the
Peer&
parameter toSendBlockTransactions
aligns with the pattern of direct peer state access.
3494-3495
: LGTM: Consistent error handling in message processingThe error handling in message processing is consistent, using the misbehavior tracking system uniformly across different message types.
Also applies to: 3500-3502
Line range hint
3983-3996
: LGTM: Address rate limiting with token bucketThe implementation of address rate limiting using a token bucket approach is well-designed and properly handles the time-based token accumulation.
4086-4086
: LGTM: Consistent inventory size checksThe size checks for INV and GETDATA messages are consistent and use appropriate misbehavior scores.
Also applies to: 4193-4193
4706-4706
: LGTM: Block validation error handlingThe error handling for invalid compact blocks and block transactions is appropriate and uses consistent misbehavior scores.
Also applies to: 4832-4832
5101-5101
: LGTM: Bloom filter validationThe validation of bloom filter size and data is thorough and uses appropriate misbehavior scores for violations.
Also applies to: 5137-5137
Line range hint
5166-5175
: LGTM: Masternode message validationThe validation of masternode-related messages is comprehensive and uses appropriate misbehavior scores for different types of violations.
Also applies to: 5197-5197, 5213-5213, 5220-5220
3628-3634
: Verify devnet version check error handlingThe devnet version check error handling looks correct but we should verify the misbehavior scores are appropriate for different scenarios.
✅ Verification successful
Misbehavior scores for devnet version mismatches are appropriately calibrated
The different scores (100 for outbound, 1 for inbound) are well-reasoned:
- Higher score for outbound prevents wasteful reconnection attempts to wrong networks
- Lower score for inbound allows honest mistakes without immediate harsh penalties
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for consistency in devnet version handling rg -B 5 'devnet' src/Length of output: 70141
1781-1802
: Verify thread safety of misbehavior trackingThe misbehavior tracking implementation looks correct but we should verify the thread safety of the score updates and disconnection logic.
✅ Verification successful
Thread safety implementation is correct and comprehensive
The misbehavior tracking implementation demonstrates proper thread safety through:
- Dedicated mutex (m_misbehavior_mutex) protecting all misbehavior state
- Consistent lock usage across all access points
- Clear thread safety annotations using GUARDED_BY
- No potential deadlock scenarios
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for potential race conditions in peer state access ast-grep --pattern 'm_misbehavior_score' src/ ast-grep --pattern 'm_should_discourage' src/Length of output: 423
Script:
#!/bin/bash # Search for misbehavior related variables and mutex with context rg -A 3 -B 3 "m_misbehavior_score" src/ rg -A 3 -B 3 "m_should_discourage" src/ rg -A 3 -B 3 "m_misbehavior_mutex" src/Length of output: 8267
test/sanitizer_suppressions/ubsan (1)
3-6
: Documentation improvement for suppression pattern format.The comment now uses a more generic format
sanitize-type:ClassName::MethodName
instead of a specific example, making it clearer how to add new suppressions.src/net_processing.h (1)
122-123
: Method renamed to clarify its testing purpose.The
Misbehaving
method has been replaced withUnitTestMisbehaving
, making it explicit that this method is intended for unit testing scenarios. This change improves code clarity and separates test functionality from production code.src/test/denialofservice_tests.cpp (4)
353-353
: Updated test for peer discouragement threshold.Test now uses
UnitTestMisbehaving
to verify peer discouragement at threshold, aligning with the new testing approach.
372-372
: Updated tests for incremental misbehavior.Tests now use
UnitTestMisbehaving
to verify:
- Below-threshold misbehavior (no discouragement)
- Reaching threshold through multiple violations
Also applies to: 380-380
403-403
: Updated test for non-IP peer handling.Test now uses
UnitTestMisbehaving
to verify discouragement behavior for non-IP peers (e.g., onion addresses).
449-449
: Updated test for ban time functionality.Test now uses
UnitTestMisbehaving
to verify the ban time implementation.src/llmq/dkgsessionhandler.cpp (1)
113-113
: Updated misbehavior reporting method.The method now uses
UnitTestMisbehaving
to report peer misbehavior, maintaining consistency with the test-focused approach adopted across the codebase.src/llmq/signing.cpp (1)
583-583
: Verify the impact of switching to UnitTestMisbehaving.The change from
Misbehaving
toUnitTestMisbehaving
alters how peer misbehavior is handled. This appears to be part of a broader refactor to improve testing capabilities, but we should ensure this doesn't affect production behavior.Let's verify if this change is consistently applied across the codebase:
✅ Verification successful
The change to UnitTestMisbehaving is a safe refactor
The switch from
Misbehaving
toUnitTestMisbehaving
is part of a consistent pattern across the codebase whereUnitTestMisbehaving
is the public interface method that internally calls the privateMisbehaving
implementation. This change improves encapsulation without altering the underlying behavior.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for any remaining direct usage of Misbehaving rg "Misbehaving\(" --type cpp # Check for new UnitTestMisbehaving usage rg "UnitTestMisbehaving\(" --type cppLength of output: 5967
src/txmempool.h (3)
116-116
: LGTM! Improved member variable naming.The change from
feeDelta
tom_modified_fee
follows better naming conventions with them_
prefix for member variables and provides a more descriptive name.
145-145
: LGTM! Simplified fee access.The updated
GetModifiedFee()
implementation directly returnsm_modified_fee
instead of calculating it on the fly, which is more efficient.
153-154
: LGTM! Improved method naming.The change from
UpdateFeeDelta
toUpdateModifiedFee
better reflects the method's purpose and maintains consistency with the new member variable name.src/llmq/instantsend.cpp (1)
941-941
: Verify consistent behavior with UnitTestMisbehaving.Similar to the change in signing.cpp, this replaces
Misbehaving
withUnitTestMisbehaving
. We should ensure this change maintains the same penalty score (20) and behavior.Let's verify the penalty scores are consistent:
✅ Verification successful
Penalty score of 20 is correct and intentionally different
The lower penalty score in instantsend.cpp is a deliberate design choice, as indicated by the code comment: the peer might simply be unlucky due to quorum changes, so a less harsh penalty is appropriate compared to clear protocol violations that receive 100 points.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check all UnitTestMisbehaving calls and their scores rg "UnitTestMisbehaving.*\(\w+,\s*(\d+)\)" --type cppLength of output: 282
Script:
#!/bin/bash # Get context around UnitTestMisbehaving calls echo "=== signing.cpp ===" rg "UnitTestMisbehaving.*\(\w+,\s*(\d+)\)" src/llmq/signing.cpp -B 5 -A 5 echo -e "\n=== instantsend.cpp ===" rg "UnitTestMisbehaving.*\(\w+,\s*(\d+)\)" src/llmq/instantsend.cpp -B 5 -A 5 echo -e "\n=== signing_shares.cpp ===" rg "UnitTestMisbehaving.*\(\w+,\s*(\d+)\)" src/llmq/signing_shares.cpp -B 5 -A 5 # Also check for any comments mentioning misbehaving scores echo -e "\n=== Comments about misbehaving ===" rg "misbehav\w+" src/llmq/ -i --type cppLength of output: 2943
bitcoin backports