yangl1996 / prism-rust

Rust implementation of the Prism consensus protocol
MIT License
100 stars 19 forks source link

Miner update context inconsistent from blockchain #82

Closed wgr523 closed 5 years ago

wgr523 commented 5 years ago

Higher level of the problem: Miner has two information inside the context, A and B. A, B might be inconsistent with each other.

Problem 1. He call blockchain.get_A to collect some information A. Then call blockchain.get_B to collect some information B. Between two calls, some information is changed inside blockchain.

Problem 2. Since Miner is smart updating, if he just receive the signal of "update A", and not receive the signal to update B (yet). Then he call blockchain.get_A. Now A is updated but B is not.

wgr523 commented 5 years ago

The real bug I found is:

The miner update the best_voter at some chain, that best_voter's proposer parent is L. But he has NOT updated best proposer yet. So he will mine a new voter whose proposer parent is at level L-1. But that new block's voter parent's proposer parent is at level L. This causes bad result inside blockchain.

wgr523 commented 5 years ago

solved in blockchain/mod.rs unvoted_proposer function. make it to return Option<>.

yangl1996 commented 5 years ago

Nice catch!

bagavi commented 5 years ago

We should simply pass the proposer and voter blocks mined by self through validation. This has very little computational cost and removes this and other unknown bugs from the miner.

yangl1996 commented 5 years ago

100 times YES!

yangl1996 commented 5 years ago

fixed