Git Product home page Git Product logo

python-blockchain-tutorial's Issues

Need some reference

If i want to implement this on a p2p network, what will be the best way to implement that?

403 error with default ROOT_PORT 5000

Hey,
I stumbled upon a problem with the default port 5000 on macOS Ventura (13.6.1).
In chapter 7.13 of the tutorial I get with:


while starting up a second node:

export PEER=True && python3 -m backend.app

as requests.get result:

result: <Response [403]>

I found out (through stackoverflow) that macOS uses this port with the control center. It can be fixed by setting ROOT_PORT to some other value than 5000.

Great tutorial and maybe this info is of use to someone else!
Cheers

bug in app/__init__.py allows miners to get rewards when the transaction pool is empty

Currently, the code to mine a block looks like this:

@app.route('/blockchain/mine')
def route_blockchain_mine():
  transaction_data = transaction_pool.transaction_data()
  transaction_data.append(Transaction.reward_transaction(wallet).to_json())
  blockchain.add_block(transaction_data)
  block = blockchain.chain[-1]
  pubsub.broadcast_block(block)
  transaction_pool.clear_blockchain_transactions(blockchain)

  return jsonify(block.to_json())

The problem here is that going to the /blockchain/mine endpoint causes the system to create a mining reward transaction even with an empty transaction pool. So a miner could keep hitting this endpoint over and over to get free coins.

The fix I made was to check and make sure there is a transaction to mine before handing out a mining reward; if the transaction pool is empty, the endpoint sends back a JSON message informing the miner that the transaction pool is empty.

@app.route('/blockchain/mine')
def route_blockchain_mine():
  transaction_data = transaction_pool.transaction_data()
  if transaction_data:
    transaction_data.append(Transaction.reward_transaction(wallet).to_json())
    blockchain.add_block(transaction_data)
    block = blockchain.chain[-1]
    pubsub.broadcast_block(block)
    transaction_pool.clear_blockchain_transactions(blockchain)

    return jsonify(block.to_json())
  return {"message": "Transaction pool is empty"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.