Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCIP-3420: Fix IsRequestTriggeredWithinTimeframe #1445

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1616,28 +1616,45 @@
return finalizedAt, finalizedBlockNum.Uint64(), nil
}

func (sourceCCIP *SourceCCIPModule) IsRequestTriggeredWithinTimeframe(timeframe *commonconfig.Duration) *time.Time {
// IsRequestTriggeredWithinTimeframe finds the average block time and picks the block number based on given timeframe and FilterCCIPSendRequested
func (sourceCCIP *SourceCCIPModule) IsRequestTriggeredWithinTimeframe(timeframe *commonconfig.Duration, ctx context.Context) (*time.Time, error) {

Check failure on line 1620 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
return nil, fmt.Errorf("nil timeframe")
}
var foundAt *time.Time
lastSeenTimestamp := time.Now().UTC().Add(-timeframe.Duration())
sourceCCIP.CCIPSendRequestedWatcher.Range(func(_, value any) bool {
if sendRequestedEvents, exists := value.([]*evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested); exists {
for _, sendRequestedEvent := range sendRequestedEvents {
raw := sendRequestedEvent.Raw
hdr, err := sourceCCIP.Common.ChainClient.HeaderByNumber(context.Background(), big.NewInt(int64(raw.BlockNumber)))
if err == nil {
if hdr.Timestamp.After(lastSeenTimestamp) {
foundAt = pointer.ToTime(hdr.Timestamp)
return false
}
}
}
}
return true
//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 1627 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 1631 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 1638 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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for additional filtering you can just set the start block in existing watchEvents

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that approach, but it appears that the filter is effective for retrieving historical events, while the watcher captures live events. As discussed, I have added a new function: it uses the filter approach for the first message to handle historical events and the watcher approach for subsequent messages to handle live events.

Start: filterFromBlock,
})
return foundAt
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 1655 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(
Expand Down
10 changes: 9 additions & 1 deletion integration-tests/ccip-tests/load/ccip_loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/AlekSi/pointer"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -204,7 +206,13 @@ func (c *CCIPE2ELoad) CCIPMsg() (router.ClientEVM2AnyMessage, *testreporters.Req
func (c *CCIPE2ELoad) Call(_ *wasp.Generator) *wasp.Response {
res := &wasp.Response{}
sourceCCIP := c.Lane.Source
recentRequestFoundAt := sourceCCIP.IsRequestTriggeredWithinTimeframe(c.SkipRequestIfAnotherRequestTriggeredWithin)
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
}
if recentRequestFoundAt != nil {
c.Lane.Logger.
Info().
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/ccip-tests/testconfig/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func (l *LoadProfile) Validate() error {
if l.TestDuration == nil || l.TestDuration.Duration().Minutes() == 0 {
return fmt.Errorf("test duration should be set")
}
if l.SkipRequestIfAnotherRequestTriggeredWithin != nil || l.TimeUnit.Duration() < l.SkipRequestIfAnotherRequestTriggeredWithin.Duration() {
return fmt.Errorf("SkipRequestIfAnotherRequestTriggeredWithin should be set below the TimeUnit duration")
}
return nil
}

Expand Down
Loading