Skip to content
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

Enable config/command-line switch replacing embedded JAR resources with external files #1855

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

SergioDemianLerner
Copy link
Contributor

We provide a method to force rskj to load internal resource files from external files. This is controlled by configuration or command-line switches.

Description

We add a new section in the configuration file like this:

path-remaps {
 genesis =  /tmp/genesis/
}

This sections can specify a folder (without filename) or a filename with path, depending on the key.

The supported path remappings are:

  • build-info (specifies a path to a folder, the file name is always "build-info.properties")
  • remasc (the remasc configuration file)
  • rskbitcoincheckpoints (the path to the folder containing a "*.checkpoints" file)
  • genesis (the path to the folder containing a genesis file. The file name is taken from the config key "genesis")

If a key is not given, no remapping is performed.

Motivation and Context

The benchmarking tool requires using different genesis files. To replace them, it's necessary to put the new genesis file somewhere in the class path and use a number of obscure methods to force Java to load it out of the JAR file. Many times it has failed. When it fails, it's impossible to diagnose the cause.

The channelling of all resource loads through a single method loadConfigurationFile() has other benefits:

  • It enables much better debugging, as we can later introduce a logger element that outputs which files have been loaded and from where. For example, the new method allowed me to detect that remasc file is loaded each time when a block is processed (inefficient) and the rskbitcoincheckpoints file is not loaded on startup, but only when the certain bridge methods are called. The existence of both files should be checked at startup for sanity.
  • It enables to mock resource loading and and test if the correct files are loaded.

How Has This Been Tested?

Tested was limited to:

  • passing the -Xpath-remaps.genesis=/tmp/genesis command line argument and checking that it works as expected.
  • Using a configuration file having a path-remaps section.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)

There is no documentation for none of the configuration options in the code, so no documentation was added to the code.

I will contact the developer's site maintainer to update the page https://developers.rsk.co/rsk/node/configure/reference/

Other information:
I suggest that after or concurrent with this merge, some tests are added to verify the correct placement of resource files.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

63.8% 63.8% Coverage
0.0% 0.0% Duplication

@illuque-iov
Copy link

pipeline:run

6 similar comments
@illuque-iov
Copy link

pipeline:run

@illuque-iov
Copy link

pipeline:run

@illuque-iov
Copy link

pipeline:run

@illuque-iov
Copy link

pipeline:run

@illuque-iov
Copy link

pipeline:run

@illuque-iov
Copy link

pipeline:run

Copy link
Contributor

@rmoreliovlabs rmoreliovlabs left a comment

Choose a reason for hiding this comment

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

Can we add more tests around new code?

@@ -1386,7 +1389,9 @@ protected StateRootsStore buildStateRootsStore() {
protected synchronized RskSystemProperties buildRskSystemProperties() {
checkIfNotClosed();

return new RskSystemProperties(new ConfigLoader(cliArgs));
RskSystemProperties props = new RskSystemProperties(new ConfigLoader(cliArgs));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use getRskSystemProperties() instead?

@@ -148,6 +149,8 @@ public class BridgeSupport {

private static final String INVALID_ADDRESS_FORMAT_MESSAGE = "invalid address format";

private static final ConfigFileLoader.ResourceLoader RESOURCE_LOADER = BridgeSupport.class::getResourceAsStream;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe rename this to BRIDGE_RESOURCE_LOADER?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

63.8% 63.8% Coverage
0.0% 0.0% Duplication

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.

3 participants