blockchain
blockchain copied to clipboard
Validating initial block?
I'm wondering if it is necessary to include a check at the beginning of the valid_chain
to ensure that the chain has the same history as one would expect?
For example, wouldn't it be possible for a malicious node to make itself i.) the longest node and ii.) with a self-consistent history that nonetheless starts out in a way that is advantageous to the node's owner?
Perhaps something like this:
class Blockchain(object)
...
def valid_chain(self, chain):
last_block = chain[0]
current_index = 1
# Check that initial block is as expected.
if last_block['previous_hash'] != 1 or last_block['proof'] != 100 or last_block['index'] != 1:
return False
while current_index < len(chain):
block = chain[current_index]
...
More generally, why isn't it necessary to validate the chain against some sort of "ground truth" contained within node? It seems like only checking that a given chain is self-consistent creates all sort of possibilities for veering off in bad directions.
A non-malicious related example arises when you have two nodes (on ports 5000 and 5001, say) and that transactions like the below occur:
curl -X POST -H "Content-Type: application/json" -d '{
"sender": "d4ee26eee15148ee92c6cd394edd974e",
"recipient": "someone-other-address",
"amount": 5
}' "http://localhost:5000/transactions/new"
# Send to another address on 5001
curl -X POST -H "Content-Type: application/json" -d '{
"sender": "d4ee26eee15148ee92c6cd394edd974e",
"recipient": "yet-other-address",
"amount": 5
}' "http://localhost:5001/transactions/new"
When and how is a case like this settled? In the present implementation it will be settled whenever a resolve occurs and one node's chain is strictly longer than the other. But that seems super arbitrary?
Perhaps all of this is material to be covered in 2? Or I'm just missing something fundamental...
this!