From 352ce2207e1281d8f83bfc2daf44a000588d563a Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 1 Mar 2024 23:56:49 -0800 Subject: [PATCH] more optimize --- .../ccip-tests/actions/ccip_helpers.go | 58 +++++++++++++++---- .../ccip-tests/load/ccip_loadgen.go | 8 +-- integration-tests/ccip-tests/load/helper.go | 3 +- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/integration-tests/ccip-tests/actions/ccip_helpers.go b/integration-tests/ccip-tests/actions/ccip_helpers.go index 2595d8a21a..c852b7e247 100644 --- a/integration-tests/ccip-tests/actions/ccip_helpers.go +++ b/integration-tests/ccip-tests/actions/ccip_helpers.go @@ -13,6 +13,7 @@ import ( "time" "github.com/AlekSi/pointer" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -37,7 +38,6 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" - "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/contracts/laneconfig" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/testconfig" @@ -146,6 +146,18 @@ type CCIPCommon struct { priceUpdateSubs []event.Subscription } +// FreeUpUnusedSpace sets nil to various elements of ccipModule which are only used +// during lane set up and not used for rest of the test duration +// this is called mainly by load test to keep the memory usage minimum for high number of lanes +func (ccipModule *CCIPCommon) FreeUpUnusedSpace() { + ccipModule.PriceAggregators = nil + ccipModule.BridgeTokenPools = []*contracts.TokenPool{} + ccipModule.gasUpdateWatcher = nil + ccipModule.gasUpdateWatcherMu = nil + ccipModule.TokenMessenger = nil + ccipModule.PriceRegistry = nil +} + func (ccipModule *CCIPCommon) StopWatchingPriceUpdates() { for _, sub := range ccipModule.priceUpdateSubs { sub.Unsubscribe() @@ -2990,24 +3002,48 @@ func (c *CCIPTestEnv) SetUpNodeKeysAndFund( } }() log.Info().Str("chain id", c1.GetChainID().String()).Msg("Funding Chainlink nodes for chain") - err = actions.FundChainlinkNodesAddresses(chainlinkNodes[1:], c1, nodeFund) - if err != nil { - return fmt.Errorf("funding nodes for chain %s %w", c1.GetNetworkName(), err) + for i := 1; i < len(chainlinkNodes); i++ { + cl := chainlinkNodes[i] + m := c.nodeMutexes[i] + toAddress, err := cl.EthAddressesForChain(c1.GetChainID().String()) + if err != nil { + return err + } + for _, addr := range toAddress { + toAddr := common.HexToAddress(addr) + gasEstimates, err := c1.EstimateGas(ethereum.CallMsg{ + To: &toAddr, + }) + if err != nil { + return err + } + m.Lock() + err = c1.Fund(addr, nodeFund, gasEstimates) + m.Unlock() + if err != nil { + return err + } + } } - return nil + return c1.WaitForEvents() } - + grp, _ := errgroup.WithContext(context.Background()) for _, chain := range chains { err := populateKeys(chain) if err != nil { return err } - err = fund(chain) - if err != nil { - return err - } } - + for _, chain := range chains { + chain := chain + grp.Go(func() error { + return fund(chain) + }) + } + err := grp.Wait() + if err != nil { + return fmt.Errorf("error funding nodes %w", err) + } c.CLNodesWithKeys = nodesWithKeys return nil diff --git a/integration-tests/ccip-tests/load/ccip_loadgen.go b/integration-tests/ccip-tests/load/ccip_loadgen.go index a950123bdd..3dc32e5078 100644 --- a/integration-tests/ccip-tests/load/ccip_loadgen.go +++ b/integration-tests/ccip-tests/load/ccip_loadgen.go @@ -21,7 +21,6 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/blockchain" - "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/contracts" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers" @@ -131,10 +130,11 @@ func (c *CCIPE2ELoad) BeforeAllCall(msgType string, gasLimit *big.Int) { sourceCCIP.Common.ChainClient.ParallelTransactions(false) destCCIP.Common.ChainClient.ParallelTransactions(false) - // delete all pools as we don't need it anymore + // this is just to free up memory space for scalability tests with high number of token and pools - sourceCCIP.Common.BridgeTokenPools = []*contracts.TokenPool{} - destCCIP.Common.BridgeTokenPools = []*contracts.TokenPool{} + sourceCCIP.Common.FreeUpUnusedSpace() + destCCIP.Common.FreeUpUnusedSpace() + // close all header subscriptions for dest chains queuedEvents := destCCIP.Common.ChainClient.GetHeaderSubscriptions() for subName := range queuedEvents { diff --git a/integration-tests/ccip-tests/load/helper.go b/integration-tests/ccip-tests/load/helper.go index 65a289b40c..c36368628a 100644 --- a/integration-tests/ccip-tests/load/helper.go +++ b/integration-tests/ccip-tests/load/helper.go @@ -144,7 +144,6 @@ func (l *LoadArgs) TriggerLoadByLane() { SharedData: l.TestCfg.TestGroupInput.MsgType, LokiConfig: wasp.NewLokiConfig(lokiConfig.Endpoint, lokiConfig.TenantId, nil, nil), Labels: labels, - FailOnErr: true, }) require.NoError(l.TestCfg.Test, err, "initiating loadgen for lane %s --> %s", lane.SourceNetworkName, lane.DestNetworkName) @@ -272,7 +271,7 @@ func (l *LoadArgs) TriggerLoadBySource() { Logger: multiCallGen.logger, LokiConfig: wasp.NewLokiConfig(lokiConfig.Endpoint, lokiConfig.TenantId, nil, nil), Labels: allLabels, - FailOnErr: true, + FailOnErr: false, }) require.NoError(l.TestCfg.Test, err, "initiating loadgen for source %s", source) loadRunner.Run(false)