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

Changing BTC network does not have any effect #2048

Closed
ManfredKarrer opened this issue Dec 4, 2018 · 4 comments · Fixed by #2063
Closed

Changing BTC network does not have any effect #2048

ManfredKarrer opened this issue Dec 4, 2018 · 4 comments · Fixed by #2063
Assignees
Labels

Comments

@ManfredKarrer
Copy link
Contributor

ManfredKarrer commented Dec 4, 2018

If user changes the BTC network in settings and restarts MAINNET will be selected again even if the user has changed to testnet. There is probably some bug in the option parsing. @freimair will look into it.
For now users who want to try out the testnet DAO need to add a program argument:
'--baseCurrencyNetwork=BTC_TESTNET ' to enable testnet.

@freimair
Copy link
Contributor

freimair commented Dec 4, 2018

I have been able to track the issue down to 83e1dd3. (and probably the issue, where the appdir uses the default dir as well).

The issue

parser.accepts(BtcOptionKeys.BASE_CURRENCY_NETWORK,
"Base currency network")
.withRequiredArg()
.ofType(String.class)
.defaultsTo(BisqEnvironment.getDefaultBaseCurrencyNetwork().name());
introduces a default value which is used by the options parser if required (i.e. whenever you do not add --baseCurrencyNetwork=BTC_TESTNET)

However, due to

propertySources.addFirst(commandLineProperties);
try {
propertySources.addLast(getAppDirProperties());

Bisq first parses the commandLineProperties (which already provides the default values due to the abovementioned changes), and thus, the getProperty-call is satisfied already and the getAppDirProperties() are never asked.

This all boils down to a mostly useless bisq.properties at the moment.

Fix

Now, it is not trivial to change the behaviour while keeping the (most welcome) changes of 83e1dd3.

  • if we change the order of the property sources, we foreclose overriding bisq.properties-properties with cmdline options
  • if we partially revert 83e1dd3, we create a permanent minefield for future developments
  • we could use bisq.properties as defaults where applicable. However, we would have to open the BisqEnvironment to BisqExecutable
  • ???

all in all, I do not want to decide on that alone: @cbeams, @ManfredKarrer any ideas?

other

  • does 83e1dd3 deprecate things? for example
    public BisqEnvironment(PropertySource commandLineProperties) {
    //CommonOptionKeys
    logLevel = commandLineProperties.containsProperty(CommonOptionKeys.LOG_LEVEL_KEY) ?
    (String) commandLineProperties.getProperty(CommonOptionKeys.LOG_LEVEL_KEY) :
    LOG_LEVEL_DEFAULT;
    //AppOptionKeys
    userDataDir = commandLineProperties.containsProperty(AppOptionKeys.USER_DATA_DIR_KEY) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.USER_DATA_DIR_KEY) :
    DEFAULT_USER_DATA_DIR;
    appName = commandLineProperties.containsProperty(AppOptionKeys.APP_NAME_KEY) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.APP_NAME_KEY) :
    DEFAULT_APP_NAME;
    appDataDir = commandLineProperties.containsProperty(AppOptionKeys.APP_DATA_DIR_KEY) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.APP_DATA_DIR_KEY) :
    appDataDir(userDataDir, appName);
    staticAppDataDir = appDataDir;
    desktopWithHttpApi = commandLineProperties.containsProperty(AppOptionKeys.DESKTOP_WITH_HTTP_API) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.DESKTOP_WITH_HTTP_API) :
    "false";
    desktopWithGrpcApi = commandLineProperties.containsProperty(AppOptionKeys.DESKTOP_WITH_GRPC_API) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.DESKTOP_WITH_GRPC_API) :
    "false";
    ignoreDevMsg = commandLineProperties.containsProperty(AppOptionKeys.IGNORE_DEV_MSG_KEY) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.IGNORE_DEV_MSG_KEY) :
    "";
    useDevPrivilegeKeys = commandLineProperties.containsProperty(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS) :
    "";
    referralId = commandLineProperties.containsProperty(AppOptionKeys.REFERRAL_ID) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.REFERRAL_ID) :
    "";
    useDevMode = commandLineProperties.containsProperty(CommonOptionKeys.USE_DEV_MODE) ?
    (String) commandLineProperties.getProperty(CommonOptionKeys.USE_DEV_MODE) :
    "";
    dumpStatistics = commandLineProperties.containsProperty(AppOptionKeys.DUMP_STATISTICS) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.DUMP_STATISTICS) :
    "";
    maxMemory = commandLineProperties.containsProperty(AppOptionKeys.MAX_MEMORY) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.MAX_MEMORY) :
    "";
    providers = commandLineProperties.containsProperty(AppOptionKeys.PROVIDERS) ?
    (String) commandLineProperties.getProperty(AppOptionKeys.PROVIDERS) :
    "";
    //NetworkOptionKeys
    seedNodes = commandLineProperties.containsProperty(NetworkOptionKeys.SEED_NODES_KEY) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.SEED_NODES_KEY) :
    "";
    myAddress = commandLineProperties.containsProperty(NetworkOptionKeys.MY_ADDRESS) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.MY_ADDRESS) :
    "";
    banList = commandLineProperties.containsProperty(NetworkOptionKeys.BAN_LIST) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.BAN_LIST) :
    "";
    socks5ProxyBtcAddress = commandLineProperties.containsProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS) :
    "";
    socks5ProxyHttpAddress = commandLineProperties.containsProperty(NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS) :
    "";
    torRcFile = commandLineProperties.containsProperty(NetworkOptionKeys.TORRC_FILE) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.TORRC_FILE) :
    "";
    torRcOptions = commandLineProperties.containsProperty(NetworkOptionKeys.TORRC_OPTIONS) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.TORRC_OPTIONS) :
    "";
    externalTorControlPort = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT) :
    "";
    externalTorPassword = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD) :
    "";
    externalTorCookieFile = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) ?
    (String) commandLineProperties.getProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) :
    "";
    externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) ?
    true :
    false;
    //RpcOptionKeys
    rpcUser = commandLineProperties.containsProperty(DaoOptionKeys.RPC_USER) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.RPC_USER) :
    "";
    rpcPassword = commandLineProperties.containsProperty(DaoOptionKeys.RPC_PASSWORD) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.RPC_PASSWORD) :
    "";
    rpcPort = commandLineProperties.containsProperty(DaoOptionKeys.RPC_PORT) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.RPC_PORT) :
    "";
    rpcBlockNotificationPort = commandLineProperties.containsProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) :
    "";
    dumpBlockchainData = commandLineProperties.containsProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA) :
    "";
    fullDaoNode = commandLineProperties.containsProperty(DaoOptionKeys.FULL_DAO_NODE) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.FULL_DAO_NODE) :
    "";
    genesisTxId = commandLineProperties.containsProperty(DaoOptionKeys.GENESIS_TX_ID) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.GENESIS_TX_ID) :
    "";
    genesisBlockHeight = commandLineProperties.containsProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT) :
    "-1";
    daoActivated = commandLineProperties.containsProperty(DaoOptionKeys.DAO_ACTIVATED) ?
    (String) commandLineProperties.getProperty(DaoOptionKeys.DAO_ACTIVATED) :
    "";
    btcNodes = commandLineProperties.containsProperty(BtcOptionKeys.BTC_NODES) ?
    (String) commandLineProperties.getProperty(BtcOptionKeys.BTC_NODES) :
    "";
    useTorForBtc = commandLineProperties.containsProperty(BtcOptionKeys.USE_TOR_FOR_BTC) ?
    (String) commandLineProperties.getProperty(BtcOptionKeys.USE_TOR_FOR_BTC) :
    "";
    userAgent = commandLineProperties.containsProperty(BtcOptionKeys.USER_AGENT) ?
    (String) commandLineProperties.getProperty(BtcOptionKeys.USER_AGENT) :
    "Bisq";
    useAllProvidedNodes = commandLineProperties.containsProperty(BtcOptionKeys.USE_ALL_PROVIDED_NODES) ?
    (String) commandLineProperties.getProperty(BtcOptionKeys.USE_ALL_PROVIDED_NODES) :
    "false";
    numConnectionForBtc = commandLineProperties.containsProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC) ?
    (String) commandLineProperties.getProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC) :
    "9";

    and
    private PropertySource<?> defaultProperties() {
    return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
    {
    setProperty(CommonOptionKeys.LOG_LEVEL_KEY, logLevel);
    setProperty(CommonOptionKeys.USE_DEV_MODE, useDevMode);
    setProperty(NetworkOptionKeys.SEED_NODES_KEY, seedNodes);
    setProperty(NetworkOptionKeys.MY_ADDRESS, myAddress);
    setProperty(NetworkOptionKeys.BAN_LIST, banList);
    setProperty(NetworkOptionKeys.TOR_DIR, Paths.get(btcNetworkDir, "tor").toString());
    setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(baseCurrencyNetwork.ordinal()));
    setProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS, socks5ProxyBtcAddress);
    setProperty(NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS, socks5ProxyHttpAddress);
    setProperty(NetworkOptionKeys.TORRC_FILE, torRcFile);
    setProperty(NetworkOptionKeys.TORRC_OPTIONS, torRcOptions);
    setProperty(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT, externalTorControlPort);
    setProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD, externalTorPassword);
    setProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE, externalTorCookieFile);
    if (externalTorUseSafeCookieAuthentication)
    setProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, "true");
    setProperty(AppOptionKeys.APP_DATA_DIR_KEY, appDataDir);
    setProperty(AppOptionKeys.DESKTOP_WITH_HTTP_API, desktopWithHttpApi);
    setProperty(AppOptionKeys.DESKTOP_WITH_GRPC_API, desktopWithGrpcApi);
    setProperty(AppOptionKeys.IGNORE_DEV_MSG_KEY, ignoreDevMsg);
    setProperty(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS, useDevPrivilegeKeys);
    setProperty(AppOptionKeys.REFERRAL_ID, referralId);
    setProperty(AppOptionKeys.DUMP_STATISTICS, dumpStatistics);
    setProperty(AppOptionKeys.APP_NAME_KEY, appName);
    setProperty(AppOptionKeys.MAX_MEMORY, maxMemory);
    setProperty(AppOptionKeys.USER_DATA_DIR_KEY, userDataDir);
    setProperty(AppOptionKeys.PROVIDERS, providers);
    setProperty(DaoOptionKeys.RPC_USER, rpcUser);
    setProperty(DaoOptionKeys.RPC_PASSWORD, rpcPassword);
    setProperty(DaoOptionKeys.RPC_PORT, rpcPort);
    setProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT, rpcBlockNotificationPort);
    setProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA, dumpBlockchainData);
    setProperty(DaoOptionKeys.FULL_DAO_NODE, fullDaoNode);
    setProperty(DaoOptionKeys.GENESIS_TX_ID, genesisTxId);
    setProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, genesisBlockHeight);
    setProperty(DaoOptionKeys.DAO_ACTIVATED, daoActivated);
    setProperty(BtcOptionKeys.BTC_NODES, btcNodes);
    setProperty(BtcOptionKeys.USE_TOR_FOR_BTC, useTorForBtc);
    setProperty(BtcOptionKeys.WALLET_DIR, btcNetworkDir);
    setProperty(BtcOptionKeys.USER_AGENT, userAgent);
    setProperty(BtcOptionKeys.USE_ALL_PROVIDED_NODES, useAllProvidedNodes);
    setProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, numConnectionForBtc);
    setProperty(UserAgent.NAME_KEY, appName);
    setProperty(UserAgent.VERSION_KEY, Version.VERSION);
    setProperty(Storage.STORAGE_DIR, Paths.get(btcNetworkDir, "db").toString());
    setProperty(KeyStorage.KEY_STORAGE_DIR, Paths.get(btcNetworkDir, "keys").toString());
    }
    });
    }

    which might cleanup the minefield a bit
  • for the appdir issue Fix log path #2019
    parser.accepts(AppOptionKeys.APP_DATA_DIR_KEY,
    "Application data directory")
    .withRequiredArg()
    .defaultsTo(BisqEnvironment.DEFAULT_APP_DATA_DIR);
    might to be responsible.

@ManfredKarrer
Copy link
Contributor Author

ManfredKarrer commented Dec 4, 2018

Ah great you found out the reason!

Same issue was with log path which was now always 'Bisq'.

I don't have strong opinions and its not my field of expertise. Leave it to @cbeams to suggest how we should resolve it, but would be good to resolve it soon as people cannot switch to testnet in the UI and it might affect other options as well.

@ManfredKarrer ManfredKarrer assigned freimair and cbeams and unassigned freimair Dec 4, 2018
@CaveSpectre11
Copy link
Contributor

I stumbled across this when I was playing with 0.9.0, but I hadn't had enough time to fully determine if I was doing something wrong or if there actually was a problem; I'm using the Windows client. One thing that may be relevant to bring up: I tried changing the field in the config file (I don't have access to my PC at this moment to specify exactly what the config file name was), and it reverted back to MAINNET after starting the client. Initially I tried this when the client was running, then restarted. I then tried it after shutting it down, and it also changed the contents of the file on startup.

cbeams added a commit to cbeams/bisq that referenced this issue Dec 5, 2018
This change fixes bisq-network#2048 by removing the assignment of a default value
for the `baseCurrencyNetwork` option at the level of the command line
option parser. The assignment of this default was an oversight in bisq-network#1961
(specifically commit 83e1dd3) that did not account for the fact that
users can change the `baseCurrencyNetwork` value via the Settings screen
in the application. When users change the setting in the application, the new
value is persisted to <appDataDir>/bisq.properties, which is handled at
runtime as a PropertySource with lower precedence than the command line
property source, which means that the changed value is never picked up
because the higher-precedence command line PropertySource always has a
default value.

This fix is surgical in that it addresses only this specific option. A
subsequent change should address the more general issue that setting
defaults in the command line option parser always precludes the
possibility of overriding them in bisq.properties. Basically, we should
revert to the previous strategy of reporting what the default value will
be in the help text without actually assigning a default value in the
option parser using the `defaultsTo` method.
@cbeams
Copy link
Contributor

cbeams commented Dec 5, 2018

Thanks, @freimair for the careful analysis above. Please see #2063, where I've fixed this specific problem, and you'll see in the comment there where I suggest a larger and more general fix.

I have a number of additional changes to our option handling infrastructure queued up locally that I have not yet submitted as a pull request. I'll see about working the more general fix into those changes before I submit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants