-
-
Notifications
You must be signed in to change notification settings - Fork 123
Open
Labels
A-contractsArea: Contract runtime, SDK, and executionArea: Contract runtime, SDK, and executionE-mediumExperience needed to fix/implement: Medium / intermediateExperience needed to fix/implement: Medium / intermediateP-mediumMedium priorityMedium priorityS-needs-designStatus: Needs architectural design or RFCStatus: Needs architectural design or RFCT-featureType: New functionality requestType: New functionality request
Description
Parent: #2827
Summary
Allow delegates to send updates to contracts, modifying their state.
Proposed Implementation
1. Add to OutboundDelegateMsg (freenet-stdlib)
UpdateContractRequest {
contract_id: ContractInstanceId,
delta: StateDelta,
},2. Add to InboundDelegateMsg (freenet-stdlib)
UpdateContractResponse {
contract_id: ContractInstanceId,
result: Result<UpdateResult, UpdateError>,
},Where UpdateResult might include:
- New state summary
- Whether update was accepted
- Any feedback from the contract
3. Handle in delegate runtime (freenet-core)
In delegate.rs, when processing OutboundDelegateMsg::UpdateContractRequest:
- Call
executor.perform_contract_update() - Package result as
InboundDelegateMsg::UpdateContractResponse - Call delegate again with the response
Design Questions
-
Authorization: How does the contract know the update is authorized?
- The delegate signs the update with a private key
- The contract verifies against a known public key
- This is entirely the contract's responsibility
- Should we provide helper utilities for common auth patterns?
-
Sender attestation in the update flow:
- When a delegate sends an update, should the contract see who sent it?
- Currently updates go through the network layer which may anonymize
- For delegate-initiated updates, should there be an option to include sender identity?
-
Conflict handling: What if the contract rejects the update?
- Return error to delegate
- Include reason/details if contract provides them
-
Batching: Should delegates be able to send multiple updates atomically?
- Single update at a time (simpler)
- Batch updates (more efficient but complex)
-
Optimistic vs confirmed updates:
- Should the delegate be notified when update is locally computed?
- Or only when it's confirmed/propagated in network mode?
- Different use cases may need different guarantees
Testing
- Unit test for new message types
- Integration test: delegate updates contract state via
freenet local - Test rejected update (contract validation fails)
- Test authorized update (delegate signs, contract verifies)
- Verify update triggers notifications to subscribed delegates (Delegate capability: Contract SUBSCRIBE #2830)
Acceptance Criteria
-
OutboundDelegateMsg::UpdateContractRequestadded to stdlib -
InboundDelegateMsg::UpdateContractResponseadded to stdlib - Runtime handles the request and applies update
- Works in both
freenet localandfreenet networkmodes - Example/test delegate demonstrates update flow
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-contractsArea: Contract runtime, SDK, and executionArea: Contract runtime, SDK, and executionE-mediumExperience needed to fix/implement: Medium / intermediateExperience needed to fix/implement: Medium / intermediateP-mediumMedium priorityMedium priorityS-needs-designStatus: Needs architectural design or RFCStatus: Needs architectural design or RFCT-featureType: New functionality requestType: New functionality request
Type
Projects
Status
Triage