-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement Governance into the ZMQ messages #2160
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
Conversation
| CheckOrphanVotes(govobj, exception, connman); | ||
|
|
||
| //Send notifications to scripts / zmq | ||
| GetMainSignals().NotifyGovernanceObject(govobj); |
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 think this is a good spot for it, but same as above. Don't know the codebase well enough to say for sure.
src/zmq/zmqpublishnotifier.cpp
Outdated
| static const char *MSG_RAWTX = "rawtx"; | ||
| static const char *MSG_RAWTXLOCK = "rawtxlock"; | ||
| static const char *MSG_GVOTE = "governancevote"; | ||
| static const char *MSG_GOBJECT = "governanceobject"; |
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.
change to hashgovernance*****? Thoughts?
|
To be consistent it should be rather: and this patch also lacks support for raw types: |
src/governance-object.cpp
Outdated
| } | ||
|
|
||
| //Send notifications to scripts / zmq | ||
| GetMainSignals().NotifyGovernanceVote(vote); |
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.
there may be a better location for this. But I couldn't find one.
|
This is one of my patch for 12.1 that adds support for this and even more (zeromq masternode announcements). After few tweaks it should also work with 12.3. |
|
@MrDefacto it would be better if you could reference your PR or those commits, or even put it in a gist. |
| print('- HASH BLOCK ('+sequence+') -') | ||
| print(binascii.hexlify(body).decode("utf-8")) | ||
| elif topic == "hashtx": | ||
| print ('- HASH TX ('+sequence+') -') |
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.
Please remove the space 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.
@nmarley there was a space originally, this commit removes that space. can revert this change if needed.
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.
@paulied You're right, sorry for getting the direction of change confused. This one is actually small, but personally I would still prefer to not mix formatting and functional PRs.
One reason is, what if this PR doesn't end up being merged in? That space fix would have to go in somewhere else then, and results in double-work (albeit minor).
src/zmq/zmqnotificationinterface.cpp
Outdated
|
|
||
| factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>; | ||
| factories["pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>; | ||
| factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>; |
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.
Can you revert these in this PR?
Do you know what is the clang-format recommendations for this type of alignment? (I am not sure myself.)
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.
If you want me to revert that formatting sure I can(accidentally didn't put this in a separate commit, so i'd have to do it by hand but yeah), I do not actually know what clang says on it. Couldn't find anything on it. I just know the old way it was looked bad and was annoying to read. Was hoping you could advise.
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 would prefer to remove formatting in this particular PR just to stick to keeping functional and formatting changes separate, for reasons described above. We do try to stick to the clang-format convention, but I'm not sure exactly what that is for this situation.
There's a clang-format program which reads the rules in the src/.clang-format file and shows the correct format (or maybe it changes the code to align w/it) based on those rules.
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.
done
src/zmq/zmqpublishnotifier.cpp
Outdated
| for (unsigned int i = 0; i < 32; i++) | ||
| data[31 - i] = hash.begin()[i]; | ||
| return SendMessage(MSG_GOBJECT, data, 32); | ||
| } |
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.
Needs EOL char
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.
done
src/zmq/zmqpublishnotifier.cpp
Outdated
| uint256 hash = vote.GetHash(); | ||
| LogPrint("zmq", "zmq: Publish governancevote %s\n", hash.GetHex()); | ||
| char data[32]; | ||
| for (unsigned int i = 0; i < 32; i++) |
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 see you're using the same format as above, but wondering if there's a way to use existing serialization methods for this. Also wondering if we can move hash.begin() out of the loop and only call it once.
|
|
||
| void CZMQNotificationInterface::NotifyGovernanceVote(const CGovernanceVote &vote) | ||
| { | ||
| for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ) |
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.
The iterator initialization is probably ok, but would prefer if we can move to using auto instead.
The convention in our codebase is to call iterators it, so would prefer that name to just i.
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.
as in for (auto it = notifiers.begin(); it != notifiers.end(); ) ? and then change the others to it too
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.
Yep, this looks correct.
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.
please view cb16cf0
| { | ||
| for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ) | ||
| { | ||
| CZMQAbstractNotifier *notifier = *i; |
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 an extra un-necessary variable. You can get the value of the iterator by dereferencing, e.g. *i.
In this case, you could use i->NotifyGovernanceVote(vote) instead of notifier. If the name is the only reason for this, you could just rename the iterator instead.
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.
removed in 2957424 But now it won't compile 🙈
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.
What is the error message?
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.
At each point where notifier was replaced with the iterator, as you described some variant of below.
zmq/zmqnotificationinterface.cpp:174:17: error: request for member ‘Shutdown’ in ‘* it.std::_List_iterator<_Tp>::operator-><CZMQAbstractNotifier*>()’, which is of pointer type
‘CZMQAbstractNotifier*’ (maybe you meant to use ‘->’ ?)
it->Shutdown();
^
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 list is a list of pointers. Try dereferencing the iterator first, then calling the method.
(*it)->Shutdown();
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.
that did it 👍
| for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i != notifiers.end(); ) | ||
| { | ||
| CZMQAbstractNotifier *notifier = *i; | ||
| if (notifier->NotifyGovernanceVote(vote)) |
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 syntax is ... ok I guess -- starting to get into personal preference a bit, but I really prefer to be able to use range-based for which is available as of C++11, and eliminate the if/else condition. Unfortunately that's not always the case, so I'd have to look into how std::list accepts an erasure to know if range-based for would work here.
|
@paulied Yep, that works too. Thanks! |
UdjinM6
left a comment
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.
utACK
UdjinM6
left a comment
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.
Heh, good catch! 👍
Tested, seems to be working as expected.
ACK
|
@UdjinM6 are votes coming through for you? I'm not getting any in my testing with jeffh |
|
Yep, 2 terminals: |
|
Votes are coming through correctly as notifications now for me, same with governance objects. Currently trying to figure out why the serialized data doesn't match the serialization spec for raw votes. |
|
Changed the location of the notification to one which I believe is slightly better. Both work but this one is more consistent based on where the govobject one is located. This will work just as well, since it is up the chain one call. it was prior in processvote, and was only called if that method will return true. And here it is called when processvote does return true |
|
Implemented raw notifications, after jeff pushed me twords it. Branch does compile, however the outputs from the raw messages do not match the formatting which serialization should follow as described in https://dash-docs.github.io/en/developer-reference#govobjvote. I'm not knowledgeable enough to know why... |
|
Hmm... indeed. Should be no and is missing in |
UdjinM6
left a comment
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.
Tested, works as expected.
ACK
|
I don't follow @UdjinM6, are you saying that the serialization is correct, but the documentation is wrong? Based on the chart at the link above the serialization for a vote should be ~150 bytes but the output we got was 132 I think. |
|
Yes, documentation has an error I described above. I tested 2 messages (1 |
|
Here's a vote How would you go about breaking that down |
|
@paulied @jhodges10 @UdjinM6 Yeah, my bad. Sorry about that. I think the table showing the fields is correct, but the hexdump is wrong. |
|
Outpoint (Size 36) - f06ec371b287f6a04e967a65bf100d76412b23eaa21b42cc4f7a5838eb8fd317 (Parent hash - 32 bytes) Note the endian-ness. Gets confusing if you don't flip the byte order 🙂 |
|
Thanks @thephez! |
* fix whitespace * added zmq stuff for governance objects and votes it seems that zmq is currently not in a working state, need to figure that out. Need to: plug in the new methods added possibly plug in the old methods, as it doesn't look like they are. * formatting fix. Will probably need to revert for this PR * continue linking new zmq messages in * added comment, might need to revert * fixes error of it not knowing about the classes * Actually link in, all new govobjects and govvotes should be broadcast over zmq now. * fix compile error, forgot to change params when copying * fix compile error * add imports to the header files in zmqconfig.h * fixing linking(i think) error * Revert "added comment, might need to revert" This reverts commit 2918ea4. * Revert "formatting fix. Will probably need to revert for this PR" This reverts commit ca10558. * fix tabs etc * EOL added * optimization of hash.begin() @nmarley thoughts? * remove formatting changes * iterator i -> it and removal of notifier * typo in df879f5 * use auto for the iterators * introduce hash prefix * implement changes in zmq_sub.py, update the doc, and change argument name to fix typo * deref iterators before calling methods * continued e8a4c50 * missed one... continued e8a4c50 * killing some tabs * fix spacing for setting or comparing iterators * change order of new variables to match current setup * re-add elif's I didn't realize got removed * Revert "fix spacing for setting or comparing iterators" This reverts commit 8ce2068. * Revert "use auto for the iterators" This reverts commit cb16cf0. * Revert "missed one... continued e8a4c50" This reverts commit 2087cf8. * Revert "continued e8a4c50" This reverts commit a78c8ad. * Revert "deref iterators before calling methods" This reverts commit e8a4c50. * Revert "iterator i -> it and removal of notifier" This reverts commit 2957424. * Revert "fix whitespace" This reverts commit 612be48. * Revert "typo in df879f5" * Revert "Optimization of hash.begin()" * fixes problem with revert * Udjin complain's a lot ;) * help text, init.cpp * add signals in validationinterface.cpp * Change location of vote notification call. * remain consistent * remove unneeded include due to change of notification location * implement raw notifications

I think I figured this one out and am done to my knowledge, but I am sure there are things I missed. This PR was inspired by @jhodges10, the lead of DashNexus (treasury funded replacement of dashcentral), possibly for use in nexus. I'd be quite surprised if I didn't miss something so just let me know and I'll try and fix it.
I accidentally added a minor formatting change, that wasn't an independent commit(other ones I reverted), in zmqnotificationinterface.cpp L:38-50ish in addition to adding the two new lines needed to make this PR work. Tell me if that's a problem.
Outside of that, this PR adds the sending of CGovernanceObject hashs over zmq when a new CGovernanceObject is added and adds the sending of CGovernanceVote hashs over zmq when a new CGovernanceVote is added. I could potentially add a pushing of a raw form, similar to transactions but I am not sure about that.
It does compile w/o problem, but I have not tried it in action yet. Will do so when I can.
Thoughts?