masa-finance / masa-oracle

Masa Oracle: Decentralized Data Protocol 🌐
https://developers.masa.ai/docs/masa-protocol/welcome
MIT License
22 stars 18 forks source link

feat: consensus mechanism to write to the CAS/ledger #496

Open mudler opened 3 months ago

mudler commented 3 months ago

Problem

Currently, writing to the ledger of the network is a process that is not synchronized. That is to say that there is no consensus between the peers, and as such data could be lost during the process as multiple actors could try to write at the same time to the ledger - and only one of them would win. This is a problem because we cannot guarantee data integrity, and moreover, since we want to have a CAS ( https://github.com/masa-finance/masa-oracle/issues/381 ) this would lead to invalid data across the nodes.

Proposed solution

As a first pass, we could implement raft consensus among the peers. There is already a well known library ( https://github.com/libp2p/go-libp2p-raft ) which can work with libp2p to have a basic raft consensus.

The idea is to have raft to guarantee that there is only one leader in a specific moment that can write to the ledger, and all the other nodes would have to accept new blocks only by the leader.

Additional context

See also an example of using raft and libp2p here: https://github.com/mudler/go-libp2p-simple-raft

Acceptance criteria

mudler commented 2 months ago

blocked by https://github.com/masa-finance/roadmap/issues/66 as we want to make sure we have all the requirements first