Summary
The current agreement flow puts negotiation logic on-chain that doesn't need to be there. The chain should only handle the mutual commitment that needs to be provable for disputes/slashing.
Current Flow (3 extrinsics)
create_bucket_with_storage — Auto-discovers a provider on-chain via find_matching_provider (O(n) iteration over all providers), creates bucket + agreement without provider consent
request_primary_agreement — User submits agreement request on-chain, reserves funds, stores temporary AgreementRequest
accept_agreement — Provider accepts on-chain, finalizes the agreement
Problems
find_matching_provider is O(n) on-chain work — iterates all registered providers in runtime storage. This is a DoS vector as the provider set grows and wastes blockspace for logic that doesn't need a proof. https://hackmd.io/@C1JDzk4wSpu-_9KIRuGLgg/B1Wc1kNlzg
request_primary_agreement is just negotiation — storing a temporary request on-chain burns gas and storage for coordination that can happen off-chain via HTTP.
create_bucket_with_storage bypasses provider consent — it auto-selects and binds a provider without their explicit agreement to the specific deal.
- Temporary storage overhead —
AgreementRequests storage map exists only to bridge two extrinsics, plus expiry/cleanup logic.
Ideal Flow
Off-chain (client + provider HTTP)
- Client discovers providers via runtime API queries (
query_find_matching_providers, query_available_providers) — already implemented in DiscoveryClient
- Client negotiates terms (price, duration, bytes) with provider via HTTP
- Provider signs the agreed terms off-chain
On-chain (single extrinsic)
establish_agreement(bucket_id, provider, terms, provider_signature) — verifies both parties' consent via signature, locks funds, creates the agreement
Benefits
- One extrinsic instead of two/three for agreement creation
- No O(n) on-chain iteration — matching stays off-chain where it belongs
- No temporary
AgreementRequest storage — no expiry cleanup needed
- Provider consent is explicit — provider signs the specific deal terms
- Chain only does what needs a proof — the binding commitment for disputes/slashing
Scope
Summary
The current agreement flow puts negotiation logic on-chain that doesn't need to be there. The chain should only handle the mutual commitment that needs to be provable for disputes/slashing.
Current Flow (3 extrinsics)
create_bucket_with_storage— Auto-discovers a provider on-chain viafind_matching_provider(O(n) iteration over all providers), creates bucket + agreement without provider consentrequest_primary_agreement— User submits agreement request on-chain, reserves funds, stores temporaryAgreementRequestaccept_agreement— Provider accepts on-chain, finalizes the agreementProblems
find_matching_provideris O(n) on-chain work — iterates all registered providers in runtime storage. This is a DoS vector as the provider set grows and wastes blockspace for logic that doesn't need a proof. https://hackmd.io/@C1JDzk4wSpu-_9KIRuGLgg/B1Wc1kNlzgrequest_primary_agreementis just negotiation — storing a temporary request on-chain burns gas and storage for coordination that can happen off-chain via HTTP.create_bucket_with_storagebypasses provider consent — it auto-selects and binds a provider without their explicit agreement to the specific deal.AgreementRequestsstorage map exists only to bridge two extrinsics, plus expiry/cleanup logic.Ideal Flow
Off-chain (client + provider HTTP)
query_find_matching_providers,query_available_providers) — already implemented inDiscoveryClientOn-chain (single extrinsic)
establish_agreement(bucket_id, provider, terms, provider_signature)— verifies both parties' consent via signature, locks funds, creates the agreementBenefits
AgreementRequeststorage — no expiry cleanup neededScope
create_bucket,create_bucket_with_storageextrinsicfind_matching_providerrequest_primary_agreement+accept_agreementwith a singleestablish_agreementextrinsic that takes a provider signatureAgreementRequestsstorage map and related cleanup logic (reject_agreement,withdraw_agreement_request, request expiry)DiscoveryClient/ client SDK to use the new flowstorage-interfaces/file-system/client) accordingly