Skip to content

Delegate capability: Contract UPDATE #2831

@sanity

Description

@sanity

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:

  1. Call executor.perform_contract_update()
  2. Package result as InboundDelegateMsg::UpdateContractResponse
  3. Call delegate again with the response

Design Questions

  1. 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?
  2. 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?
  3. Conflict handling: What if the contract rejects the update?

    • Return error to delegate
    • Include reason/details if contract provides them
  4. Batching: Should delegates be able to send multiple updates atomically?

    • Single update at a time (simpler)
    • Batch updates (more efficient but complex)
  5. 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::UpdateContractRequest added to stdlib
  • InboundDelegateMsg::UpdateContractResponse added to stdlib
  • Runtime handles the request and applies update
  • Works in both freenet local and freenet network modes
  • Example/test delegate demonstrates update flow

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-contractsArea: Contract runtime, SDK, and executionE-mediumExperience needed to fix/implement: Medium / intermediateP-mediumMedium priorityS-needs-designStatus: Needs architectural design or RFCT-featureType: New functionality request

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions