Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Allow for programmatic configuration of protocol settings #845
This PR adds a mechanism to configure the protocol settings programmatically. This enhancement is needed to enable automatic configuration of the privatenet blockchain,
This change adds an Initialize static function to ProtocolSettings, enabling the host process to pass custom protocol configuration information without needing to write a protocol.json file to disk. ASP.NET Configuration already supports multiple configuration providers. The caller of Initialize is free to use whatever configuration provider they wish, including in-memory .NET objects.
If Initialize method is not called, the first time the ProtocolSettings.Default get function is called, protocol configuration is loaded exactly as it loaded today - the protocol.json file is used as a configuration provider if available with mainnet defaults used for any configuration settings not provided. Again, as today these settings are cached for later use.
ProtocolSettings.Initialize must be called before the ProtocolSettings.Default property is ever accessed. Initialize will not overwrite existing loaded protocol settings - regardless if those settings were loaded by an earlier call to Initialize or by the first time the Default property is accessed. CompareExchange is used to ensure protocol settings are only initialized once, even in the face of multiple threads possibly accessing ProtocolSettings.
PR also includes unit tests for ProtocolSettings initialization. All unit tests pass locally.
@@ Coverage Diff @@ ## master #845 +/- ## ========================================== + Coverage 38.39% 38.45% +0.05% ========================================== Files 176 176 Lines 12465 12475 +10 ========================================== + Hits 4786 4797 +11 + Misses 7679 7678 -1