Browse Source

Do not update coinjoin state if maker cannot start

Fixes #1168.
Before this commit, if an RPC client sent /maker/start
on an active wallet without confirmed coins, it would
raise NotEnoughCoins but this would happen *after* the
call to the setup function which resets the coinjoin
state to CJ_MAKER_RUNNING, even though the maker service
did not successfully start.
After this commit, the raise of NotEnoughCoins happens
first, preventing the update of coinjoin state.
master
Adam Gibson 4 years ago
parent
commit
7b822a4540
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 13
      jmclient/jmclient/wallet_rpc.py

13
jmclient/jmclient/wallet_rpc.py

@ -598,7 +598,7 @@ class JMWalletDaemon(Service):
# to fail):
def cleanup():
self.activate_coinjoin_state(CJ_NOT_RUNNING)
def setup():
def setup_set_coinjoin_state():
# note this returns False if we cannot update the state.
if not self.activate_coinjoin_state(CJ_MAKER_RUNNING):
raise ServiceAlreadyStarted()
@ -612,12 +612,19 @@ class JMWalletDaemon(Service):
# picked up by Maker.try_to_create_my_orders().
if not len(self.services["wallet"].get_balance_by_mixdepth(
verbose=False, minconfs=1)) > 0:
# note: this raise will prevent the setup
# of the service (and therefore the startup) from
# proceeding:
raise NotEnoughCoinsForMaker()
self.services["maker"].addCleanup(cleanup)
self.services["maker"].addSetup(setup)
# order of addition of service setup functions matters;
# if a precondition should prevent the update of the
# coinjoin_state, it must come first:
self.services["maker"].addSetup(setup_sanitycheck_balance)
# Service startup now checks and updates coinjoin state:
self.services["maker"].addSetup(setup_set_coinjoin_state)
# Service startup now checks and updates coinjoin state,
# assuming setup is successful:
self.services["maker"].startService()
return make_jmwalletd_response(request, status=202)

Loading…
Cancel
Save