This small PR deduplicates common low-level creation and sending code for the 'sequence' zmq publisher message (methods NotifyBlock{Connect,Disconnect}(), NotifyTransaction{Acceptance,Removal}() in the class CZMQPublishSequenceNotifier) by introducing a helper function.
zmq: deduplicate 'sequence' publisher message creation/sending #20523
pull theStack wants to merge 1 commits into bitcoin:master from theStack:20201128-zmq-refactor-dedup_sequence_msg_sending changing 1 files +17 −23-
theStack commented at 5:56 PM on November 28, 2020: member
- DrahtBot added the label RPC/REST/ZMQ on Nov 28, 2020
-
fanquake commented at 8:54 AM on November 30, 2020: member
Concept ACK - thanks
- fanquake requested review from instagibbs on Nov 30, 2020
-
in src/zmq/zmqpublishnotifier.cpp:236 in 5a249c7896 outdated
227 | @@ -227,50 +228,42 @@ bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &tr 228 | return SendZmqMessage(MSG_RAWTX, &(*ss.begin()), ss.size()); 229 | } 230 | 231 | +// Helper function to send a 'sequence' topic message with the following structure: 232 | +// <32-byte hash> | <1-byte label> | <8-byte LE sequence> (optional) 233 | +static bool SendSequenceMsg(CZMQAbstractPublishNotifier& notifier, uint256 hash, char label, std::optional<uint64_t> sequence = {}) 234 | +{ 235 | + unsigned char data[32+1+8]; 236 | + for (unsigned int i = 0; i < 32; i++)
jonasschnelli commented at 10:13 AM on December 1, 2020:even if its move only, I suggest adding brackets to confirm with the code style.
jonatack commented at 10:49 AM on December 1, 2020:s/i++/++i/
theStack commented at 1:53 PM on December 1, 2020:Thanks, done (both suggested changes).
in src/zmq/zmqpublishnotifier.cpp:238 in 5a249c7896 outdated
233 | +static bool SendSequenceMsg(CZMQAbstractPublishNotifier& notifier, uint256 hash, char label, std::optional<uint64_t> sequence = {}) 234 | +{ 235 | + unsigned char data[32+1+8]; 236 | + for (unsigned int i = 0; i < 32; i++) 237 | + data[31 - i] = hash.begin()[i]; 238 | + data[32] = label;
jonasschnelli commented at 10:15 AM on December 1, 2020:is there a reason you have dropped the
sizeof(uint256)(I think plain constant numbers are hard to read)?
theStack commented at 1:57 PM on December 1, 2020:The reasoning was that if a
sizeofis done on a type with a fixed bit-length then one could as well use directly the byte-length. Changed that to use the variable names instead of magic numbers now, see #20523 (comment)
jonasschnelli added the label Refactoring on Dec 1, 2020jonasschnelli commented at 10:15 AM on December 1, 2020: contributorConcept ACK - see my comments above.
theStack commented at 1:53 PM on December 1, 2020: memberForce-pushed with suggested changes:
- put brackets around loop body to confirm with the code style
- s/
i++/++i/ - replaced all magic numbers by
sizeof(varname)(I don't see much advantage of usingsizeof(type)over a number iftypealso includes a number (e.g.sizeof(uint256)vs.32); by usingsizeofon a variable though, a hypothetical change of the type would not need to change any code in the function body)
theStack force-pushed on Dec 1, 2020theStack commented at 6:55 PM on January 17, 2021: memberClosing this PR, as there hasn't been any activity for more than 6 weeks.
theStack closed this on Jan 17, 2021fanquake commented at 8:39 AM on January 21, 2021: memberping @instagibbs
fanquake reopened this on Jan 21, 2021MarcoFalke commented at 10:20 AM on January 21, 2021: memberreview ACK f231ffde04cbd20ba3ec3dc897f6484783ed9e76
in src/zmq/zmqpublishnotifier.cpp:235 in f231ffde04 outdated
227 | @@ -227,50 +228,43 @@ bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &tr 228 | return SendZmqMessage(MSG_RAWTX, &(*ss.begin()), ss.size()); 229 | } 230 | 231 | +// Helper function to send a 'sequence' topic message with the following structure: 232 | +// <32-byte hash> | <1-byte label> | <8-byte LE sequence> (optional) 233 | +static bool SendSequenceMsg(CZMQAbstractPublishNotifier& notifier, uint256 hash, char label, std::optional<uint64_t> sequence = {}) 234 | +{ 235 | + unsigned char data[sizeof(hash)+sizeof(label)+sizeof(uint64_t)];
jonatack commented at 12:04 PM on January 21, 2021:nit, clang format
unsigned char data[sizeof(hash) + sizeof(label) + sizeof(uint64_t)];
theStack commented at 1:38 PM on January 21, 2021:Done.
in src/zmq/zmqpublishnotifier.cpp:241 in f231ffde04 outdated
236 | + for (unsigned int i = 0; i < sizeof(hash); ++i) { 237 | + data[sizeof(hash) - 1 - i] = hash.begin()[i]; 238 | + } 239 | + data[sizeof(hash)] = label; 240 | + if (sequence) WriteLE64(data+sizeof(hash)+sizeof(label), *sequence); 241 | + return notifier.SendZmqMessage(MSG_SEQUENCE, data, sequence ? sizeof(data) : sizeof(hash)+sizeof(label));
jonatack commented at 12:05 PM on January 21, 2021:nit, clang format
- if (sequence) WriteLE64(data+sizeof(hash)+sizeof(label), *sequence); - return notifier.SendZmqMessage(MSG_SEQUENCE, data, sequence ? sizeof(data) : sizeof(hash)+sizeof(label)); + if (sequence) WriteLE64(data + sizeof(hash) + sizeof(label), *sequence); + return notifier.SendZmqMessage(MSG_SEQUENCE, data, sequence ? sizeof(data) : sizeof(hash) + sizeof(label));
theStack commented at 1:38 PM on January 21, 2021:Done.
in src/zmq/zmqpublishnotifier.cpp:231 in f231ffde04 outdated
227 | @@ -227,50 +228,43 @@ bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &tr 228 | return SendZmqMessage(MSG_RAWTX, &(*ss.begin()), ss.size()); 229 | } 230 | 231 | +// Helper function to send a 'sequence' topic message with the following structure:
jonatack commented at 12:05 PM on January 21, 2021:nit extra space
// Helper function to send a 'sequence' topic message with the following structure:
theStack commented at 1:37 PM on January 21, 2021:Good eye! :) Done.
jonatack commented at 12:08 PM on January 21, 2021: memberACK f231ffde04cbd20ba3ec3dc897f6484783ed9e76
zmq: deduplicate 'sequence' publisher message creation/sending 962444295dtheStack force-pushed on Jan 21, 2021jonatack commented at 7:56 PM on January 21, 2021: memberCode review re-ACK 962444295d92744e6f671dac2462037f9f3d79d7 per
git diff f231ffd 9624442instagibbs commented at 4:53 AM on January 22, 2021: memberfanquake merged this on Jan 22, 2021fanquake closed this on Jan 22, 2021sidhujag referenced this in commit 44406ab9c3 on Jan 22, 2021DrahtBot locked this on Aug 18, 2022
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me