subsquid / sqd-network

A network of decentralized archives
GNU Affero General Public License v3.0
6 stars 1 forks source link

Query fees #39

Open dzhelezov opened 1 year ago

dzhelezov commented 1 year ago

Overview

Query fees are deducted from the user escrow account via a proxy address. This enables the following use cases:

The user story is as follows:

Funds flow

The query fees are deducted once the worker submits a claim. The router may abort the incoming transaction if the escrow account is too low.

The exact price of the query execution can only be calculated once the worker finishes the job. The worker executing the query (or part of the query) submits a claim based on the amount of processed data. As the query volume grows we will introduce the option to aggregate the claims to minimize the amount of data submitted on-chain. Since the worker rewards do not depend on the collected fees, there's no incentive for the worker to report excessive fees.

image

UPDATE

Here is an updated payment schema without a direct communication user <-> router:

  1. The client is authenticated using the address Public Key
  2. The client picks up a worker for the query
  3. The client sends a signed message containing:
    • query
    • nonce
    • signature
    • max fee (optional)
      1. The worker receives the client request and authenticates it against the router, sending to the router:
    • the digest + signature of the client request
      1. The router checks that the client has sufficient credits and locks the specified amount (with a margin). Responds to the worker with the max fee to spend
      2. The worker executes the query. Upon completion, sends back to the router the digest of the result and the actual resource spent (scanned data)
      3. The router finalizes the transaction and posts the query digest for optimistic verification

The scheme achieves the following:

image

dzhelezov commented 1 year ago

Architecture update 08.06.2023: https://gist.github.com/dzhelezov/5622ef130c8a2e671cddbc210b971178