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

Node Contract Creation During Rent Contract Grace Period #1003

Open
sameh-farouk opened this issue Sep 11, 2024 · 3 comments
Open

Node Contract Creation During Rent Contract Grace Period #1003

sameh-farouk opened this issue Sep 11, 2024 · 3 comments
Assignees
Labels
tfchain tfchain repo issue type_bug Something isn't working
Milestone

Comments

@sameh-farouk
Copy link
Member

sameh-farouk commented Sep 11, 2024

Description:

This issue affects node contracts when they exist alongside a rent contract. The issue occurs as node contracts are synced only when the rent contract state changes and no check is performed on the state of the rent contract when the user tries to deploy workloads (create node contracts) on their rented nodes.

Issue Details:

  1. Sync Limitation: Node contracts are only synced with the rent contract when the rent contract state changes. This allows for a state mismatch between the rent contract and node contracts when certain actions are performed.

  2. No State Check on Node Creation: When a user creates a node contract on a rented node, the state of the rent contract is not checked. This becomes problematic if the rent contract is in a grace period.

Example Case:

  • A user rents a node, and the rent contract transitions to the grace period due to unpaid dues.
  • After this transition, the user is still able to create node contracts (without public IP addresses) on the rented node.
  • These node contracts stay active throughout the grace period, allowing the user to deploy workloads without interruption, even though the rent contract is suspended.

Proposed Solution:

  • State Check for Rent Contract: A check should be added to verify the state of the rent contract when a user attempts to create a node contract on a rented node. If the rent contract is in a grace period or suspended state, the system should block the creation of new node contracts and return an error until the rent contract is restored to active status.

Notes:

  • This issue can allow users to exploit the grace period of the rent contract and deploy workloads without incurring costs during the grace period.
  • Implementing the proposed check will ensure consistent behavior between rent contracts and node contracts, preventing misuse.
  • Currently, there are some checks on the client side to prevent this misuse, but it's vulnerable to easy manipulation.
@sameh-farouk sameh-farouk self-assigned this Sep 11, 2024
@sameh-farouk sameh-farouk added priority_major type_bug Something isn't working tfchain tfchain repo issue labels Sep 11, 2024
@renauter
Copy link
Collaborator

Good catch!
Indeed, for a node under a rent contract, the state of the latter should be checked before allowing to create new node contract on it.

The idea is to add this extra check somewhere in this part of code, correct ?

// In case there is a rent contract make sure only the contract owner can deploy
// If not, allow to deploy only if node is not dedicated
match ActiveRentContractForNode::<T>::get(node_id) {
Some(contract_id) => {
let rent_contract =
Contracts::<T>::get(contract_id).ok_or(Error::<T>::ContractNotExists)?;
if rent_contract.twin_id != twin_id {
return Err(Error::<T>::NodeNotAvailableToDeploy.into());
}
}
None => {
if node_is_dedicated {
return Err(Error::<T>::NodeNotAvailableToDeploy.into());
}
}
}

@sameh-farouk
Copy link
Member Author

Exactly.
Once we have obtained the rent contract, we should also verify its state.

@sameh-farouk
Copy link
Member Author

Update:
PR pending review

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
Status: Pending Deployment
Development

No branches or pull requests

2 participants