build(agent): molt-y#23e5c8 iteration
This commit is contained in:
parent
b62082d735
commit
8112928b6a
|
|
@ -27,4 +27,11 @@ Contributing
|
||||||
|
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
|
Improvements (Post-MVP Goals)
|
||||||
|
- Cloud anchoring: Optional anchoring of log roots to a trusted ground anchor for long-term verifiability across partitions.
|
||||||
|
- Governance ledger: Lightweight event-sourced log for data-access decisions, policy changes, and contract amendments.
|
||||||
|
- Delta proofs: Plan to extend delta exports to include compact Merkle proofs for selective entry verification.
|
||||||
|
- Interoperability bridges: Start mapping core primitives to canonical data schemas for ecosystem interoperability.
|
||||||
|
- Observability: Instrumentation for proof sizes, reconciliation latency, and data-integrity guarantees.
|
||||||
|
|
||||||
READY_TO_PUBLISH marker is created when this MVP is deemed production-ready in a real SWARM build.
|
READY_TO_PUBLISH marker is created when this MVP is deemed production-ready in a real SWARM build.
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ def merkle_root(digests: List[str]) -> str:
|
||||||
class DeltaLog:
|
class DeltaLog:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.entries = [] # each entry is a dict with digest and payload
|
self.entries = [] # each entry is a dict with digest and payload
|
||||||
|
self.anchor = None # optional cloud/ground anchor for global verifiability
|
||||||
|
|
||||||
def add_entry(self, entry: dict) -> str:
|
def add_entry(self, entry: dict) -> str:
|
||||||
# entry must be serializable, and we store a digest for Merkle
|
# entry must be serializable, and we store a digest for Merkle
|
||||||
|
|
@ -32,6 +33,15 @@ class DeltaLog:
|
||||||
})
|
})
|
||||||
return digest
|
return digest
|
||||||
|
|
||||||
|
def anchor_root(self, anchor: str) -> None:
|
||||||
|
"""Record an optional anchor for the current delta log.
|
||||||
|
|
||||||
|
This does not alter existing entries; it simply stores a reference
|
||||||
|
to a trusted anchor (e.g., ground control) to tie the local log to
|
||||||
|
an external verifiable state.
|
||||||
|
"""
|
||||||
|
self.anchor = anchor
|
||||||
|
|
||||||
def delta_from_index(self, index: int) -> List[dict]:
|
def delta_from_index(self, index: int) -> List[dict]:
|
||||||
# return full payloads for simplicity (MVP). In a real system you'd return compact digests with proofs.
|
# return full payloads for simplicity (MVP). In a real system you'd return compact digests with proofs.
|
||||||
return [e["payload"] for e in self.entries[index:]]
|
return [e["payload"] for e in self.entries[index:]]
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,29 @@ from .contracts import DataContractRegistry
|
||||||
from .delta import DeltaLog
|
from .delta import DeltaLog
|
||||||
from .crypto import Signer, digest
|
from .crypto import Signer, digest
|
||||||
|
|
||||||
|
class GovernanceLedger:
|
||||||
|
"""Lightweight governance/ audit ledger for data-access events."""
|
||||||
|
def __init__(self):
|
||||||
|
self._events = []
|
||||||
|
|
||||||
|
def log_event(self, event: str, details: dict) -> dict:
|
||||||
|
ts = time.time()
|
||||||
|
payload = {
|
||||||
|
"event": event,
|
||||||
|
"details": details,
|
||||||
|
"ts": ts,
|
||||||
|
}
|
||||||
|
payload_bytes = json.dumps(payload, sort_keys=True).encode('utf-8')
|
||||||
|
event_id = hashlib.sha256(payload_bytes).hexdigest()
|
||||||
|
entry = {
|
||||||
|
"id": event_id,
|
||||||
|
"ts": ts,
|
||||||
|
"event": event,
|
||||||
|
"details": details,
|
||||||
|
}
|
||||||
|
self._events.append(entry)
|
||||||
|
return entry
|
||||||
|
|
||||||
class LedgerEntry:
|
class LedgerEntry:
|
||||||
def __init__(self, entry_id: str, ts: float, entry_type: str, payload: dict, contract_version: int, signer_name: str, signature: bytes):
|
def __init__(self, entry_id: str, ts: float, entry_type: str, payload: dict, contract_version: int, signer_name: str, signature: bytes):
|
||||||
self.id = entry_id
|
self.id = entry_id
|
||||||
|
|
@ -41,6 +64,10 @@ class LocalLedger:
|
||||||
self.delta_log = DeltaLog()
|
self.delta_log = DeltaLog()
|
||||||
self._entries = [] # store LedgerEntry objects locally
|
self._entries = [] # store LedgerEntry objects locally
|
||||||
self._signer = Signer(signer_key or os.urandom(32))
|
self._signer = Signer(signer_key or os.urandom(32))
|
||||||
|
# Simple governance log (extensible in future iterations)
|
||||||
|
self.governance = GovernanceLedger()
|
||||||
|
# Track known entry IDs to avoid duplicating imported deltas
|
||||||
|
self._entry_ids = set()
|
||||||
|
|
||||||
def register_contract(self, name: str, schema: dict, version: int = 1):
|
def register_contract(self, name: str, schema: dict, version: int = 1):
|
||||||
self.contracts.register(name, schema, version)
|
self.contracts.register(name, schema, version)
|
||||||
|
|
@ -60,6 +87,7 @@ class LocalLedger:
|
||||||
signature = self._signer.sign(payload_bytes)
|
signature = self._signer.sign(payload_bytes)
|
||||||
entry = LedgerEntry(entry_id, ts, entry_type, payload, contract_version, signer_name or self.node_id, signature)
|
entry = LedgerEntry(entry_id, ts, entry_type, payload, contract_version, signer_name or self.node_id, signature)
|
||||||
self._entries.append(entry)
|
self._entries.append(entry)
|
||||||
|
self._entry_ids.add(entry_id)
|
||||||
self.delta_log.add_entry(entry.to_dict())
|
self.delta_log.add_entry(entry.to_dict())
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
@ -72,7 +100,11 @@ class LocalLedger:
|
||||||
# delta_entries is a list of entry dicts (as produced by export_delta) to merge
|
# delta_entries is a list of entry dicts (as produced by export_delta) to merge
|
||||||
for d in delta_entries:
|
for d in delta_entries:
|
||||||
entry = LedgerEntry.from_dict(d)
|
entry = LedgerEntry.from_dict(d)
|
||||||
|
# Avoid duplicating entries we've already seen
|
||||||
|
if entry.id in self._entry_ids:
|
||||||
|
continue
|
||||||
self._entries.append(entry)
|
self._entries.append(entry)
|
||||||
|
self._entry_ids.add(entry.id)
|
||||||
self.delta_log.add_entry(entry.to_dict())
|
self.delta_log.add_entry(entry.to_dict())
|
||||||
|
|
||||||
def root(self) -> str:
|
def root(self) -> str:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue