Skip to content

Commit

Permalink
Merge branch 'ccip-develop' into feature/selfServeFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweintraub authored Sep 20, 2024
2 parents 58bdf08 + 97f6f55 commit 1e8cbe2
Show file tree
Hide file tree
Showing 68 changed files with 2,489 additions and 121 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-onions-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#changed Make Mantle use default OP stack l1 gas oracle in core
5 changes: 5 additions & 0 deletions .changeset/great-timers-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Updated gas limit estimation feature to set From address #internal
5 changes: 5 additions & 0 deletions .changeset/green-eagles-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Handle zkEVM node level OOC error as TerminallyStuck #internal
5 changes: 5 additions & 0 deletions .changeset/loud-windows-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Added gas limit estimation feature to EVM gas estimators. Introduced a new config `EVM.GasEstimator.EstimateLimit` to toggle this feature. #added
5 changes: 5 additions & 0 deletions .changeset/seven-kiwis-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Added custom client error messages for Mantle to capture InsufficientEth and Fatal errors. #added
5 changes: 5 additions & 0 deletions .changeset/shiny-hornets-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Introduce new gas estimator #internal
5 changes: 5 additions & 0 deletions .changeset/two-mugs-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Edited the Optimism Stack L1 Oracle to add support for Mantle #added
3 changes: 3 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ packages:
feeEstimatorClient:
config:
mockname: FeeEstimatorClient
feeHistoryEstimatorClient:
config:
mockname: FeeHistoryEstimatorClient
EvmEstimator:
github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups:
interfaces:
Expand Down
3 changes: 2 additions & 1 deletion common/fee/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
ErrBumpFeeExceedsLimit = errors.New("fee bump exceeds limit")
ErrBump = errors.New("fee bump failed")
ErrConnectivity = errors.New("transaction propagation issue: transactions are not being mined")
ErrFeeLimitTooLow = errors.New("provided fee limit too low")
)

func IsBumpErr(err error) bool {
Expand Down Expand Up @@ -63,7 +64,7 @@ func CalculateBumpedFee(
// Returns highest bumped fee price of originalFeePrice bumped by fixed units or percentage.
func MaxBumpedFee(originalFeePrice *big.Int, feeBumpPercent uint16, feeBumpUnits *big.Int) *big.Int {
return bigmath.Max(
addPercentage(originalFeePrice, feeBumpPercent),
AddPercentage(originalFeePrice, feeBumpPercent),
new(big.Int).Add(originalFeePrice, feeBumpUnits),
)
}
Expand Down
2 changes: 1 addition & 1 deletion common/fee/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ApplyMultiplier(feeLimit uint64, multiplier float32) (uint64, error) {
}

// Returns the input value increased by the given percentage.
func addPercentage(value *big.Int, percentage uint16) *big.Int {
func AddPercentage(value *big.Int, percentage uint16) *big.Int {
bumped := new(big.Int)
bumped.Mul(value, big.NewInt(int64(100+percentage)))
bumped.Div(bumped, big.NewInt(100))
Expand Down
7 changes: 6 additions & 1 deletion common/txmgr/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/utils"

"github.com/smartcontractkit/chainlink/v2/common/client"
commonfee "github.com/smartcontractkit/chainlink/v2/common/fee"
feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
Expand Down Expand Up @@ -434,7 +435,11 @@ func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) hand
}

attempt, _, _, retryable, err := eb.NewTxAttempt(ctx, *etx, eb.lggr)
if err != nil {
// Mark transaction as fatal if provided gas limit is set too low
if errors.Is(err, commonfee.ErrFeeLimitTooLow) {
etx.Error = null.StringFrom(commonfee.ErrFeeLimitTooLow.Error())
return eb.saveFatallyErroredTransaction(eb.lggr, etx), false
} else if err != nil {
return fmt.Errorf("processUnstartedTxs failed on NewAttempt: %w", err), retryable
}

Expand Down
9 changes: 9 additions & 0 deletions core/chains/evm/client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Client interface {
SuggestGasPrice(ctx context.Context) (*big.Int, error)
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
LatestBlockHeight(ctx context.Context) (*big.Int, error)
FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error)

HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error)
HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error)
Expand Down Expand Up @@ -353,6 +354,14 @@ func (c *chainClient) LatestFinalizedBlock(ctx context.Context) (*evmtypes.Head,
return c.multiNode.LatestFinalizedBlock(ctx)
}

func (c *chainClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
rpc, err := c.multiNode.SelectNodeRPC()
if err != nil {
return feeHistory, err
}
return rpc.FeeHistory(ctx, blockCount, rewardPercentiles)
}

func (c *chainClient) CheckTxValidity(ctx context.Context, from common.Address, to common.Address, data []byte) *SendError {
msg := ethereum.CallMsg{
From: from,
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ var zkSync = ClientErrors{
}

var zkEvm = ClientErrors{
TerminallyStuck: regexp.MustCompile(`(?:: |^)not enough .* counters to continue the execution$`),
TerminallyStuck: regexp.MustCompile(`(?:: |^)(?:not enough .* counters to continue the execution|out of counters at node level (?:.*))$`),
}

var aStar = ClientErrors{
Expand Down
5 changes: 5 additions & 0 deletions core/chains/evm/client/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func Test_Eth_Errors(t *testing.T) {
{"insufficient funds for gas + value. balance: 42719769622667482000, fee: 48098250000000, value: 42719769622667482000", true, "celo"},
{"client error insufficient eth", true, "tomlConfig"},
{"transaction would cause overdraft", true, "Geth"},
{"failed to forward tx to sequencer, please try again. Error message: 'insufficient funds for gas * price + value'", true, "Mantle"},
}
for _, test := range tests {
err = evmclient.NewSendErrorS(test.message)
Expand Down Expand Up @@ -316,6 +317,8 @@ func Test_Eth_Errors(t *testing.T) {
{"failed to add tx to the pool: not enough step counters to continue the execution", true, "Xlayer"},
{"failed to add tx to the pool: not enough keccak counters to continue the execution", true, "zkEVM"},
{"failed to add tx to the pool: not enough keccak counters to continue the execution", true, "Xlayer"},
{"RPC error response: failed to add tx to the pool: out of counters at node level (Steps)", true, "zkEVM"},
{"RPC error response: failed to add tx to the pool: out of counters at node level (GasUsed, KeccakHashes, PoseidonHashes, PoseidonPaddings, MemAligns, Arithmetics, Binaries, Steps, Sha256Hashes)", true, "Xlayer"},
}

for _, test := range tests {
Expand Down Expand Up @@ -400,6 +403,8 @@ func Test_Eth_Errors_Fatal(t *testing.T) {
{"Failed to serialize transaction: max priority fee per gas higher than 2^64-1", true, "zkSync"},
{"Failed to serialize transaction: oversized data. max: 1000000; actual: 1000000", true, "zkSync"},

{"failed to forward tx to sequencer, please try again. Error message: 'invalid sender'", true, "Mantle"},

{"client error fatal", true, "tomlConfig"},
{"invalid chain id for signer", true, "Treasure"},
}
Expand Down
60 changes: 60 additions & 0 deletions core/chains/evm/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions core/chains/evm/client/mocks/rpc_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions core/chains/evm/client/null_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,7 @@ func (nc *NullClient) LatestFinalizedBlock(_ context.Context) (*evmtypes.Head, e
func (nc *NullClient) CheckTxValidity(_ context.Context, _ common.Address, _ common.Address, _ []byte) *SendError {
return nil
}

func (nc *NullClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
return nil, nil
}
25 changes: 25 additions & 0 deletions core/chains/evm/client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type RPCClient interface {
SuggestGasTipCap(ctx context.Context) (t *big.Int, err error)
TransactionReceiptGeth(ctx context.Context, txHash common.Hash) (r *types.Receipt, err error)
GetInterceptedChainInfo() (latest, highestUserObservations commonclient.ChainInfo)
FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error)
}

const rpcSubscriptionMethodNewHeads = "newHeads"
Expand Down Expand Up @@ -599,6 +600,7 @@ func (r *rpcClient) TransactionReceiptGeth(ctx context.Context, txHash common.Ha

return
}

func (r *rpcClient) TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, err error) {
ctx, cancel, ws, http := r.makeLiveQueryCtxAndSafeGetClients(ctx, r.rpcTimeout)
defer cancel()
Expand Down Expand Up @@ -1119,6 +1121,29 @@ func (r *rpcClient) BalanceAt(ctx context.Context, account common.Address, block
return
}

func (r *rpcClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
ctx, cancel, ws, http := r.makeLiveQueryCtxAndSafeGetClients(ctx, r.rpcTimeout)
defer cancel()
lggr := r.newRqLggr().With("blockCount", blockCount, "rewardPercentiles", rewardPercentiles)

lggr.Debug("RPC call: evmclient.Client#FeeHistory")
start := time.Now()
if http != nil {
feeHistory, err = http.geth.FeeHistory(ctx, blockCount, nil, rewardPercentiles)
err = r.wrapHTTP(err)
} else {
feeHistory, err = ws.geth.FeeHistory(ctx, blockCount, nil, rewardPercentiles)
err = r.wrapWS(err)
}
duration := time.Since(start)

r.logResult(lggr, err, duration, r.getRPCDomain(), "FeeHistory",
"feeHistory", feeHistory,
)

return
}

// CallArgs represents the data used to call the balance method of a contract.
// "To" is the address of the ERC contract. "Data" is the message sent
// to the contract. "From" is the sender address.
Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/client/simulated_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ func (c *SimulatedBackendClient) LINKBalance(ctx context.Context, address common
panic("not implemented")
}

func (c *SimulatedBackendClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
panic("not implemented")
}

// TransactionReceipt returns the transaction receipt for the given transaction hash.
func (c *SimulatedBackendClient) TransactionReceipt(ctx context.Context, receipt common.Hash) (*types.Receipt, error) {
return c.b.TransactionReceipt(ctx, receipt)
Expand Down
18 changes: 18 additions & 0 deletions core/chains/evm/config/chain_scoped_gas_estimator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"time"

gethcommon "github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
Expand Down Expand Up @@ -36,6 +38,10 @@ func (g *gasEstimatorConfig) BlockHistory() BlockHistory {
return &blockHistoryConfig{c: g.c.BlockHistory, blockDelay: g.blockDelay, bumpThreshold: g.c.BumpThreshold}
}

func (g *gasEstimatorConfig) FeeHistory() FeeHistory {
return &feeHistoryConfig{c: g.c.FeeHistory}
}

func (g *gasEstimatorConfig) EIP1559DynamicFees() bool {
return *g.c.EIP1559DynamicFees
}
Expand Down Expand Up @@ -108,6 +114,10 @@ func (g *gasEstimatorConfig) LimitJobType() LimitJobType {
return &limitJobTypeConfig{c: g.c.LimitJobType}
}

func (g *gasEstimatorConfig) EstimateLimit() bool {
return *g.c.EstimateLimit
}

type limitJobTypeConfig struct {
c toml.GasLimitJobType
}
Expand Down Expand Up @@ -172,3 +182,11 @@ func (b *blockHistoryConfig) TransactionPercentile() uint16 {
func (b *blockHistoryConfig) BlockDelay() uint16 {
return *b.blockDelay
}

type feeHistoryConfig struct {
c toml.FeeHistoryEstimator
}

func (u *feeHistoryConfig) CacheTimeout() time.Duration {
return u.c.CacheTimeout.Duration()
}
Loading

0 comments on commit 1e8cbe2

Please sign in to comment.