Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function#18165
Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function#18165jonasschnelli merged 2 commits intobitcoin:masterfrom
Conversation
|
Concept ACK |
1 similar comment
|
Concept ACK |
…agToStr function Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-vector<string> function because both GUI and RPC would need to iterate through it to convert to their desired target formats.
38f8b69 to
c31bc5b
Compare
| return allNetMessageTypesVec; | ||
| } | ||
|
|
||
| std::string serviceFlagToStr(const uint64_t mask, const int bit) |
There was a problem hiding this comment.
Seems it would be enough to only pass in bit, or what am I missing?
There was a problem hiding this comment.
This avoid recalculating mask
There was a problem hiding this comment.
That's one bit shift 1ull << bit;. Given how rarely this function is called that seems like an over-optimization.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
| uint64_t check = 1LL << i; | ||
| uint64_t check = 1ull << i; | ||
| if (mask & check) | ||
| { | ||
| strList.append(serviceFlagToStr(check, i)); | ||
| strList.append(QString::fromStdString(serviceFlagToStr(mask, i))); |
There was a problem hiding this comment.
Here we should pass check instead of mask? I did not test it but I think with the current patch formatServicesStr(NODE_NETWORK | NODE_WITNESS) will return a string like UNKNOWN[9] & UNKNOWN[9].
The arguments to serviceFlagToStr() are redundant (one can be derived from the other easily) which I think is confusing and could lead to slippages. I agree with @laanwj that just one of them should be passed.
|
Now that this PR got merged I tested whether my concern above was legit. It was: instead of now I see |
|
@vasild Thanks for following up and testing, did you want to open a PR to fix this? |
|
@vasild. Oh. I missed that. Would be great if you can fix it via a new PR. |
|
I am on it, hold on! |
|
Here is a fix: #19106 Cheerz! |
Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in bitcoin#18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`.
189ae0c util: dedup code in callers of serviceFlagToStr() (Vasil Dimov) fbacad1 util: simplify the interface of serviceFlagToStr() (Vasil Dimov) Pull request description: Don't take two redundant arguments in `serviceFlagToStr()`. Introduce `serviceFlagsToStr()` which takes a mask (with more than one bit set) and returns a vector of strings. As a side effect this fixes an issue introduced in #18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`. ACKs for top commit: MarcoFalke: ACK 189ae0c jonasschnelli: Tested ACK 189ae0c Tree-SHA512: 000c490f16ebbba04458c62ca4ce743abffd344d375d95f5bbd5008742012032787655db2874b168df0270743266261dccf1693761906567502dcbac902bda50
Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in bitcoin/bitcoin#18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`.
…to a shared serviceFlagToStr function c31bc5b Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function (Luke Dashjr) cea91a1 Bugfix: GUI: Use unsigned long long type to avoid implicit conversion of MSB check (Luke Dashjr) Pull request description: Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-`vector<string>` function because both GUI and RPC would need to iterate through it to convert to their desired target formats. ACKs for top commit: jonasschnelli: utACK ~~cea91a1e40e12029140ebfba969ce3ef2965029c~~ c31bc5b Tree-SHA512: 32c7ba8ac7ef2d4087f4f317447ae93a328ec9fb9ad81301df2fbaeeb21a3db7a503187a369552b05a9414251b7cf8e15bcde74c1ea2ef36591ea7ffb6721f60
Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in bitcoin#18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`.
Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in bitcoin/bitcoin#18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`.
…agToStr function Summary: ``` Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-vector<string> function because both GUI and RPC would need to iterate through it to convert to their desired target formats. ``` Backport of core [[bitcoin/bitcoin#18165 | PR18165]]. Depends on D8516. Test Plan: ninja all check-all ./src/qt/bitcoin-qt -server Check the service bits are displayed correctly in the peers window ./src/bitcoin-cli getnetworkinfo Check the service bits are displayed correctly Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8518
Summary: ``` Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in bitcoin/bitcoin#18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`. util: dedup code in callers of serviceFlagToStr() ``` Backport of core [[bitcoin/bitcoin#19106 | PR19106]]. Depends on D8518. Test Plan: ninja all check-all ./src/qt/bitcoin-qt -server Check the service bits display correctly ./src/bitcoin-cli getnetworkinfo Check the service bits display correctly Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8519
…to a shared serviceFlagToStr function
189ae0c util: dedup code in callers of serviceFlagToStr() (Vasil Dimov) fbacad1 util: simplify the interface of serviceFlagToStr() (Vasil Dimov) Pull request description: Don't take two redundant arguments in `serviceFlagToStr()`. Introduce `serviceFlagsToStr()` which takes a mask (with more than one bit set) and returns a vector of strings. As a side effect this fixes an issue introduced in bitcoin#18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`. ACKs for top commit: MarcoFalke: ACK 189ae0c jonasschnelli: Tested ACK 189ae0c Tree-SHA512: 000c490f16ebbba04458c62ca4ce743abffd344d375d95f5bbd5008742012032787655db2874b168df0270743266261dccf1693761906567502dcbac902bda50
…to a shared serviceFlagToStr function
Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI.
Note that there is no common mask-to-
vector<string>function because both GUI and RPC would need to iterate through it to convert to their desired target formats.