JoinMarket-Org / joinmarket-clientserver

Bitcoin CoinJoin implementation with incentive structure to convince people to take part
GNU General Public License v3.0
729 stars 179 forks source link

edge case: selected own offer in collaborative transaction #1715

Open theborakompanioni opened 5 months ago

theborakompanioni commented 5 months ago

After stopping the maker service, and initiating a collaborative transaction, it seems it took it's own offer and tried to create a transaction. This happened on regtest after stopping the maker (via rpc) and trying to initiate a collaborative transaction (with 1 counterparty) shortly after.

While this is an edge case and extremely unlikely to happen on mainnet, I think it provides valuable information about the seemingly unclean shutdown of the maker deamon. Maybe this happens only via RPC (as this occurred while using the Jam development environment), but it is nontheless a problem in production, as there were also reports about "old" offers being taking when a new one with other fee settings was actually active. So, my humble guess is, there is something wrong with the shutdown procedure of the subservices.

Below are the logs. Notice the input 3089559b2605cb8d57d553a53c1e963f9c8f9415c3afd22f8de95563e41256e4:0 is included twice. Which hints at that somehow the service was selecting itself as the counterparty.

2024-06-21 01:12:36,277 [INFO]  obtained tx
{
    "hex": "0200000002e45612e46355e98d2fd2afc315948f9c3f961e3ca553d5578dcb05269b5589300000000000feffffffe45612e46355e98d2fd2afc315948f9c3f961e3ca553d5578dcb05269b5589300000000000feffffff045714a78d000000001600141bffae399b921a34edab9f91dcdaef92d5a5759ce52ca78d00000000160014b01681b2424a6262e30f14375759d125a9902b0f15cd5b070000000016001496f4e323b91782e3af0ae9e6412eea344ba3fc0715cd5b070000000016001440df71c21182ef7d34f4da300ac7e6cfe2d182ab36010000",
    "inputs": [
        {
            "outpoint": "3089559b2605cb8d57d553a53c1e963f9c8f9415c3afd22f8de95563e41256e4:0",
            "scriptSig": "",
            "nSequence": 4294967294,
            "witness": "00"
        },
        {
            "outpoint": "3089559b2605cb8d57d553a53c1e963f9c8f9415c3afd22f8de95563e41256e4:0",
            "scriptSig": "",
            "nSequence": 4294967294,
            "witness": "00"
        }
    ],
    "outputs": [
        {
            "value_sats": 2376537175,
            "scriptPubKey": "00141bffae399b921a34edab9f91dcdaef92d5a5759c",
            "address": "bcrt1qr0l6uwvmjgdrfmdtn7gaekh0jt262avu4d4wl3"
        },
        {
            "value_sats": 2376543461,
            "scriptPubKey": "0014b01681b2424a6262e30f14375759d125a9902b0f",
            "address": "bcrt1qkqtgrvjzff3x9cc0zsm4wkw3yk5eq2c04gf7r6"
        },
        {
            "value_sats": 123456789,
            "scriptPubKey": "001496f4e323b91782e3af0ae9e6412eea344ba3fc07",
            "address": "bcrt1qjm6wxgaez7pw8tc2a8nyzth2x3968lq82rkagy"
        },
        {
            "value_sats": 123456789,
            "scriptPubKey": "001440df71c21182ef7d34f4da300ac7e6cfe2d182ab",
            "address": "bcrt1qgr0hrss3sthh6d85mgcq43lxel3drq4tztjfwm"
        }
    ],
    "txid": "d710a90f4b416b05d9d62680558b156aab28d4353c0620da2f47d2c090e2b000",
    "nLockTime": 310,
    "nVersion": 2
}
2024-06-21 01:12:36,280 [INFO]  potentially earned = 0.00000250 BTC (250 sat)
2024-06-21 01:12:36,280 [INFO]  mycjaddr, mychange = bcrt1qjm6wxgaez7pw8tc2a8nyzth2x3968lq82rkagy, bcrt1qkqtgrvjzff3x9cc0zsm4wkw3yk5eq2c04gf7r6
2024-06-21 01:12:36,281 [INFO]  goodtx
2024-06-21 01:12:36,300 [DEBUG]  >>privmsg on onion-network: nick=J56hWPQbRMoucz2V cmd=sig msg=55mwm/Uz4mLcogG4xEhLK8tkJZqbf7DSb9G0RmuYx0TThS6SrB4Ltc4wlOhMnfCdjOcdu9jdd9McTGURXCQuCPfeM5U7dKy2obAkoH9Fvb/k2ul9UkpUQD5HvBfmgdnesYiAy3RJHpdrd1/vfs+j6AgbnIwBw8g1agBPteE4yM0JEqTuaZRrgkhS7VZapV0SG+NJ2sAJzjCOcR2IA7g7bLXfJmbDisjJX0zO09HUeitvyoVrxlwOMQ== 0347b7e9a4ae8ae2ed57c0ab6b4d3e4c6e74e9622d56295eee61765bfd81bc80de MEQCIDIdXrxngxhApd8y4Bgcbt1Oc1rK3EKP5s+/+gtGYAW/AiBcir3hQpeyNmgJCfrbCoiKrdhIDOhWC0FbHLQ9BB6dmQ==
2024-06-21 01:12:36,300 [DEBUG]  >>privmsg on onion-network: nick=J56hWPQbRMoucz2V cmd=sig msg=ZdESXJbbQUgjsXPpK5IlPBXQrgLfuqwUM14BRkYIB249TIszcQRZ5fedpKbeZRnx9BLsCL1Rb12lv8l1Qr4VKm0/pwA2wU3wJyc+P62tY5zaLu/jIaektFcAlewzr3M78+TSRDfjOxY69RBUpGjySaCGbJYHWsNwDKkt9hH6fiLsE6ww5Lh7h7t1mapr6n7K13KJ+0NTAbJ5re4gdRW6xX0+FLh9geUvGe2aCpVohiMEtW7XCxeSrQ== 0347b7e9a4ae8ae2ed57c0ab6b4d3e4c6e74e9622d56295eee61765bfd81bc80de MEUCIQCVlAgzSC+xx1OS5hW6RC9EDLOZu6LvBo6o12sNbXa5jAIgEwNbPkZ8oPlVLwZt6ILnt0Fdvfi87YJwuww6c8mQdss=
2024-06-21 01:12:36,645 [DEBUG]  signature did not match anything in the tx
Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1010, in _commandReceived
    deferred = self.dispatchCommand(box)
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1067, in dispatchCommand
    return maybeDeferred(responder, box)
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 209, in maybeDeferred
    result = f(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1161, in doit
    maybeDeferred(aCallable, **kw)
--- <exception caught here> ---
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 1075, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1141, in checkKnownErrors
    key = error.trap(*command.allErrors)
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 481, in trap
    self.raiseException()
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 505, in raiseException
    raise self.value.with_traceback(self.tb)
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 209, in maybeDeferred
    result = f(*args, **kwargs)
  File "/src/src/jmclient/client_protocol.py", line 739, in on_JM_SIG_RECEIVED
    retval = self.client.on_sig(nick, sig)
  File "/src/src/jmclient/taker.py", line 755, in on_sig
    assert not len(self.nonrespondants)
builtins.AssertionError: 

2024-06-21 01:12:36,653 [DEBUG]  signature did not match anything in the tx
Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1010, in _commandReceived
    deferred = self.dispatchCommand(box)
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1067, in dispatchCommand
    return maybeDeferred(responder, box)
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 209, in maybeDeferred
    result = f(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1161, in doit
    maybeDeferred(aCallable, **kw)
--- <exception caught here> ---
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 1075, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "/usr/local/lib/python3.9/dist-packages/twisted/protocols/amp.py", line 1141, in checkKnownErrors
    key = error.trap(*command.allErrors)
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 481, in trap
    self.raiseException()
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 505, in raiseException
    raise self.value.with_traceback(self.tb)
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 209, in maybeDeferred
    result = f(*args, **kwargs)
  File "/src/src/jmclient/client_protocol.py", line 739, in on_JM_SIG_RECEIVED
    retval = self.client.on_sig(nick, sig)
  File "/src/src/jmclient/taker.py", line 755, in on_sig
    assert not len(self.nonrespondants)
builtins.AssertionError: 

Amp server or network failure unhandled by client application.  Dropping connection!  To avoid, add errbacks to ALL remote commands!
Traceback (most recent call last):
--- <exception caught here> ---
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 1075, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "/src/src/jmdaemon/daemon_protocol.py", line 499, in defaultErrback
    failure.trap(ConnectionAborted, ConnectionClosed,
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 481, in trap
    self.raiseException()
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 505, in raiseException
    raise self.value.with_traceback(self.tb)
twisted.protocols.amp.UnknownRemoteError: Code<UNKNOWN>: Unknown Error

Amp server or network failure unhandled by client application.  Dropping connection!  To avoid, add errbacks to ALL remote commands!
Traceback (most recent call last):
--- <exception caught here> ---
  File "/usr/local/lib/python3.9/dist-packages/twisted/internet/defer.py", line 1075, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "/src/src/jmdaemon/daemon_protocol.py", line 499, in defaultErrback
    failure.trap(ConnectionAborted, ConnectionClosed,
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 481, in trap
    self.raiseException()
  File "/usr/local/lib/python3.9/dist-packages/twisted/python/failure.py", line 505, in raiseException
    raise self.value.with_traceback(self.tb)
twisted.protocols.amp.UnknownRemoteError: Code<UNKNOWN>: Unknown Error
theborakompanioni commented 3 weeks ago

Probably related: https://github.com/JoinMarket-Org/joinmarket-clientserver/issues/1581

oPFGKk9gtuw8nuHkzrQn commented 3 weeks ago

I wonder if this here will cause problems when cj can not take place because the same maker gets chosen several times: grafik