Comments (3)
A real-world network typically will use some form of gossip protocol, where every node is connected to few other nodes and it relays the information to those, and so on, eventually syncing the entire network. This is neither simple to implement or demonstrate in a single machine set up, hence I left it out.
from python_blockchain_app.
But yeah, just in case if someone is interested, they can add a for loop in the mine
method to relay the transaction to other nodes, and handle the logic to abandon mining the relayed block when some other node figures out the nonce first and announces it to the network.
from python_blockchain_app.
We need to clear those out and put them inside actual blocks. So, we have to create a minePendingTransactions() method. This method will not only mine a new block with all the pending transactions, it will also send a mining reward to the miner.
minePendingTransactions(miningRewardAddress) {
// Create new block with all pending transactions and mine it..
let block = new Block(Date.now(), this.pendingTransactions);
block.mineBlock(this.difficulty);
// Add the newly mined block to the chain
this.chain.push(block);
// Reset the pending transactions and send the mining reward
this.pendingTransactions = [
new Transaction(null, miningRewardAddress, this.miningReward)
];
}
If you start mining, you can pass along your wallet address to this method. Once you successfully mined a block, the system will create a new transaction to give you your mining reward (in this case 100 coins).
One thing to note is that in this implementation we take all the pending transactions and add them to a block. In reality however that won’t work because the size of a block is limited. In Bitcoin’s case there is a block size limit of 2mb. If there are more transactions that can fit in a block, the miner gets to choose which transaction he includes and which he doesn’t (usually the ones with the highest fee wins).
from python_blockchain_app.
Related Issues (20)
- Quick question about deploying this to share with my class
- How can we generate desired hash code ? HOT 1
- Blockchain data goes to node 8000/chain HOT 2
- Can´t execute the Blockchain HOT 1
- Error HOT 1
- 1
- Transaction size HOT 1
- requests.exceptions.ConnectionError HOT 4
- Tutorial no longer accessible HOT 2
- e
- Pin markupsafe version in requirements.txt HOT 8
- in run_app.py 'app' is not defined HOT 1
- timestamp is not included when calculate genesis block HOT 2
- Localhost 5000 & 8000 can not work. HOT 1
- Containerise this?
- OpenAPI API spec HOT 1
- Server error HOT 2
- How can retrieve transactions and how many transaction in one block? HOT 1
- not able to contact with llm models HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python_blockchain_app.