Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛑 Remove PreEvaluationBlock #3744

Open
riemannulus opened this issue Apr 16, 2024 · 3 comments
Open

🛑 Remove PreEvaluationBlock #3744

riemannulus opened this issue Apr 16, 2024 · 3 comments
Assignees
Labels
Breaking Change discussion needed We need to dicuss about this suggestion Suggestion or feature request

Comments

@riemannulus
Copy link
Member

riemannulus commented Apr 16, 2024

Context

PreEvaluationBlock played an important role in the days when Libplanet ran on PoW. The idea of ​​HashRandom, which determines the Hash before executing a transaction and uses it as a Random Seed, has always been a core concept of Libplanet.

However, now that the PBFT consensus algorithm has been adopted, there is less reason to use this method. Rather, the problem is that Hash is easy to manipulate, making it easy to use the transaction results as desired.

We attempted to introduce VRF to solve this problem, but it is difficult to introduce VRF in its current form as the StateRootHash of the nth block contains the execution result of the nth block.

Therefore, we would like to proceed with a more flexible and reliable chain consensus by deleting PreEvaluationBlock and making StateRootHash look at the execution results of the previous block.

Rationale

We must check the point below.

  • Meaning of genesis block.
  • How to store the nth block's state root hash.
  • Side effect of changes.
@riemannulus riemannulus added suggestion Suggestion or feature request discussion needed We need to dicuss about this Breaking Change labels Apr 16, 2024
@OnedgeLee
Copy link
Contributor

OnedgeLee commented Apr 16, 2024

Meaning of genesis block

For now, Block.StateRootHash is a root hash of the state after state transition, which is triggered by Block.Transactions.
So, Block proves the result of the Block.Transaction, so if someone finds state whose root hash is equal to Block.StateRootHash, he can believe that state is result state of Block.

After above change applied, there's no way to prove some state is a result state of Block, without computing state transition, so meaning of Block has been changed slightly.

Now Block means a set of previous state and transactions, which was a set of transactions and result state (a, s') => (s, a), which means almost same as current PreEvaluationBlock.

For the genesis block, it meant "world setter transactions" and "state after world setter transactions" previously, but this have to be redefined.

IMO, What we have to decide is, whether define genesis block as

  • Empty state + World setter transactions or
  • State after world setter transactions + Empty transactions -> (I think it doesn't have to be empty though)

From a different point of view, we can remove genesis block, starting 1st block with consensus.

@OnedgeLee
Copy link
Contributor

OnedgeLee commented Apr 17, 2024

How to store the nth block's state root hash

Below methods will be added to IStore interface.

  • void PutNextStateRootHash(BlockHash hash, HashDigest<SHA256> stateRootHash)
  • HashDigest<SHA256> GetNextStateRootHash(BlockHash hash)

BlockChain.Append() will check below additionally.

  • GetNextStateRootHash(block.PreviousHash).Equals(block.StateRootHash)

BlockChain will hold additional event handler.

  • event EventHandler<(Block block, HashDigest<SHA256> stateRootHash)> NextStateRootHashEvaluated
  • Above event will be triggered in the BlockChain.Append(), after IStateStore.PutNextStateRootHash() called

Context.IsValid(Block block) will be suspended until BlockChain.NextStateRootHashEvaluated triggered.

@OnedgeLee
Copy link
Contributor

OnedgeLee commented Apr 18, 2024

Redefine StateRootHash

  • Update IStore
  • Update BlockChain.Append()
  • Update BlockChain.ValidateBlock()
  • Update BlockChain.Propose()
  • Update tests for blockchain
  • Update Consensus.IsValid()
  • Update tests for consensus
  • Update queries for IWorldState

Introduce Proof

Generate random seed from Proof

Remove PreEvaluationBlock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change discussion needed We need to dicuss about this suggestion Suggestion or feature request
Projects
Status: In Progress
Development

No branches or pull requests

2 participants