Skip to content

Commit

Permalink
more optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Mar 2, 2024
1 parent 70c0baf commit 352ce22
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
58 changes: 47 additions & 11 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/ccip-tests/load/ccip_loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/ccip-tests/load/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 352ce22

Please sign in to comment.