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

fix(pallet): rework billing loop #702

Merged
merged 6 commits into from
May 24, 2023

Conversation

renauter
Copy link
Collaborator

@renauter renauter marked this pull request as ready for review May 24, 2023 00:09
@@ -534,8 +534,10 @@ pub mod pallet {
let _account_id = ensure_signed(origin)?;

// Clean up contract from billing loop if it doesn't exist anymore
// This is the only place it should be done to guaranty we
Copy link
Contributor

Choose a reason for hiding this comment

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

guarantee*

Copy link
Contributor

@DylanVerstraete DylanVerstraete left a comment

Choose a reason for hiding this comment

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

Looks good, some comments

continue;
}
}
}
let _res = Self::bill_contract_using_signed_transaction(contract_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

move this one line up? If there is no contract (deleted somehow but still in billing loop) we don't want to push an extrinsic?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, lets check #703 (comment) for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

move this one line up? If there is no contract (deleted somehow but still in billing loop) we don't want to push an extrinsic?

cannot move this line up because when contract is deleted its id in billing loop is cleaned up at next cycle by pushing the extrinsic

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I just noticed that as well this morning, but it's very weird and hidden behaviour. It's not clear that it's subject to the offchain worker to be cleaned up or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

For now let's keep this behaviour but let's plan a future improvement where we redesign the connection between a contract and it's billing status / cycle

Comment on lines 685 to 686
let bill_cu_su = NodeContractResources::<T>::contains_key(contract_id)
&& !NodeContractResources::<T>::get(contract_id).used.is_empty();
Copy link
Contributor

Choose a reason for hiding this comment

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

why contains_key and get afterwards ? I think get suffices because of the ValueQuery storage definition (default when not present)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed
But I have a conceptual case here
Ok, I am aware the get will return default value
And what if a default value was intentionally pushed? how to differentiate both scenarios? (nothing pushed / default value pushed)

Copy link
Contributor

Choose a reason for hiding this comment

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

And what if a default value was intentionally pushed?

This is something that is bad practice and should be avoided, it also results in the same. To me, this looks like 2 storage reads while it can be only 1 storage read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly, in our case it results the same
But if we change the default value for the resource we are broken
So, I ll get rid of extra storage read and add comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we broken if we change the default value for resources? .used.is_empty() should always check if all values are 0 and this should not change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if for some reason we set this for example

    pub fn default() -> Resources {
        Resources {
            hru: 1,
            sru: 1,
            cru: 1,
            mru: 1,
        }
    }

    pub fn empty() -> Resources {
        Resources {
            hru: 0,
            sru: 0,
            cru: 0,
            mru: 0,
        }
    }
   

Copy link
Contributor

Choose a reason for hiding this comment

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

well, if the default is any other than 0 values, the user has to pay anyway

Comment on lines 688 to 689
ContractBillingInformationByID::<T>::contains_key(contract_id)
&& ContractBillingInformationByID::<T>::get(contract_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

why contains_key and get afterwards ? I think get suffices because of the ValueQuery storage definition (default when not present)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same idea here

@DylanVerstraete DylanVerstraete merged commit c471f19 into development May 24, 2023
@DylanVerstraete DylanVerstraete deleted the development_fix_billing_loop branch May 24, 2023 12:29
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