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

Chain compatibility #3345

Closed
wants to merge 8 commits into from
Closed

Conversation

0oM4R
Copy link
Contributor

@0oM4R 0oM4R commented Aug 28, 2024

  • no need to calculate the free balance, now we have the pure free field without the reserved balance.
  • rename locked field with reserved.
  • in profile manager added the free to the reserved to show total balance

Description

Describe the changes introduced by this PR and what does it affect

Changes

#3340

Related Issues

List of related issues

Documentation PR

For UI changes, Please provide the Documetation PR on info_grid

Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstrings
  • Screenshots/Video attached (needed for UI changes)

0oM4R added 8 commits August 28, 2024 18:16
-  no need to calculate the free balance, now we have the pure free field without the reserved balance.
- rename locked field with reserved.
- in profile manager added the free to the reserved to show total balance
add yarn before running gereratedefses and meta types
@@ -13,6 +14,8 @@ import { formatErrorMessage } from "../../helpers";
import { ContractStates } from "../../modules";
import { Graphql } from "../graphql/client";

const ONE_HOUR = 1000 * 60 * 60;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what unit exactly? Please change the variable name to a more descriptive one.
An ideal name for a variable that holds the number of milliseconds in one hour could be MILLISECONDS_PER_HOUR, which is descriptive and clearly convey the purpose of the variable.

async calculateContractOverDue(options: CalculateOverdueOptions) {
const { lastUpdatedSeconds, standardOverdraft, additionalOverdraft } = options.paymentState;
const contractCost = await this.getConsumption({ id: options.id, graphqlURL: options.graphqlURL });
const elapsedSeconds = new Decimal(Date.now()).minus(lastUpdatedSeconds).div(1000);
Copy link
Member

@sameh-farouk sameh-farouk Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that ContractPaymentState.lastUpdatedSecond is already a timestamp in seconds, you need to convert the current timestamp from milliseconds to seconds before performing the subtraction, right?

The corrected code would be

const elapsedSeconds = new Decimal(Date.now()).div(1000).minus(lastUpdatedSeconds);

Date.now() returns the current timestamp in milliseconds, then .div(1000) converts the current time from milliseconds to seconds by dividing by 1000. finally .minus(lastUpdatedSeconds) subtracts lastUpdatedSeconds (which is already in seconds) from the current time in seconds.

const { lastUpdatedSeconds, standardOverdraft, additionalOverdraft } = options.paymentState;
const contractCost = await this.getConsumption({ id: options.id, graphqlURL: options.graphqlURL });
const elapsedSeconds = new Decimal(Date.now()).minus(lastUpdatedSeconds).div(1000);
const overdue = standardOverdraft
Copy link
Member

@sameh-farouk sameh-farouk Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain how the overdue is calculated, add a comment, and possibly simplify it by calculating it progressively using descriptive intermediary variable names?

const elapsedSeconds = new Decimal(Date.now()).minus(lastUpdatedSeconds).div(1000);
const overdue = standardOverdraft
.plus(additionalOverdraft)
.times(elapsedSeconds.plus(ONE_HOUR).times((contractCost / 60) * 60));
Copy link
Member

@sameh-farouk sameh-farouk Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Units are not consistent here.
From what I see elapsedSeconds is in seconds, while ONE_HOUR is in milliseconds.
Perhaps you intended to set ONE_HOUR to 3600 (seconds) instead of 3600000 (milliseconds)?

Also, I'm trying to understand why we divide by 60 and then multiply by 60.

.plus(additionalOverdraft)
.times(elapsedSeconds.plus(ONE_HOUR).times((contractCost / 60) * 60));

return Number(overdue.div(10 ** 7));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, add a comment to explain the division here, and/or first assign the result to a descriptive variable name like overdueTFT for better reliability, then return it. you can refer to the raw amount (before division) as overdueMicroTFT

*/
async calculateContractOverDue(options: CalculateOverdueOptions) {
const { lastUpdatedSeconds, standardOverdraft, additionalOverdraft } = options.paymentState;
const contractCost = await this.getConsumption({ id: options.id, graphqlURL: options.graphqlURL });
Copy link
Member

@sameh-farouk sameh-farouk Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an estimate, as some contracts might have public IP addresses, and the cost will depend on the amount of bandwidth used, which is likely to vary.

The cost calculation should simulate the billing process on tfchain (dry run) to provide a more accurate estimate. This involves checking the pricing policy, NU, and other resource consumption to determine the actual cost of the contract. Then, account for the time between the calculation and the submission of the transaction.

We still need to estimate the cost of this extra time, but it shouldn't be a problem. Since the cost changes dynamically, we should also update the cost accordingly. It's unlikely that we will receive a new NU report, especially if we refresh the cost at short intervals, such as every 10~20 seconds.

@0oM4R 0oM4R closed this Sep 11, 2024
@0oM4R
Copy link
Contributor Author

0oM4R commented Sep 11, 2024

changes on #3387

@0oM4R 0oM4R deleted the development_chainCompatibility branch September 11, 2024 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants