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

feat(runtime): Track block gas allowance in builtins #4345

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ekovalev
Copy link
Member

The initial implementation of builtin actors overlooked the need of keeping track of the block gas allowance. So far only individual message gas limit has been taken in consideration.
Therefore cases of time-consuming computations in builtin actors's handle might affect the block time if not checked against available gas allowance.

Potential todo:

  • some builtins (like Bls12-381) burn gas for decoding a message payload before even knowing which function is then supposed to be called and how much more gas it will require. In case at the latter step we realize we will exceed the available gas allowance, the gas for decoding the payload would have already been burnt and will have to be spent for the second time in the next block when the message is processed again. So should we or should we not make the user pay for it?

@ekovalev ekovalev added A0-pleasereview PR is ready to be reviewed by the team D2-node Gear Node C1-feature Feature request labels Nov 18, 2024
Copy link
Member

@breathx breathx left a comment

Choose a reason for hiding this comment

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

Generally looks good. Regarding "potential todo" mentioned in the description: nobody should under no circumstances be charged for anything in case of gas allowance exceeded case.

@@ -93,6 +95,9 @@ pub enum BuiltinActorError {
/// Actor's inner error encoded as a String.
#[display(fmt = "Builtin execution resulted in error: {_0}")]
Custom(LimitedStr<'static>),
/// Occurs if a builtin actor execution does not fit in the current block.
#[display(fmt = "Block gas allowance exceeded")]
Copy link
Member

Choose a reason for hiding this comment

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

Im wondering If we could abstract it since it more about how system implemented rather than each particular builtin

}

gas_spent += to_spend;
gas_left -= to_spend;
Copy link
Member

Choose a reason for hiding this comment

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

saturating?

Copy link
Member Author

Choose a reason for hiding this comment

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

Safe due to a check above - if gas_left is less than to_spend we abort earlier

Copy link
Member Author

Choose a reason for hiding this comment

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

But for the sake of universality we can use saturated arithmetics - no problem

}

gas_spent += to_spend;
gas_left -= to_spend;
Copy link
Member

Choose a reason for hiding this comment

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

here and in other places

Copy link
Member

@gshep gshep left a comment

Choose a reason for hiding this comment

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

Good job! 🥇

@breathx breathx added A3-gotissues PR occurred to have issues after the review and removed A0-pleasereview PR is ready to be reviewed by the team labels Nov 27, 2024
@breathx
Copy link
Member

breathx commented Nov 27, 2024

discussed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A3-gotissues PR occurred to have issues after the review C1-feature Feature request D2-node Gear Node
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants