Skip to content

Introduce RPCContext #124

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

Open
wants to merge 3 commits into
base: Development
Choose a base branch
from

Conversation

domob1812
Copy link

This introduces the RPCContext class. This is a singleton instance which holds references to some context (at the moment, the MasternodeModule and CSporkManager, but also the ChainstateManager and perhaps others will fit in there in the future). The plan is to access all global state from RPC handlers through this instance, which gets managed with the RPC warmup and shutdown sequence.

Once this is done, it will also allow us to get rid of globals in the RPC code completely more easily: We could then modify the signature of RPC handlers to pass in such an RPCContext& ctx argument to all handler methods and thus get rid of globals for them. (This would be a rather large change that would have to adapt every single RPC handler at once, but is much easier to do and more consistent once we have RPCContext to begin with.)

domob1812 added 3 commits June 8, 2022 14:23
This introduces the RPCContext class, and an associated global instance
(accessible through RPCContext::Get).  This class is empty for now, but
will in the future hold contextual information such as references to the
global chainstate, masternode module and others, for use by RPC method
handlers while the RPC server is running.

It will be difficult to explicitly pass references like these to the
RPC handlers, as that would require updating the entire RPC server
infrastructure and all RPC handler methods at once.  With this class, we
still lay the foundation for removing direct "global" accesses from
the RPC methods, and instead bundling them in the RPCContext class.  This
makes the use of global state from the RPC server clearer, and can be
used later on to fully remove any global access by simply providing the
RPCContext instance explicitly to handlers somehow.
Add the global CSporkManager to RPCContext as the first actual data field.
With this, we can replace the use of GetSporkManager() from all RPC methods
with the RPCContext.
This adds a reference to the global MasternodeModule to the RPCContext
class, and accesses it through this instead of GetMasternodeModule
throughout all RPC code.
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.

1 participant