fort-nix / nix-bitcoin

A collection of Nix packages and NixOS modules for easily installing full-featured Bitcoin nodes with an emphasis on security.
https://nixbitcoin.org
MIT License
508 stars 106 forks source link

joinmarket.cfg missing default settings #734

Open kmajs opened 1 month ago

kmajs commented 1 month ago

The defaults were removed here, but it appears jmclient/configure.py is not setting them properly. The [POLICY] section is missing and it doesn't look like the joinmarket code has fallback values if these are missing.

erikarvstedt commented 1 month ago

it appears jmclient/configure.py is not setting them properly

How can I reproduce this?

kmajs commented 1 month ago

I thought the jmclient/configure.py script was called somewhere in the nix-bitcoin module, but looking back through, I couldn't find where that happens.

There may be an easier way to do this, but I used this flake to make a container so I could check the contents of a fresh joinmarket.cfg.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    nix-bitcoin.url = "github:fort-nix/nix-bitcoin/release";
  };

  outputs =
    { nixpkgs, nix-bitcoin, ... }:
    {
      nixosConfigurations.btc = nixpkgs.lib.nixosSystem {
        modules = [
          (
            { ... }:
            {
              imports = [ nix-bitcoin.nixosModules.default ];
              nixpkgs.hostPlatform = "x86_64-linux";
              boot.isContainer = true;
              nix-bitcoin.generateSecrets = true;
              services.joinmarket.enable = true;
            }
          )
        ];
      };
    };
}

Then: sudo nixos-container create --flake .#btc btc sudo nixos-container run btc sudo nixos-container root-login btc # cat /var/lib/joinmarket/joinmarket.cfg

erikarvstedt commented 1 month ago

Joinmarket loads the default config from jmclient/configure.py and then merges the user-provided config (/var/lib/joinmarket/joinmarket.cfg) into it. Why do you think the default settings from jmclient/configure.py are not present in the final config at runtime?

kmajs commented 1 month ago

Oh, I see - yes, that makes a lot more sense. :)

I changed a joinmarket [POLICY] setting:

joinmarket = {
  enable = true;
  settings.POLICY.merge_algorithm = "gradual";
  yieldgenerator = { enable = true; };
};

and my yield-generator stopped filling offers and the joinmarketd logs showed lots of these: Received commitment broadcast by other maker: 4ef0...ae, now blacklisted. I pasted in the defaults that had been removed and the yieldgenerator started filling orders again.

Note: I get the same behavior even if settings is not defined.

erikarvstedt commented 1 month ago

I still can't reproduce this. In my tests the config merging works correctly.

Can you share the nix-bitcoin config where joinmarket-yieldgenerator works correctly for you and the config where it fails? I'll then check how both joinmarket configs differ at runtime.

DIY debugging

This section is from an older version of this post. It's only relevant if you want to try debugging this by yourself.

Here's a version of nix-bitcoin that patches joinmarket to print its config at startup. (Unfortunately, because of https://github.com/NixOS/nixpkgs/issues/44426, we can't simply add a config setting that overrides joinmarket, but we have to change nix-bitcoin instead.)

Do the following:

  1. Switch to the custom nix-bitcoin version linked above. This is easy with Flakes, let me know if you need help with this.
  2. Run joinmarket-yieldgenerator with the config that's working for you.
  3. Print the logs of the currently runningjoinmarket-yieldgenerator instance:
    journalctl --since "$(systemctl show -p InactiveExitTimestamp --timestamp=us --value joinmarket-yieldgenerator)" -u joinmarket-yieldgenerator

    Copy the printed config values from the beginning of the log. It should look like this:

    {'DAEMON': [('no_daemon', '0'),
               ('daemon_port', '27183'),
               ...
    'BLOCKCHAIN': [('blockchain_source', 'bitcoin-rpc'),
                   ('network', 'mainnet'),
     ...                
  4. Then switch to the config that fails for you and also copy its config values from the log.
  5. Post the diff of both configs (or just post both configs and I'll do the diff).