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

Make max end hints a custom type #346

Merged
merged 1 commit into from
May 10, 2024
Merged

Make max end hints a custom type #346

merged 1 commit into from
May 10, 2024

Conversation

CodeSandwich
Copy link
Collaborator

This makes the calldata simpler by replacing zero-padded 4-byte words with a full word. The API also becomes cleaner by reducing the number of parameters.

Copy link
Collaborator

@xmxanuel xmxanuel 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. I think it is a nice improvement. However, it requires a good understanding of the hints to use it. Which might be okay because it is an optional gas improvement parameter.

src/Streams.sol Outdated
/// @param maxEndHint1 An optional parameter allowing gas optimization, pass `0` to ignore it.
/// The first hint for finding the maximum end time when all streams stop due to funds
/// @param maxEndHints An optional parameter allowing gas optimization.
/// Pass a list of 8 zero value hints to ignore it, it's represented as an integer `0`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// Pass a list of 8 zero value hints to ignore it, it's represented as an integer `0`.
/// Pass `0` to ignore it.

That's too complicated in my opinion list of 8 zero value hints for the reader who only wants to skip it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clarified.

src/Streams.sol Outdated
Comment on lines 746 to 748
/// Hints lower than the current timestamp including the zero value hints are ignored.
/// If you provide fewer than 8 non-zero value hints make them the rightmost values to save gas.
/// It's the best approach to make the most risky and precise hints the rightmost ones.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would good to mention specifically that there are no assumptions.

  • no specific ordering of the hints is strictly required
    • only the already mentioned gas improvement with risky hints on the right
  • all hints could be used to improve either higher bound or the lower bound
  • it is not required that hints come in pairs of two with a start and end
  • provided list only improves gas usage and has no impact on the outcome of the transaction

I think a potentially confusing part is: why is it a list with multiple hints.

Maybe a few strategies to illustrate the concept. Alternatively a link to some documentation

For example: Unkown block.timstamp of the new transactions together with streams which should stop when running out of funds:

  • risky hint pair a 1 min start/end range
  • 5 minute hint pair start/end range
  • 2 hours pair for the worst case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clarified.

if (hint2 > enoughEnd && hint2 < notEnoughEnd) {
if (_isBalanceEnough(balance, configs, configsLen, hint2)) {
enoughEnd = hint2;
while (maxEndHints.hasHints()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to double check.

uint256 enoughEnd = _currTimestamp();

Current timestamp will be always enoughEnd. This is an invariant of the system and can never be false.

Comment on lines +864 to +869
(maxEndHints, hint) = maxEndHints.pop();
if (hint <= enoughEnd || hint >= notEnoughEnd) continue;
if (_isBalanceEnough(balance, configs, configsLen, hint)) {
enoughEnd = hint;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Logic makes sense to me 👍

/// @param hints The list of hints.
/// @return newHints The modified list of hints.
/// @return hint The removed hint.
function pop(MaxEndHints hints) internal pure returns (MaxEndHints newHints, uint32 hint) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes sense to implement it with a pop instead of a read operation for a specific list index. (more costly)

Base automatically changed from igor/splits_api to main March 26, 2024 13:29
@CodeSandwich CodeSandwich marked this pull request as ready for review May 10, 2024 08:13
@CodeSandwich CodeSandwich merged commit a8932b9 into main May 10, 2024
1 check passed
@CodeSandwich CodeSandwich deleted the igor/hints branch May 10, 2024 08:14
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