maidsafe / sn_routing

Routing - specialised storage DHT
Other
278 stars 81 forks source link

Accumulation at Destination #2315

Closed oetyng closed 3 years ago

oetyng commented 3 years ago

Problem

To accumulate at destination, we can today send msg with SrcLocation::Node, but then you are responsible for the accumulation and verification yourself as currently routing doesn't know the message it supposed to be accumulated (it sees it only as a raw Bytes).

Solution

We can add something like this: fn send_message_accumulated_at_dst(&self, dst: DstLocation, signing_key: &bls::PublicKey, content: Bytes) -> Result<()> And routing would then sign content with the secret key share that corresponds to signing_key (if any) and send it to dst as a special message variant. The dst's routing would then validate the messages, checks their keys and accumulate the signatures and finally raise it upwards as Event::MessageReceived.

Details

There are essentially two approaches. We call them accumulation at source and accumulation at destination.

Accumulation at source works like this:

  1. The 7 elders each create a message and sign it with their respective secret key share.
  2. Each then sends the message to all the other elders
  3. Once an elder receives a supermajority of such messages, it aggregates the signatures into a full section signature and sends the resulting message to the destination
  4. The destination receives up to 7 such messages, but they are all identical as they already contain the full section signature, not just the signature share
  5. So the destination only needs to receive one such message and action it. It can then disregard the rest.

Accumulation at destination approach:

  1. Each elders created a message and signs it with their respective secret key share
  2. Then each elders sends this message to the destination
  3. When the destination receives a supermajority of such messages, it aggregates the signature shares into the full section signature and actions the message

Currently in routing we support both. To accumulate at source, all you need to do is send the message with SrcLocation::Section and routing takes care of the rest. On the destination you get it as Event::MessageReceived and the message is already verified, so you can already action it. To accumulate at destination, send it with SrcLocation::Node, but then you are responsible for the accumulation and verification yourself as currently routing doesn't know the message it supposed to be accumulated (it sees it only as a raw Bytes). We can try to change this if desired though.

We are trying to move towards using the accumulation at destination approach where possible as it seems simpler - there is fewer messages sent and the bulk of the work is carried by the destination which seems to be in line with the overall philosophy we are going for.