Skip to content

poll: Implement poll notifications in core #2804

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

jamescowens
Copy link
Member

@jamescowens jamescowens commented May 12, 2025

This PR implements the ability to specify an external command to run via -pollnotify=<cmd> argument that takes two placeholders, %s1 and %s2, which are replaced with the poll txid and the notification status (added, deleted, or expiration_warning).

The notifications are sent on all non-expired polls. Add/delete notifications are executed by the poll contract handlers. The expiration warning is handled by a scheduler function which checks every 5 minutes and does a single shot notification for polls that are within -pollexpirewarningtime=<hours> of expiration.

This should be sufficient to drive an external script for notification via email or other desired approach. The external script can call gridcoinresearchd getpollresults <poll txid> or listpolls to get the details of the poll.

This PR includes an example script, poll_notify.sh, to email the poll notification that can be found in the contrib directory.

Closes #2803 and gridcoin-community/Gridcoin-Tasks#255.

@jamescowens jamescowens self-assigned this May 12, 2025
@jamescowens jamescowens added this to the Natasha milestone May 12, 2025
@jamescowens jamescowens marked this pull request as draft May 12, 2025 15:11
@jamescowens jamescowens force-pushed the implement_poll_notify_scripting branch 3 times, most recently from 37490f5 to b8f99c3 Compare May 12, 2025 16:32
@jamescowens jamescowens requested a review from Copilot May 12, 2025 16:59
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements poll notifications by adding new command-line options for external commands, extending the poll registry to support notification types, and scheduling poll notifications to be executed on poll events and expiration warnings.

  • Adds -pollnotify and -pollexpirewarningtime arguments in src/init.cpp.
  • Introduces a new PollNotificationType enum and associated notification functions in src/gridcoin/voting/registry.
  • Schedules poll notifications using a new NotifyPoll function in src/gridcoin/gridcoin.cpp.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/init.cpp Added new arguments for poll notifications and expiration warnings.
src/gridcoin/voting/registry.h Introduced PollNotificationType enum and new notification methods.
src/gridcoin/voting/registry.cpp Implemented the notification functions and updated poll handling.
src/gridcoin/gridcoin.h Declared the NotifyPoll function.
src/gridcoin/gridcoin.cpp Scheduled poll notifications via the scheduler and defined NotifyPoll.
Comments suppressed due to low confidence (1)

src/gridcoin/gridcoin.cpp:634

  • [nitpick] Typo in variable name 'poll_registy'; consider renaming it to 'poll_registry' for clarity.
PollRegistry& poll_registy = GetPollRegistry();

This commit implements the ability to specify an external command
to run via -pollnotify=<cmd> argument that takes two placeholders,
%s1 and %s2, which are replaced with the poll txid and the
notification status (added, deleted, or expiration_warning).

The notifications are sent on all non-expired polls. Add/delete
notifications are executed by the poll contract handlers. The
expiration warning is handled by a scheduler function which checks
every 5 minutes and does a single shot notification for polls that
are within -pollexpirewarningtime=<hours> of expiration.

This should be sufficient to drive an external script for
notification via email or other desired approach.
@jamescowens jamescowens force-pushed the implement_poll_notify_scripting branch from e024f31 to ff69c34 Compare May 12, 2025 17:13
@div72
Copy link
Member

div72 commented May 12, 2025

I mean it's kind of fine now since you implemented it but since the poll notify consumers already need to handle things like 1-block forks, you could've just passed the poll txid and left the extra machinery of type and expire to the consumer.

@jamescowens
Copy link
Member Author

I get where you are coming from; however, not every person using this will have a sophisticated state machine that tracks polls. Some are just enthusiasts running a command line wallet. On the expire warning, it is more efficient to implement an internal scheduler to check this rather than having someone either 1. creating a sophisticated external state machine to track poll expirations, and/or 2. poll the wallet to check.

This allows the external script to be much simpler for most uses.

The extra little bit of functionality wasn't that hard, anyway! :)

@jamescowens jamescowens force-pushed the implement_poll_notify_scripting branch 3 times, most recently from c7e560c to 421feab Compare May 12, 2025 20:32
@jamescowens jamescowens force-pushed the implement_poll_notify_scripting branch from 421feab to 227d317 Compare May 12, 2025 21:01
@jamescowens
Copy link
Member Author

jamescowens commented May 14, 2025

Tested this. Both the test rpc and the expiration warning works.

@jamescowens jamescowens marked this pull request as ready for review May 14, 2025 03:01
@jamescowens jamescowens requested a review from div72 May 14, 2025 03:01
This implements a simple rpc command to test poll notification. It
also makes changes to the poll_notify.sh script and a few other
refinements.
Copy link
Member

@div72 div72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK 5e379a8689b0af90a1fb613e454ee744b7a9f75b.

@jamescowens jamescowens merged commit 668cf72 into gridcoin-community:development May 25, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

poll: Implement ability to run an external command in free thread based on poll notification signal
2 participants