Skip to content

Commit

Permalink
Use filter for first msg and rest use watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
b-gopalswami committed Sep 17, 2024
1 parent 6287276 commit 12ad7e1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
44 changes: 44 additions & 0 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,8 @@ func (sourceCCIP *SourceCCIPModule) AssertSendRequestedLogFinalized(
return finalizedAt, finalizedBlockNum.Uint64(), nil
}

// IsRequestTriggeredWithinTimeframe monitors for live events occurring within the specified timeframe.
// Live events refer to those that are triggered after subscribing to the CCIP Send Requested event.
func (sourceCCIP *SourceCCIPModule) IsRequestTriggeredWithinTimeframe(timeframe *commonconfig.Duration) *time.Time {
if timeframe == nil {
return nil
Expand All @@ -1644,6 +1646,48 @@ func (sourceCCIP *SourceCCIPModule) IsRequestTriggeredWithinTimeframe(timeframe
return foundAt
}

// IsPastRequestTriggeredWithinTimeframe determines the average block time and calculates the block numbers
// within the specified timeframe. It then uses FilterCCIPSendRequested to identify the past events.
func (sourceCCIP *SourceCCIPModule) IsPastRequestTriggeredWithinTimeframe(timeframe *commonconfig.Duration, ctx context.Context) (*time.Time, error) {

Check failure on line 1651 in integration-tests/ccip-tests/actions/ccip_helpers.go

View workflow job for this annotation

GitHub Actions / Build and Lint integration-tests

context-as-argument: context.Context should be the first parameter of a function (revive)
if timeframe == nil {
return nil, fmt.Errorf("nil timeframe")
}
//var foundAt *time.Time
latestBlock, err := sourceCCIP.Common.ChainClient.LatestBlockNumber(ctx)
if err != nil {
return nil, fmt.Errorf("error while getting latest source block number. Error: %v", err)

Check failure on line 1658 in integration-tests/ccip-tests/actions/ccip_helpers.go

View workflow job for this annotation

GitHub Actions / Build and Lint integration-tests

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}
avgBlockTime, err := sourceCCIP.Common.ChainClient.AvgBlockTime(ctx)
if err != nil {
return nil, fmt.Errorf("error while getting average source block time. Error: %v", err)

Check failure on line 1662 in integration-tests/ccip-tests/actions/ccip_helpers.go

View workflow job for this annotation

GitHub Actions / Build and Lint integration-tests

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}
filterFromBlock := latestBlock - uint64(timeframe.Duration()/avgBlockTime)

onRampContract, err := evm_2_evm_onramp.NewEVM2EVMOnRamp(common.HexToAddress(sourceCCIP.OnRamp.EthAddress.Hex()),
sourceCCIP.Common.ChainClient.Backend())
if err != nil {
return nil, fmt.Errorf("error while on ramp contract. Error: %v", err)

Check failure on line 1669 in integration-tests/ccip-tests/actions/ccip_helpers.go

View workflow job for this annotation

GitHub Actions / Build and Lint integration-tests

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}
iterator, err := onRampContract.FilterCCIPSendRequested(&bind.FilterOpts{
Start: filterFromBlock,
})
if err != nil {
return nil, fmt.Errorf("error while filtering CCIP send requested starting block number: %d. Error: %v", filterFromBlock, err)
}
defer func() {
_ = iterator.Close()
}()
if iterator.Next() {
hdr, err := sourceCCIP.Common.ChainClient.HeaderByNumber(context.Background(), big.NewInt(int64(iterator.Event.Raw.BlockNumber)))
if err != nil {
return nil, fmt.Errorf("error getting header for block: %d, Error: %v", iterator.Event.Raw.BlockNumber, err)
}
return pointer.ToTime(hdr.Timestamp), nil
} else {

Check failure on line 1686 in integration-tests/ccip-tests/actions/ccip_helpers.go

View workflow job for this annotation

GitHub Actions / Build and Lint integration-tests

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return nil, nil
}
}

func (sourceCCIP *SourceCCIPModule) AssertEventCCIPSendRequested(
lggr *zerolog.Logger,
txHash string,
Expand Down
17 changes: 11 additions & 6 deletions integration-tests/ccip-tests/load/ccip_loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,18 @@ func (c *CCIPE2ELoad) CCIPMsg() (router.ClientEVM2AnyMessage, *testreporters.Req
func (c *CCIPE2ELoad) Call(_ *wasp.Generator) *wasp.Response {
res := &wasp.Response{}
sourceCCIP := c.Lane.Source
recentRequestFoundAt, err := sourceCCIP.IsRequestTriggeredWithinTimeframe(c.SkipRequestIfAnotherRequestTriggeredWithin,
testcontext.Get(c.t))
if err != nil {
res.Failed = true
res.Error = fmt.Sprintf("error while checking if there is any recent transactions. Error: %v", err.Error())
return res
var recentRequestFoundAt *time.Time
var err error
// Use IsPastRequestTriggeredWithinTimeframe to check for any historical CCIP send request events
// within the specified timeframe for the first message. Subsequently, use the watcher method to monitor
// and detect any new events as they occur.
if c.CurrentMsgSerialNo.Load() == int64(1) {
recentRequestFoundAt, err = sourceCCIP.IsPastRequestTriggeredWithinTimeframe(c.SkipRequestIfAnotherRequestTriggeredWithin, testcontext.Get(c.t))
require.NoError(c.t, err, "error while filtering past requests")
} else {
recentRequestFoundAt = sourceCCIP.IsRequestTriggeredWithinTimeframe(c.SkipRequestIfAnotherRequestTriggeredWithin)
}

if recentRequestFoundAt != nil {
c.Lane.Logger.
Info().
Expand Down

0 comments on commit 12ad7e1

Please sign in to comment.