Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This introduces the
RPCContextclass. This is a singleton instance which holds references to some context (at the moment, theMasternodeModuleandCSporkManager, but also theChainstateManagerand 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& ctxargument 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 haveRPCContextto begin with.)