Skip to content

Commit 773a691

Browse files
akaladarshiCopilot
andauthored
fix(api): use params tipset-key to load the tipset for gas premium calculation (#13357)
* fix: use params tipset key to load the tipset for gas premium calculation * address copilot comments Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 3b7e362 commit 773a691

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

node/impl/full/gas.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (a *GasAPI) GasEstimateFeeCap(
5757
maxqueueblks int64,
5858
tsk types.TipSetKey,
5959
) (types.BigInt, error) {
60-
return gasutils.GasEstimateFeeCap(a.Chain, msg, maxqueueblks)
60+
return gasutils.GasEstimateFeeCap(ctx, a.Chain, msg, maxqueueblks, tsk)
6161
}
6262

6363
func (m *GasModule) GasEstimateFeeCap(
@@ -66,27 +66,27 @@ func (m *GasModule) GasEstimateFeeCap(
6666
maxqueueblks int64,
6767
tsk types.TipSetKey,
6868
) (types.BigInt, error) {
69-
return gasutils.GasEstimateFeeCap(m.Chain, msg, maxqueueblks)
69+
return gasutils.GasEstimateFeeCap(ctx, m.Chain, msg, maxqueueblks, tsk)
7070
}
7171

7272
func (a *GasAPI) GasEstimateGasPremium(
7373
ctx context.Context,
7474
nblocksincl uint64,
7575
sender address.Address,
7676
gaslimit int64,
77-
_ types.TipSetKey,
77+
tsk types.TipSetKey,
7878
) (types.BigInt, error) {
79-
return gasutils.GasEstimateGasPremium(ctx, a.Chain, a.PriceCache, nblocksincl)
79+
return gasutils.GasEstimateGasPremium(ctx, a.Chain, a.PriceCache, nblocksincl, tsk)
8080
}
8181

8282
func (m *GasModule) GasEstimateGasPremium(
8383
ctx context.Context,
8484
nblocksincl uint64,
8585
sender address.Address,
8686
gaslimit int64,
87-
_ types.TipSetKey,
87+
tsk types.TipSetKey,
8888
) (types.BigInt, error) {
89-
return gasutils.GasEstimateGasPremium(ctx, m.Chain, m.PriceCache, nblocksincl)
89+
return gasutils.GasEstimateGasPremium(ctx, m.Chain, m.PriceCache, nblocksincl, tsk)
9090
}
9191

9292
func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, tsk types.TipSetKey) (int64, error) {
@@ -105,9 +105,9 @@ func (m *GasModule) GasEstimateGasLimit(ctx context.Context, msgIn *types.Messag
105105
return gasutils.GasEstimateGasLimit(ctx, m.Chain, m.Stmgr, m.Mpool, msgIn, ts)
106106
}
107107

108-
func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, _ types.TipSetKey) (*types.Message, error) {
108+
func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, ts types.TipSetKey) (*types.Message, error) {
109109
if msg.GasLimit == 0 {
110-
gasLimit, err := m.GasEstimateGasLimit(ctx, msg, types.EmptyTSK)
110+
gasLimit, err := m.GasEstimateGasLimit(ctx, msg, ts)
111111
if err != nil {
112112
return nil, err
113113
}
@@ -120,15 +120,15 @@ func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Messag
120120
}
121121

122122
if msg.GasPremium == types.EmptyInt || types.BigCmp(msg.GasPremium, types.NewInt(0)) == 0 {
123-
gasPremium, err := m.GasEstimateGasPremium(ctx, 10, msg.From, msg.GasLimit, types.EmptyTSK)
123+
gasPremium, err := m.GasEstimateGasPremium(ctx, 10, msg.From, msg.GasLimit, ts)
124124
if err != nil {
125125
return nil, xerrors.Errorf("estimating gas price: %w", err)
126126
}
127127
msg.GasPremium = gasPremium
128128
}
129129

130130
if msg.GasFeeCap == types.EmptyInt || types.BigCmp(msg.GasFeeCap, types.NewInt(0)) == 0 {
131-
feeCap, err := m.GasEstimateFeeCap(ctx, msg, 20, types.EmptyTSK)
131+
feeCap, err := m.GasEstimateFeeCap(ctx, msg, 20, ts)
132132
if err != nil {
133133
return nil, xerrors.Errorf("estimating fee cap: %w", err)
134134
}

node/impl/gasutils/gasutils.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ func GasEstimateGasLimit(
224224
return ret, nil
225225
}
226226

227-
func GasEstimateFeeCap(cstore ChainStoreAPI, msg *types.Message, maxqueueblks int64) (types.BigInt, error) {
228-
ts := cstore.GetHeaviestTipSet()
227+
func GasEstimateFeeCap(ctx context.Context, cstore ChainStoreAPI, msg *types.Message, maxqueueblks int64, tsk types.TipSetKey) (types.BigInt, error) {
228+
ts, err := cstore.GetTipSetFromKey(ctx, tsk)
229+
if err != nil {
230+
return types.BigInt{}, xerrors.Errorf("getting tipset from key: %w", err)
231+
}
229232

230233
parentBaseFee := ts.Blocks()[0].ParentBaseFee
231234
increaseFactor := math.Pow(1.+1./float64(buildconstants.BaseFeeMaxChangeDenom), float64(maxqueueblks))
@@ -240,15 +243,19 @@ func GasEstimateFeeCap(cstore ChainStoreAPI, msg *types.Message, maxqueueblks in
240243
return out, nil
241244
}
242245

243-
func GasEstimateGasPremium(ctx context.Context, cstore ChainStoreAPI, cache *GasPriceCache, nblocksincl uint64) (types.BigInt, error) {
246+
func GasEstimateGasPremium(ctx context.Context, cstore ChainStoreAPI, cache *GasPriceCache, nblocksincl uint64, tsKey types.TipSetKey) (types.BigInt, error) {
244247
if nblocksincl == 0 {
245248
nblocksincl = 1
246249
}
247250

248251
var prices []GasMeta
249252
var blocks int
250253

251-
ts := cstore.GetHeaviestTipSet()
254+
ts, err := cstore.GetTipSetFromKey(ctx, tsKey)
255+
if err != nil {
256+
return types.BigInt{}, xerrors.Errorf("getting tipset from key: %w", err)
257+
}
258+
252259
for i := uint64(0); i < nblocksincl*2; i++ {
253260
if ts.Height() == 0 {
254261
break // genesis

0 commit comments

Comments
 (0)