2024-02-12 14:35:23 +00:00
|
|
|
from typing import List, Optional, Generator
|
|
|
|
|
|
|
|
from da.common import Certificate, NodeId
|
|
|
|
from da.encoder import EncodedData
|
|
|
|
from da.verifier import DABlob, Attestation
|
|
|
|
|
|
|
|
|
|
|
|
class Dispersal:
|
|
|
|
def __init__(self, nodes: List[NodeId], threshold: int):
|
|
|
|
self.nodes = nodes
|
|
|
|
self.threshold = threshold
|
|
|
|
|
|
|
|
def _prepare_data(self, encoded_data: EncodedData) -> Generator[DABlob, None, None]:
|
|
|
|
assert len(encoded_data.row_commitments) == len(self.nodes)
|
|
|
|
assert len(encoded_data.row_proofs) == len(self.nodes)
|
2024-03-05 11:16:28 +00:00
|
|
|
columns = encoded_data.extended_matrix.columns
|
2024-02-12 14:35:23 +00:00
|
|
|
column_commitments = encoded_data.column_commitments
|
|
|
|
row_commitments = encoded_data.row_commitments
|
|
|
|
rows_proofs = encoded_data.row_proofs
|
|
|
|
aggregated_column_commitment = encoded_data.aggregated_column_commitment
|
|
|
|
aggregated_column_proof = encoded_data.aggregated_column_proof
|
|
|
|
for index, (column, column_commitment, row_proofs) in enumerate(zip(columns, column_commitments, rows_proofs)):
|
|
|
|
blob = DABlob(
|
|
|
|
index,
|
|
|
|
column,
|
|
|
|
column_commitment,
|
|
|
|
aggregated_column_commitment,
|
|
|
|
aggregated_column_proof,
|
|
|
|
row_commitments,
|
|
|
|
row_proofs
|
|
|
|
)
|
|
|
|
yield blob
|
|
|
|
|
|
|
|
def _send_and_await_response(self, node, encoded_data: EncodedData) -> Optional[Attestation]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _build_certificate(self, attestations: List[Attestation]):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _verify_attestation(self, attestation: Attestation) -> bool:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def disperse(self, encoded_data: EncodedData) -> Optional[Certificate]:
|
|
|
|
attestations = []
|
|
|
|
for node, blob in zip(self.nodes, self._prepare_data(encoded_data)):
|
|
|
|
if attestation := self._send_and_await_response(node, blob):
|
|
|
|
if self._verify_attestation(attestation):
|
|
|
|
attestations.append(attestation)
|
|
|
|
if len(attestations) >= self.threshold:
|
|
|
|
return self._build_certificate(attestations)
|