Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions node/impl/full/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (a *GasAPI) GasEstimateFeeCap(
maxqueueblks int64,
tsk types.TipSetKey,
) (types.BigInt, error) {
return gasutils.GasEstimateFeeCap(a.Chain, msg, maxqueueblks)
return gasutils.GasEstimateFeeCap(ctx, a.Chain, msg, maxqueueblks, tsk)
}

func (m *GasModule) GasEstimateFeeCap(
Expand All @@ -66,27 +66,27 @@ func (m *GasModule) GasEstimateFeeCap(
maxqueueblks int64,
tsk types.TipSetKey,
) (types.BigInt, error) {
return gasutils.GasEstimateFeeCap(m.Chain, msg, maxqueueblks)
return gasutils.GasEstimateFeeCap(ctx, m.Chain, msg, maxqueueblks, tsk)
}

func (a *GasAPI) GasEstimateGasPremium(
ctx context.Context,
nblocksincl uint64,
sender address.Address,
gaslimit int64,
_ types.TipSetKey,
tsk types.TipSetKey,
) (types.BigInt, error) {
return gasutils.GasEstimateGasPremium(ctx, a.Chain, a.PriceCache, nblocksincl)
return gasutils.GasEstimateGasPremium(ctx, a.Chain, a.PriceCache, nblocksincl, tsk)
}

func (m *GasModule) GasEstimateGasPremium(
ctx context.Context,
nblocksincl uint64,
sender address.Address,
gaslimit int64,
_ types.TipSetKey,
tsk types.TipSetKey,
) (types.BigInt, error) {
return gasutils.GasEstimateGasPremium(ctx, m.Chain, m.PriceCache, nblocksincl)
return gasutils.GasEstimateGasPremium(ctx, m.Chain, m.PriceCache, nblocksincl, tsk)
}

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

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, ts types.TipSetKey) (*types.Message, error) {
if msg.GasLimit == 0 {
gasLimit, err := m.GasEstimateGasLimit(ctx, msg, types.EmptyTSK)
gasLimit, err := m.GasEstimateGasLimit(ctx, msg, ts)
if err != nil {
return nil, err
}
Expand All @@ -120,15 +120,15 @@ func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Messag
}

if msg.GasPremium == types.EmptyInt || types.BigCmp(msg.GasPremium, types.NewInt(0)) == 0 {
gasPremium, err := m.GasEstimateGasPremium(ctx, 10, msg.From, msg.GasLimit, types.EmptyTSK)
gasPremium, err := m.GasEstimateGasPremium(ctx, 10, msg.From, msg.GasLimit, ts)
if err != nil {
return nil, xerrors.Errorf("estimating gas price: %w", err)
}
msg.GasPremium = gasPremium
}

if msg.GasFeeCap == types.EmptyInt || types.BigCmp(msg.GasFeeCap, types.NewInt(0)) == 0 {
feeCap, err := m.GasEstimateFeeCap(ctx, msg, 20, types.EmptyTSK)
feeCap, err := m.GasEstimateFeeCap(ctx, msg, 20, ts)
if err != nil {
return nil, xerrors.Errorf("estimating fee cap: %w", err)
}
Expand Down
15 changes: 11 additions & 4 deletions node/impl/gasutils/gasutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ func GasEstimateGasLimit(
return ret, nil
}

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

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

func GasEstimateGasPremium(ctx context.Context, cstore ChainStoreAPI, cache *GasPriceCache, nblocksincl uint64) (types.BigInt, error) {
func GasEstimateGasPremium(ctx context.Context, cstore ChainStoreAPI, cache *GasPriceCache, nblocksincl uint64, tsKey types.TipSetKey) (types.BigInt, error) {
if nblocksincl == 0 {
nblocksincl = 1
}

var prices []GasMeta
var blocks int

ts := cstore.GetHeaviestTipSet()
ts, err := cstore.GetTipSetFromKey(ctx, tsKey)
if err != nil {
return types.BigInt{}, xerrors.Errorf("getting tipset from key: %w", err)
}

for i := uint64(0); i < nblocksincl*2; i++ {
if ts.Height() == 0 {
break // genesis
Expand Down