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

Gas estimation: Overestimate based on (actor, method) tuples #8620

Merged
merged 3 commits into from
May 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 52 additions & 21 deletions node/impl/full/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,31 +295,62 @@ func gasEstimateGasLimit(
return -1, xerrors.Errorf("message execution failed: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error)
}

// Special case for PaymentChannel collect, which is deleting actor
st, err := smgr.ParentState(ts)
if err != nil {
_ = err
// somewhat ignore it as it can happen and we just want to detect
// an existing PaymentChannel actor
return res.MsgRct.GasUsed, nil
}
act, err := st.GetActor(msg.To)
if err != nil {
_ = err
// somewhat ignore it as it can happen and we just want to detect
// an existing PaymentChannel actor
return res.MsgRct.GasUsed, nil
ret := res.MsgRct.GasUsed

transitionalMulti := 1.0
// Overestimate gas around the upgrade
if ts.Height() <= build.UpgradeFVM1Height && (build.UpgradeFVM1Height-ts.Height() <= 20) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How did you pick 20 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.

This gives us 10 minutes of overestimation, there are few reasons I went with 20 epochs.
I would be comfortable with 5 minutes, if we didn’t have tipset system, possible off-by-ones somewhere so on, and I feel like increasing it to 10min has a low cost.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems reasonable -- i don't think there's a "correct" answer here.

transitionalMulti = 2.0

func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

what do we gain by using an anonymous function 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.

It cleans up the error handling.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, makes sense

st, err := smgr.ParentState(ts)
if err != nil {
return
}
act, err := st.GetActor(msg.To)
if err != nil {
return
}

if builtin.IsStorageMinerActor(act.Code) {
switch msgIn.Method {
case 5:
Copy link
Contributor

Choose a reason for hiding this comment

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

case miner.Methods.SubmitWindowedPoSt? (and so on for others)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This corresponds to what is reported in collected statistics so it is easier to verify if it stays as numbers, also as this is very temporary code there is little to no harm to having raw numbers.

If you feel strongly about it I can add comments with method names.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel strongly about it, no.

if you want me to double check the values against the collected statistics, i can, but i trust you

transitionalMulti = 3.954
case 6:
transitionalMulti = 4.095
case 7:
// skip, stay at 2.0
//transitionalMulti = 1.289
case 11:
transitionalMulti = 17.8758
case 16:
transitionalMulti = 2.1704
case 25:
transitionalMulti = 3.1177
case 26:
transitionalMulti = 2.3322
default:
}
}

// skip storage market, 80th percentie for everything ~1.9, leave it at 2.0
}()
}
ret = (ret * int64(transitionalMulti*1024)) >> 10

if !builtin.IsPaymentChannelActor(act.Code) {
return res.MsgRct.GasUsed, nil
}
if msgIn.Method != paych.Methods.Collect {
return res.MsgRct.GasUsed, nil
// Special case for PaymentChannel collect, which is deleting actor
// We ignore errors in this special case since they CAN occur,
// and we just want to detect existing payment channel actors
st, err := smgr.ParentState(ts)
if err == nil {
act, err := st.GetActor(msg.To)
if err == nil && builtin.IsPaymentChannelActor(act.Code) && msgIn.Method == paych.Methods.Collect {
// add the refunded gas for DestroyActor back into the gas used
ret += 76e3
}
}

// return GasUsed without the refund for DestoryActor
return res.MsgRct.GasUsed + 76e3, nil
return ret, nil
}

func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, _ types.TipSetKey) (*types.Message, error) {
Expand Down