satwikkansal / python_blockchain_app

A fully functional blockchain application implemented in Python from scratch (with tutorial).
822 stars 471 forks source link

Unable to mine from new node (localhost:8001) #38

Closed cifranix closed 4 years ago

cifranix commented 4 years ago

Hi Satwik,

Thanks for putting this all together! Is it possible to mine from other nodes?

For example, in the web interface (localhost:5000), I post from node1, is it possible to mine the transaction from node2 using the api? When interacting with the API http://localhost:8001/mine, the ledger does not update. The only way that I could mine is through http://localhost:8000/mine.

However, the ledger is being distributed, so it is visible and in sync at both http://localhost:8000/chain AND http://localhost:8001/chain.

At the moment, this project doest seem to support mining from any other nodes accept for port 8000, however, I could be missing something.

satwikkansal commented 4 years ago

Yes, you're right

However, you can change the port here: https://github.com/satwikkansal/python_blockchain_app/blob/905ee87bbb635777133517ffb5d4830a98107269/app/views.py#L11

If you want to do it dynamically, you can pass the parameter through the API (you'll have to write some more code for that though)

Usually, the client syncing with any single node is enough in simple applications, that's why it is implemented that way in the project.

Hope that answers your queries.

cifranix commented 4 years ago

I wrapped this application into docker containers, removed it from localhost, and am hosting in 3 nodes in 3 different countries (AWS regions). My initial thought to propagate transactions to all nodes via the /submit endpoint; however, while this does propagate to all nodes, it also stores it in their transaction buffer. Meaning, the after propagating to node2 from node1, and mining from both nodes results in adding the transaction twice in two different blocks. Perhaps the /submit decorator is where some new code could be placed to mitigate that issue.

satwikkansal commented 4 years ago

You're right, transaction handling is a bit complex, there are multiple things to take care of. Maybe reading about how bitcoin does it or how ethereum does it will help you.