Skip to content

Conversation

@benjamin-stacks
Copy link

I started doing this as part of #6762, but since this refactoring is a self-contained change, I figured I'd split it into its own PR.

Two primary changes:

  • split the 3000-line event_dispatcher.rs into multiple files to make it easier to work with, and
  • turn EventObserver into a "dumb" struct that contains nothing more than the actual subscriber information and has no functionality of its own, with the EventDispatcher being the one doing the real work.

I would strongly suggest reviewing commit-by-commit.

The individual commits are structured so that the largely mechanical changes (like moving code from one file to another) can be more quickly verified by diffing the code that was remove from one file with the corresponding code that was added to another. Also take not of the individual commit messages.

The observer is now a pure data struct without any methods. All
functionality lives in the dispatcher; the observer just contains the
info where to send the data.

This is a largely mechanical change: cut & paste; delete now duplicate
`delete_payload` method; fix references.
No functional changes, only moving things around
Since the code in new files is just cut & paste from
`event_dispatcher.rs`, I kept the same header from there, but bumped
the year to 2025.
This is the final step to making `EventObserver` a "dumb" data object
that simply reflects the configuration of the registered observer.

Most of this change is straightforward. There is one thing that's worth
a mention, and that's the `ProposalCallbackHandler`, a concept that was
added in stacks-network#4228.
Because block proposal validation happens on a dedicated thread, those
validation events are handled a little specially.

Since `send_payload` now needs a dispatcher instance as the source of
the `db_path`, the list of observers alone is no longer enough.

For now I've elected to simply add the DB path to the
ProposalCallbackHandler and keep a non-method version of `send_payload`
around that gets the DB path passed in. Eventually I may have to clone
the dispatcher, but for now this approach had the smallest blast radius.

There wasn't any test coverage for this special behavior (at least not
on the event dispatcher side -- there are [some tests](https://github.com/stacks-network/stacks-core/blob/45381558f5e79554fc6e7930b0c4091e739e4992/stackslib/src/net/api/tests/postblock_proposal.rs#L234)
on the API side of things), so I added that as well.
Copy link
Contributor

@brice-stacks brice-stacks left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants