Merge pull request #8620 from filecoin-project/feat/upgrade-gas-est

Gas estimation: Overestimate based on (actor, method) tuples
This commit is contained in:
Jakub Sztandera 2022-05-09 21:09:40 +02:00 committed by GitHub
commit e1a3ef4266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -295,31 +295,62 @@ func gasEstimateGasLimit(
return -1, xerrors.Errorf("message execution failed: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error) 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 ret := res.MsgRct.GasUsed
transitionalMulti := 1.0
// Overestimate gas around the upgrade
if ts.Height() <= build.UpgradeFVM1Height && (build.UpgradeFVM1Height-ts.Height() <= 20) {
transitionalMulti = 2.0
func() {
st, err := smgr.ParentState(ts) st, err := smgr.ParentState(ts)
if err != nil { if err != nil {
_ = err return
// 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) act, err := st.GetActor(msg.To)
if err != nil { if err != nil {
_ = err return
// somewhat ignore it as it can happen and we just want to detect
// an existing PaymentChannel actor
return res.MsgRct.GasUsed, nil
} }
if !builtin.IsPaymentChannelActor(act.Code) { if builtin.IsStorageMinerActor(act.Code) {
return res.MsgRct.GasUsed, nil switch msgIn.Method {
case 5:
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:
} }
if msgIn.Method != paych.Methods.Collect {
return res.MsgRct.GasUsed, nil
} }
// return GasUsed without the refund for DestoryActor // skip storage market, 80th percentie for everything ~1.9, leave it at 2.0
return res.MsgRct.GasUsed + 76e3, nil }()
}
ret = (ret * int64(transitionalMulti*1024)) >> 10
// 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 ret, nil
} }
func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, _ types.TipSetKey) (*types.Message, error) { func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, _ types.TipSetKey) (*types.Message, error) {