Skip to content

[v4.2.0rc5] Testnet configuration is ignored. #417

Closed

Description

@beirut-boop

When the app is run in -testnet mode, it creates a testnet QSettings using QAPP_APP_NAME_TESTNET.

This is by design, so mainnet and testnet can exist om same computer. Options such as strDataDirSyscoin can be specified to use different datadirs.

Expected behavior

When Qt client is run with the -testnet command line argument, use the settings from QAPP_APP_NAME_TESTNET.

Actual behavior

The settings from QAPP_APP_NAME_DEFAULT are used in stead.

As a workaround, devs append hardcoded testnet3 to the mainnet value read from strDataDirSyscoin setting. This is wrong, because it should use the {QAPP_APP_NAME_TESTNET}/strDataDirSyscoin value in stead. This value should have testnet3 or Syscoin-testnet3 as the default, rather than an append on the mainnet settings.

The problem probably starts here:

syscoin/src/qt/syscoin.cpp

Lines 522 to 527 in 55ed9f2

/// 3. Application identification
// must be set before OptionsModel is initialized or translations are loaded,
// as it is used to locate QSettings
QApplication::setOrganizationName(QAPP_ORG_NAME);
QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);

Because QAPP_APP_NAME_DEFAULT is hardcoded while the actual settings key name is now tucked away in NetworkStyle:

static const struct {
const char *networkId;
const char *appName;
const int iconColorHueShift;
const int iconColorSaturationReduction;
} network_styles[] = {
{"main", QAPP_APP_NAME_DEFAULT, 0, 0},
{"test", QAPP_APP_NAME_TESTNET, 70, 30},
{"signet", QAPP_APP_NAME_SIGNET, 35, 15},
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30},
};

To reproduce

Change testnet settings in the relevant location (on Windows it's the registry) and see how the setting is ignored.

image

System information

Windows 10 x64
v4.2.0rc5 tagged release

Activity

  1. added a commit that references this issue on Feb 11, 2021
  2. sidhujag commented on Feb 11, 2021

    @sidhujag
    Member

    check this commit @beirut-boop
    0b78005

    This look ok? We can remove that hack now

  3. beirut-boop commented on Feb 11, 2021

    @beirut-boop
    Author

    @sidhujag commit is fine, but it doesn't seem to address the issue.

    I believe the most concise summary is this:

    • Running syscoin-qt.exe -testnet for the first time creates a QSettings (e.g. Windows Registry directory) with default settings specifically for testnet.
    • These settings are ignored and mainnet settings are used in stead.

    I am not sure where exactly the QSettings appName is defined, but in essence right in the beginning (when writing the defaults) the app name is QAPP_APP_NAME_TESTNET, yet later (when reading the settings) the app name changed to QAPP_APP_NAME_DEFAULT.

    I think this is because the AppName is stored in NetworkStyle which should be referenced, but in stead it is ignored and DEFAULT is used when looking for QSettings:

    syscoin/src/qt/syscoin.cpp

    Lines 522 to 527 in 55ed9f2

    /// 3. Application identification
    // must be set before OptionsModel is initialized or translations are loaded,
    // as it is used to locate QSettings
    QApplication::setOrganizationName(QAPP_ORG_NAME);
    QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
    QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);

    Line 527 might need something like this:

     /// 3. Application identification 
     // must be set before OptionsModel is initialized or translations are loaded, 
     // as it is used to locate QSettings 
     QApplication::setOrganizationName(QAPP_ORG_NAME); 
     QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN); 
    - QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT); 
    + QApplication::setApplicationName(networkStyle->getAppName());
  4. sidhujag commented on Feb 11, 2021

    @sidhujag
    Member

    @beirut-boop it is consistent with Bitcoin, does the problem happen on Bitcoin?

    I believe the logic you are describing happens here:

    QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString()));

    It will use testnet there and set app name, if its happening in Bitcoin as well we can open a PR to fix upstream. If what you are saying is true then it locates wrong QSettings and later changes the name after QSettings are already loaded with default regardless of testnet settings. Perhaps its not desired but we can ask upstream as intended behavior in that case.

    My guess is params isn't available at the time of the first call and thus its working as designed and we don't have enough information to load QSettings with testnet in line 527.

    Note: comments do say it will use QSettings from the new configuration after QApplication::setApplicationName(networkStyle->getAppName()); is applied on L594

  5. beirut-boop commented on Feb 11, 2021

    @beirut-boop
    Author

    @sidhujag commented:

    @beirut-boop it is consistent with Bitcoin, does the problem happen on Bitcoin?

    You are correct. I just tested this. The exact same behavior. Didn't know this. Never used Bitcoin Qt.

  6. sidhujag commented on Feb 11, 2021

    @sidhujag
    Member

    @sidhujag commented:

    @beirut-boop it is consistent with Bitcoin, does the problem happen on Bitcoin?

    You are correct. I just tested this. The exact same behavior. Didn't know this. Never used Bitcoin Qt.

    Why don't you open one upstream and ask them the intended behaviour and perhaps if it is a real bug or not

  7. beirut-boop commented on Feb 11, 2021

    @beirut-boop
    Author

    I've written my observations upstream: bitcoin#21154
    Let's wait and see which was the intended behavior.

  8. sidhujag commented on Feb 13, 2021

    @sidhujag
    Member

    @beirut-boop please post your syscoin address for a tip

  9. sidhujag commented on Mar 3, 2021

    @sidhujag
    Member

    @beirut-boop seems like not an issue according to upstream

  10. beirut-boop commented on Mar 4, 2021

    @beirut-boop
    Author

    @sidhujag at least not an issue with any kind of urgency.

    But definitely an issue of sorts. Confirmed in 2016(!). You can see what went wrong when following the logic:

    1. Someone made an interesting separation of configs
    2. Someone broke it (or never finished it)
    3. Someone monkey-patched testnet into mainnet data dir

    It works and anyone working with testnet for the first time will trash their mainnet data a maximum of 1 times and never again, so it's probably not worth fixing.

    I will close this issue to keep the tracker clean.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions