akash-network / support

Akash Support and Issue Tracking
5 stars 3 forks source link

Authorized Spend Not Returned To Grantee On Deployment Closure #88

Closed chainzero closed 2 months ago

chainzero commented 1 year ago

Example Scenario:

Authorized spend is made from a grantor to a grantee of 10AKT. Grantee creates deployment using grant with 5AKT and closes deployment immediately,. When authz grant balance is queried 5AKT (approx) is available. The important point here is that when authz funds are used for a deployment - remaining funds left in escrow on close are not returned to the grant allocation.

###Authorization created

provider-services tx deployment authz grant akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc 10000000uakt --from akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7

###State after initial authorization

provider-services query authz grants akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc
grants:
- authorization:
    '@type': /akash.deployment.v1beta2.DepositDeploymentAuthorization
    spend_limit:
      amount: "10000000"
      denom: uakt
  expiration: "2023-11-26T14:28:36Z"
pagination:
  next_key: null
  total: "0"

  ###Deployment created using authorization and then immediately closed

  provider-services tx deployment create --depositor-account akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 --from akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc deploy.yml -y 

provider-services tx deployment close --from $AKASH_KEY_NAME

###Balance of authorization after closure (as we can see the auth is now 5AKT in balance

root@ip-172-31-41-158:~# provider-services query authz grants akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc
grants:
- authorization:
    '@type': /akash.deployment.v1beta2.DepositDeploymentAuthorization
    spend_limit:
      amount: "5000000"
      denom: uakt
  expiration: "2023-11-26T14:28:36Z"
andy108369 commented 1 year ago

@chainzero the unused funds (5 AKT) have returned to the granter wallet (not to the granters authz deposit wallet, but to its normal wallet)

dseq: 8647334
owner: akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc
granter: akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7

1) 8647288: DepositDeploymentAuthorization: grant (10 AKT)

https://www.mintscan.io/akash/txs/39ED7FAEF9DB2102A52044369395B971EB5BC246FBDB017E3595807991BCBBC5

$ provider-services --height 8647288 query authz grants akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc
grants:
- authorization:
    '@type': /akash.deployment.v1beta2.DepositDeploymentAuthorization
    spend_limit:
      amount: "10000000"
      denom: uakt
  expiration: "2023-11-26T14:28:36Z"
pagination:
  next_key: null
  total: "0"

2) 8647335: MsgCreateDeployment

https://www.mintscan.io/akash/txs/895BB9EC2E43EC922E70D2B69F4D24499486DDF20BCC1E32C7F614DA174FDE87

$ provider-services --height 8647335 query authz grants akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc
grants:
- authorization:
    '@type': /akash.deployment.v1beta2.DepositDeploymentAuthorization
    spend_limit:
      amount: "5000000"
      denom: uakt
  expiration: "2023-11-26T14:28:36Z"
pagination:
  next_key: null
  total: "0"

None of 26 bids were selected, i.e. lease has never been created:

$ provider-services query market bid list --dseq 8647334 --owner akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc  | grep state | uniq -c
     26     state: closed

$ provider-services query market lease list --dseq 8647334 --owner akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc 
leases: []
pagination:
  next_key: null
  total: "0"

3) 8647343: MsgCloseDeployment

https://www.mintscan.io/akash/txs/6EB79060FFE23D8A00A862BCDB955BE839DB88E5BC56CD06C588069175287CC9

Right at that height 8647343 the granter received his 5000000uakt (or 5 AKT) back:

$ akash --height 8647342 query bank balances akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 -o json | jq -r '.balances[].amount|tonumber / pow(10;6)'
8.245243

$ akash --height 8647343 query bank balances akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 -o json | jq -r '.balances[].amount|tonumber / pow(10;6)'
13.245243

Since these funds have been used (read: authorized), they did not return back to the authz grants authorization wallet but to his normal wallet:

$ provider-services --height 8647343 query authz grants akash1f53fp8kk470f7k26yr5gztd9npzpczqv4ufud7 akash12nwd3ezmfkux589wu47vsr3wd05kt9wn09ymgc
grants:
- authorization:
    '@type': /akash.deployment.v1beta2.DepositDeploymentAuthorization
    spend_limit:
      amount: "5000000"
      denom: uakt
  expiration: "2023-11-26T14:28:36Z"
pagination:
  next_key: null
  total: "0"

Not sure whether this is the intended behavior though.

andy108369 commented 1 year ago

as per @boz - this behavior can be changed, below are the entry points: