Skip to content

Commit

Permalink
update metadata implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkmin committed Jun 24, 2022
1 parent 8e74a8c commit 97982cb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions services/construction/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,24 @@ func (a *APIService) ConstructionMetadata(
return nil, svcErrors.WrapErr(svcErrors.ErrGeth, err)
}

// Ensure the gas tip is at least 30 gwei. This is the minimum gas price recommended by the Polygon team.
// See https://forum.polygon.technology/t/recommended-min-gas-price-setting/7604 for additional context.
// This minimum must be applied to the tip, not the cap to effectivley mitigate spam (since the tip goes to miners)
minTip := big.NewInt(30000000000) // 30 gwei
if minTip.Cmp(gasTip) == 1 {
gasTip = minTip
}

var gasCap *big.Int
if input.GasCap == nil {
// Set default max fee to double the last base fee plus priority tip
// Set default max fee to double the last base fee plus multiplied priority tip
// to ensure tx is highly likely to go out in the next block.
multiplier := big.NewInt(2)
gasCap = new(big.Int).Add(gasTip, new(big.Int).Mul(header.BaseFee, multiplier))
} else {
gasCap = input.GasCap
}

// Ensure the gas cap is at least 30 gwei, the minimum gas price that the node will accept on mainnet.
// See https://forum.polygon.technology/t/recommended-min-gas-price-setting/7604 for additional context.
minFee := big.NewInt(30000000000) // 30 gwei
if minFee.Cmp(gasCap) == 1 {
gasCap = minFee
}

metadata := &metadata{
Nonce: nonce,
GasLimit: gasLimit,
Expand All @@ -152,7 +153,7 @@ func (a *APIService) ConstructionMetadata(
}

// Find suggested gas usage. Note that this figure accounts for the minimum (30 gwei), and
// is potentially doubled the block base fee.
// is potentially double the block base fee.
suggestedFee := gasCap.Int64() * int64(gasLimit)

return &types.ConstructionMetadataResponse{
Expand Down

0 comments on commit 97982cb

Please sign in to comment.