Skip to content

Delegate capability: Contract PUT #2829

@sanity

Description

@sanity

Parent: #2827

Summary

Allow delegates to create/store contracts via a PUT operation.

Proposed Implementation

1. Add to OutboundDelegateMsg (freenet-stdlib)

PutContractRequest {
    contract: ContractContainer,
    state: WrappedState,
    related_contracts: RelatedContracts,
},

2. Add to InboundDelegateMsg (freenet-stdlib)

PutContractResponse {
    contract_id: ContractInstanceId,
    result: Result<(), PutError>,  // or a custom error type
},

3. Handle in delegate runtime (freenet-core)

In delegate.rs, when processing OutboundDelegateMsg::PutContractRequest:

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

Design Questions

  1. Who can PUT?

    • Any delegate can PUT any contract (authorization is contract's responsibility)
    • But should there be any rate limiting or resource controls?
  2. Should the delegate be able to specify contract parameters?

    • Parameters are part of ContractContainer
    • Need to ensure the delegate can construct valid contract containers
  3. Related contracts handling

    • What if related contracts aren't available?
    • Should the delegate be notified of missing dependencies?
  4. Network propagation

    • In network mode, PUT broadcasts to peers
    • Should the delegate be notified when propagation completes, or just when local commit succeeds?

Sender Attestation

When a delegate PUTs a contract, should the contract know who created it? This could be useful for:

  • Initial authorization setup
  • Audit trails
  • Trust relationships

The delegate's key could be recorded as the contract's creator, though this may need design discussion.

Testing

  • Unit test for new message types
  • Integration test: delegate creates a contract via freenet local
  • Test with related contracts
  • Test error cases (invalid contract, resource limits)

Acceptance Criteria

  • OutboundDelegateMsg::PutContractRequest added to stdlib
  • InboundDelegateMsg::PutContractResponse added to stdlib
  • Runtime handles the request and stores contract
  • Works in both freenet local and freenet network modes
  • Example/test delegate demonstrates the capability

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-contractsArea: Contract runtime, SDK, and executionA-developer-xpArea: developer experienceA-networkingArea: Networking, ring protocol, peer discoveryE-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