From 26a780a1986dbeeb235374f62d9bf14291a66920 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 6 May 2022 11:39:13 -0400 Subject: [PATCH 1/3] Gas estimation: Refactor the special PayCh collect case --- node/impl/full/gas.go | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index dd1e8d5ea..53e4b5a03 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -295,31 +295,21 @@ func gasEstimateGasLimit( return -1, xerrors.Errorf("message execution failed: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error) } + ret := res.MsgRct.GasUsed + // 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 { - _ = 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 + 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 + } } - if !builtin.IsPaymentChannelActor(act.Code) { - return res.MsgRct.GasUsed, nil - } - if msgIn.Method != paych.Methods.Collect { - return res.MsgRct.GasUsed, nil - } - - // 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) { From 8282484f655e1079156d419d182e2963767b58bb Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 6 May 2022 11:50:43 -0400 Subject: [PATCH 2/3] Gas estimation: Overestimate by 2 around the M1 upgrade --- node/impl/full/gas.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 53e4b5a03..421beba2a 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -309,6 +309,11 @@ func gasEstimateGasLimit( } } + // Overestimate gas used around the + if ts.Height() <= build.UpgradeFVM1Height && (build.UpgradeFVM1Height-ts.Height() <= 5) { + ret *= 2 + } + return ret, nil } From 5fb69281d80cbfab9fd17f06cbc30257c5b090ab Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 9 May 2022 17:00:00 +0200 Subject: [PATCH 3/3] Estimate gas across the upgrade with per message multipliers Signed-off-by: Jakub Sztandera --- node/impl/full/gas.go | 46 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 421beba2a..73bc1ea85 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -297,6 +297,47 @@ func gasEstimateGasLimit( 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) + if err != nil { + return + } + act, err := st.GetActor(msg.To) + if err != nil { + return + } + + if builtin.IsStorageMinerActor(act.Code) { + 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: + } + } + + // skip storage market, 80th percentie for everything ~1.9, leave it at 2.0 + }() + } + 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 @@ -309,11 +350,6 @@ func gasEstimateGasLimit( } } - // Overestimate gas used around the - if ts.Height() <= build.UpgradeFVM1Height && (build.UpgradeFVM1Height-ts.Height() <= 5) { - ret *= 2 - } - return ret, nil }