Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What will happen to a rent contract on a grace period for an offline node #979

Open
A-Harby opened this issue Jun 6, 2024 · 5 comments
Open
Labels
tfchain tfchain repo issue type_bug Something isn't working

Comments

@A-Harby
Copy link

A-Harby commented Jun 6, 2024

What is your question?

What will happen to a rent contract on a grace period for an offline node?

What have you tried so far?

Tried deleting but couldn't,
Error from TS client: FarmHasNotEnoughPublicIPsFree: Failed to apply {"args":{"calls":[{"args":{"contract_id":"119,696"},"method":"cancelContract","section":"smartContractModule"}]},"method":"batchAll","section":"utility"}

14,976,851,872,796,664 the grace period amount on the chain.

contract was created yesterday, 6/5/2024, 3:28:18 PM
here
https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Ftfchain.dev.grid.tf%2Fws#/explorer/query/0xad6a6762b837ab9aef06acbf729462fe708de7c9e5864b01398188251c5bd52a

Screenshots

Error from polka
image

@renauter
Copy link
Collaborator

renauter commented Jun 6, 2024

From polka side:
The error suggest you don't have fund enough to make the call to cancelContract():
https://polkadot.js.org/docs/substrate/errors/#expendability
Since you are in grace period I assume it is the case (?)

From TS client side;
This is weird because FarmHasNotEnoughPublicIPsFree error can only be triggered when you want to reserve an IP when creating a node contract so I don't see how it comes here...

@sameh-farouk
Copy link
Member

sameh-farouk commented Jul 18, 2024

While reviewing the billing code, I observed that when billing is triggered for a rent contract associated with a standby node, our current behavior is to return a success status. Our intention is to prevent billing users when they rent a sleeping node that fails to come back online.

The challenge arises because there are multiple paths to this point. For instance:

  • A user can explicitly call bill_contract.
  • The off-chain worker might trigger billing.
  • Additionally, we can end up here when a contract is canceled (either by the user or the council), or when a node is deleted.
    Returning success in these latter cases would inaccurately mark canceled contracts or deleted nodes as successful, even though the necessary cleanup for contract storage and billing loops wasn’t properly executed due to the early return. To address this, we should check the status of the rent contract and ensure proper cleanup if it has been deleted.

Considering that the contract may have already entered the grace period before the node transitioned to standby, we should also investigate how the node was allowed to enter standby mode despite having active contracts. @A-Harby any hints?

Regarding what would happen, I assume that the rent contract associated with the standby node would remain stuck in the grace period even after the period expires because we bypass billing logic while the node is on standby.

Here are the relevant scenarios to consider:

1- Node rented while on standby and never brought back online:

  • Billing triggered by user/off-chain worker (state would be created).
  • Billing triggered by another transaction such as delete_node or cancel_contract (contract state would be deleted, with no funds to collect).

2- Node rented while online and later transitioned to standby (still to be investigated):

  • Billing triggered by user/off-chain worker (state would be created or in grace period).
  • Billing triggered by another transaction such as delete_node or cancel_contract (contract state would be deleted).

These are more paths than what was originally planned. we need to ensure that the necessary cleanup and handling occur even if the node is in standby mode.

Instead of returning a success status, setting the amount due to 0 and continuing with function execution could be a more robust approach. what do you think @renauter?

I’m currently in the process of rewriting and refactoring the billing logic, and I would greatly appreciate your feedback.

@sameh-farouk
Copy link
Member

sameh-farouk commented Jul 18, 2024

Take a look at the contract info

smartContractModule.contractLock: PalletSmartContractContractLock
{
  amountLocked: 241,249,373,259,065,683
  extraAmountLocked: 3,216,664,639
  lockUpdated: 1,718,798,538
  cycles: 336
}

system.account: FrameSystemAccountInfo
{
  nonce: 11,698
  consumers: 2
  providers: 1
  sufficients: 0
  data: {
    free: 21,217,440,553
    reserved: 0
    frozen: 4,249,983
    flags: 170,141,183,460,469,231,731,687,303,715,884,207,228
  }
}

tfgridModule.nodePower: TfchainSupportNodePower
{
  state: Up
  target: Up
}

smartContractModule.contracts: Option<PalletSmartContractContract>
{
  version: 4
  state: {
    GracePeriod: 11,377,497
  }
  contractId: 119,696
  twinId: 1,174
  contractType: {
    RentContract: {
      nodeId: 73
    }
  }
  solutionProviderId: null
}

It seems that the node is back online, but the billing has been stuck for a month now.
Too many billing cycles passed without proper distribution, and the grace period should have ended weeks ago.
I saw this before and likely related to #834

@sameh-farouk sameh-farouk added type_bug Something isn't working tfchain tfchain repo issue labels Jul 18, 2024
@A-Harby
Copy link
Author

A-Harby commented Jul 24, 2024

Update on offline rented node contract: it didn't delete after passing the expiration date; it's been nearly two months and still in grace period.

{
  "contract_id": 119696,
  "twin_id": 1174,
  "type": "rent",
  "state": "GracePeriod",
  "created_at": 1717590498,
  "details": {
    "nodeId": 73,
    "farm_id": 57
  },
  "solutionName": "-",
  "solutionType": "-",
  "expiration": "6/19/2024, 4:04:31 PM",
  "consumption": 0
}

image

@A-Harby
Copy link
Author

A-Harby commented Jul 24, 2024

Considering that the contract may have already entered the grace period before the node transitioned to standby, we should also investigate how the node was allowed to enter standby mode despite having active contracts. @A-Harby any hints?

I haven't faced an issue similar to this tbh, but this should never happen; otherwise, the standby mode would be working wrong because the most important rule for the node to go standby is not to have any contracts.

Also, this case is happening to an offline node; I am not sure about the standby node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tfchain tfchain repo issue type_bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants