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

VM gas usage implementation and refactor #350

Merged
merged 17 commits into from
Apr 15, 2020
Merged

Conversation

austinabell
Copy link
Contributor

Summary of changes
Changes introduced in this pull request:

  • Implements gas consumption with explicit calls and implicit through GasBlockStore and GasSyscalls VM Gas metering and usage #332

    • GasTracker is the shared object which is shared between those two objects and the runtime itself. This is achieved by wrapping it in a Rc<RefCell<>> which can have a runtime panic if a mutable borrow is attempted when any other borrow exists so make sure if the GasTracker is borrowed that it is dropped as soon as possible
  • Removes error from Cid generation from Cbor bytes

    • Could have done before, but wanted to keep API as similar to upstream, but that isn't a concern anymore
  • Refactored some error handling, downcasting errors in future is going to be needed to match the patterns in go to interop 1:1 with exit codes and this is a step toward that

Reference issue to close (if applicable)

Closes #332

Other information and links

self.gas_tracker.borrow().gas_used()
}

fn gas_available(&self) -> i64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: add comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

private method but sure I'll add one

}
/// Returns gas required for signature verification
#[inline]
pub fn on_verify_signature(&self, sig_type: SignatureType, plain_text_size: usize) -> i64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice in the lotus implementation that they are passing back a SysErrInternal exit code if the retrieval of the costFn fails. Do we need to match this exit code?

Also, I would include the following TODO as mentioned here.

this cost is not persistable, create a LinearCost{a,b} struct that has a .Cost(x) -> ax + b

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nah, not needed, they are using a map to retrieve the function, we are just matching on all signature types, impossible for us to hit this

_proof: RegisteredProof,
_pieces: &[PieceInfo],
) -> i64 {
self.compute_unsealed_sector_cid_base
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: add a TODO here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is nothing else TODO for all of these, but I will add a comment to revisit as this probably will change in future

Copy link
Contributor

Choose a reason for hiding this comment

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

I figured a TODO must be required since we are not using the params?

}
/// Returns gas required for seal verification
#[inline]
pub fn on_verify_seal(&self, _info: &SealVerifyInfo) -> i64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: add a TODO here

}
/// Returns gas required for PoSt verification
#[inline]
pub fn on_verify_post(&self, _info: &PoStVerifyInfo) -> i64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: add a TODO here


/// Returns gas price list by Epoch for gas consumption
pub fn price_list_by_epoch(_epoch: ChainEpoch) -> PriceList {
// In future will match on epoch and select matching price lists when config options allowed
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit add TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is nothing to do here, the protocol is not supporting different price tables yet (unless I am mistaken), this is just a feature

Copy link
Member

@ec2 ec2 left a comment

Choose a reason for hiding this comment

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

I really like having the gas tracker object. LGTM

@austinabell austinabell merged commit 38825e7 into master Apr 15, 2020
@austinabell austinabell deleted the austin/vm/gasusage branch April 15, 2020 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VM Gas metering and usage
3 participants