openmina / openmina-poc

0 stars 0 forks source link

As a developer, I need to implement mina bootstrap proof of concept in Rust #1

Open vlad9486 opened 1 year ago

vlad9486 commented 1 year ago

Explore mina node bootstrap consensus. Implement simple application that synchronize epoch ledgers from the network.

Use get_best_tip to determine staking epoch ledger and next epoch ledger.

Use answer_sync_ledger_query to query the ledger tree.

vlad9486 commented 1 year ago

Setup rust-libp2p and redux. Implemented libp2p service (with gossipsub and rpc) and send get_best_tip from the redux state machine.

Next steps:

  1. Implement parsing rpc message response in the state machine.
  2. Use answer_sync_ledger_query to fetch the ledger.
vlad9486 commented 1 year ago

Rpc messages are parsed in state machine. Synchronize epoch ledger works in state machine.

Next steps:

  1. Choose internal representation for the ledger. Maybe, use our ledger storage implementation.
  2. Handle transitions. Use get_transition_chain and get_transition_chain_proof.
vlad9486 commented 1 year ago

Use mina-tree Sebastian's crate as a representation and storage for the ledger. Obtain correct epoch ledger hash. Receive some blocks from the peer using get_transition_chain.

Next steps:

  1. Apply blocks on the epoch ledger to obtain correct staged ledger hash.
  2. Understand scan state and obtain correct protocol state hash.
vlad9486 commented 1 year ago

Implemented a state machine to download and apply blocks. Customized mina-tree crate for this.

Still struggling to get the correct snarked ledger hash after applying the block. Need to download the correct block for the ledger.

vlad9486 commented 1 year ago

Create correct staged ledger and scan state using get_staged_ledger_aux_and_pending_coinbases_at_hash RPC. Implement cache and persistence for snarked ledger and blocks.

Have correct staged ledger hash. Have applied few blocks without errors and found a block 17414 hash is 3NKd84VTAYDsPpnkqziEzSrQgJFXrnuTTZxoiy3iYvkiNnEAxd7i which cause staged ledger hash mismatch.

vlad9486 commented 1 year ago

Most problems are fixed. A few things left:

  1. Sometimes peer returns nil best tip. Must to wait some time for peer to be able to respond. This will be fixed when we have multiple peers.
  2. Not all necessary logic is a part of the redux state machine.
  3. Documentation. Need to update and add docs.
vlad9486 commented 1 year ago

Done big refactoring of the redux state machine. Now it correctly retries canceled requests when peer resets the RPC stream.

TODO: documentation.