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

[DEP] Add Cancel Transaction API #23

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ARK4579
Copy link

@ARK4579 ARK4579 commented Apr 27, 2024

Added Cancel Transaction API which takes sr_id to find and remove an already scheduled transaction.

Note: Please note that currently this API only removes transaction from our db and doesn't touch electrum wallet.

DEP:

this also includes code from other PRs, we can either review and merge this one PR and close previous ones or review those first and then create a new PR for this one.

@ARK4579 ARK4579 changed the title Add Cancel Transaction API [DEP] Add Cancel Transaction API Apr 27, 2024
@ErfanMN
Copy link

ErfanMN commented Jul 5, 2024

I am going to review this, but first, I have some questions:

  1. What is the primary purpose of this PR? It seems that we are just removing the transaction from our database. What is the impact of this change on the overall system, especially since it doesn't touch the Electrum wallet?
  2. you mentioned dependencies on other PRs. Can you specify which PRs these are and how they relate to the changes in this one?
  3. How does this cancellation process affect any dependent systems or subsequent transactions? Are there any scenarios where this could cause inconsistencies?

@ARK4579
Copy link
Author

ARK4579 commented Jul 5, 2024

While waiting for review on PRs #18 #21 #22, I merged those branches into master branch on my forked repo. so this PR builds on those PRs. i.e. If we review this PR we won't have to review other PRs and they can be closed instead.

  1. Purpose of this PR:
    1. Linting & Formatting updates #18 Linting and formatting updates along with a vscode settings file so all developers have have consistent development experience.
    2. [DEP] Add Regtest net support #21 Added Regtest Support so we can develop and test without waiting for testnet to confirm transactions
    3. [DEP] Add docker compose for easy setup #22 Added Docker support for easier setup
    4. [DEP] Add Cancel Transaction API #23 As mentioned above, added endpoint to cancel a transaction
  2. Cancelling a transaction here refers to deleting a scheduled transaction that's in our sqlite db and not one in BTC network.
  3. This scheduled transaction could be in 3 states.
    1. First, when corresponding transaction in bitcoin network is not yet created. this could be because of Insufficient balance, time remaining till next attempt or some other error. Removing transaction in this state should not effect any dependent systems negatively. Instead it frees up the transaction amount to be used to schedule other transactions.
    2. Second, it could be that transaction is not queued in Bitcoin Network too but not confirmed yet.
    3. Third would be when transaction in BTC network is confirmed. Removing in second and third stage won't effect dependent system as the transaction would already be in BTC network and corresponding balance updated accordingly.

Copy link

@ErfanMN ErfanMN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in overall I think linting will be a good idea. make the code always cleaner. the logic of the cancel function is also good.

"debug.log*": true,
"wallet_service_db": true,
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this be a good Idea. as a developer I like to see all the folders and configs in my vs code. I was trying to run your code but was confused at first where is my venv folder!!

I don't recommend to use a settings.json for vs code as every developer may have different desire for his/her work space.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with everyone having their own preferences. But, I think we should have settings.json added with must have settings for that repo. e.g. without settings.json some might have a warning not ignored and be annoyed when someone else checks in their code having that particular warning. or having different line length and ending up with un-wanted auto-formatting changes because of that.
But yeah, settings that have to do with appearance can be moved to user preference. I will make those changes.

@@ -1,6 +1,7 @@
[SYSTEM]
wallet_dir = wallets
use_testnet = True
use_regtest = False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use_testnet and use_regtest are mutually exclusive. it means we cannot set both of them True or both of them False. So it is better to define one variable for this purpose. e.g mode = regtest/testnet

[I will explain the issue it may have in the related code]

@@ -23,9 +24,17 @@ def __init__(self):
self.network = None
if self.config['SYSTEM']['use_testnet'] == 'True':
electrum.constants.set_testnet()
if self.config['SYSTEM']['use_regtest'] == 'True':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if somebody set use_testnet and use_regtest == True by mistake! it will be overwritten.

RUN pip install -e Electrum-4.2.1/.

# set electrum config parameters
RUN export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for ? please add a comment for this line and explain it.

Instead of using RUN export, use the ENV directive for setting environment variables.
best practice here is using ENV.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how much is the final image size? is it large ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a docker expert but as you have dependency between your services, consider adding health checks for services to ensure they are ready before dependent services start to avoid race condition. this is optional and up to you.

electrum.constants.set_regtest()
# default server add in regtest in electrum is 127.0.0.1
# this allows us to replace 127.0.0.1 with REGTEST_SERVER
regtest_server = os.environ.get('REGTEST_SERVER')
Copy link

@ErfanMN ErfanMN Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you get REGTEST_SERVER from docker-compose ?
can you explain what does this mean inside docker-compose:
REGTEST_SERVER=host.docker.internal

does it using an external host or it is internal ?? what is the ip it is using ?

Copy link
Author

@ARK4579 ARK4579 Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you get REGTEST_SERVER from docker-compose ?

yes

REGTEST_SERVER is basically a env variable containing to regtest address . while running without docker you would most probably have regtest server running on 127.0.0.1, depending on docker networking mode that might not be the case for our containers. Now, using this variable we can easily configure regetest server address.
Here we have set it to host.docker.internal to point to docker's docker container's localhost

Copy link

@ErfanMN ErfanMN Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking, don't we need this cancel operation in cli mode like what you implement in api mode ?

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

Successfully merging this pull request may close these issues.

2 participants