-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[SHIP-3903]Remove WS requirement for data feeds soak tests #15003
Changes from 7 commits
a9a622b
c48a1a5
eb3b127
ca4b59f
4d5bfb5
ed712a6
24128ee
ec0cf6d
0642e39
62bcd56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ import ( | |
|
||
geth "github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/pelletier/go-toml/v2" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -619,8 +618,8 @@ func (o *OCRSoakTest) testLoop(testDuration time.Duration, newValue int) { | |
newRoundTrigger := time.NewTimer(0) // Want to trigger a new round ASAP | ||
defer newRoundTrigger.Stop() | ||
o.setFilterQuery() | ||
err := o.observeOCREvents() | ||
require.NoError(o.t, err, "Error subscribing to OCR events") | ||
err := o.pollingOCREvents(endTest) | ||
require.NoError(o.t, err, "Error setting up polling for OCR events") | ||
|
||
n := o.Config.GetNetworkConfig() | ||
|
||
|
@@ -824,70 +823,106 @@ func (o *OCRSoakTest) setFilterQuery() { | |
Msg("Filter Query Set") | ||
} | ||
|
||
// observeOCREvents subscribes to OCR events and logs them to the test logger | ||
// WARNING: Should only be used for observation and logging. This is not a reliable way to collect events. | ||
func (o *OCRSoakTest) observeOCREvents() error { | ||
eventLogs := make(chan types.Log) | ||
ctx, cancel := context.WithTimeout(testcontext.Get(o.t), 5*time.Second) | ||
eventSub, err := o.seth.Client.SubscribeFilterLogs(ctx, o.filterQuery, eventLogs) | ||
cancel() | ||
if err != nil { | ||
return err | ||
} | ||
// pollingOCREvents Polls the blocks for OCR events and logs them to the test logger | ||
func (o *OCRSoakTest) pollingOCREvents(endTest <-chan time.Time) error { | ||
// Keep track of the last processed block number | ||
startingBlockNum := o.startingBlockNum | ||
// Initialized to an invalid block number (max value of uint64) | ||
lastCheckedBlockNum := ^uint64(0) | ||
|
||
go func() { | ||
// TODO: Make this configurable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this PR or follow-up? Is there a ticket to link? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intention was for a follow up. Just created SHIP-3973 to cover it. |
||
pollInterval := time.Second * 30 | ||
ticker := time.NewTicker(pollInterval) | ||
defer ticker.Stop() | ||
o.log.Info().Msg("Start Polling for Answer Updated Events") | ||
for { | ||
select { | ||
case event := <-eventLogs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think its worth keeping the WSS option also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move onto polling. Seems more reliable and not prone to disconnections. |
||
if o.OCRVersion == "1" { | ||
answerUpdated, err := o.ocrV1Instances[0].ParseEventAnswerUpdated(event) | ||
if err != nil { | ||
o.log.Warn(). | ||
Err(err). | ||
case <-endTest: | ||
o.log.Info().Msg("Test duration ended, stopping polling") | ||
return | ||
case <-ticker.C: | ||
// Get the latest block number to search up to the current block | ||
latestBlock, err := o.seth.Client.BlockNumber(context.Background()) | ||
if err != nil { | ||
o.log.Error().Err(err).Msg("Error getting latest block number") | ||
continue | ||
} | ||
|
||
// Skip if this block has already been checked | ||
if latestBlock == lastCheckedBlockNum { | ||
o.log.Debug(). | ||
Uint64("Latest Block", latestBlock). | ||
Uint64("Last Checked Block Number", lastCheckedBlockNum). | ||
Msg("No new blocks since last poll") | ||
continue | ||
} | ||
// Check if the latest block is behind the starting block just in case | ||
if startingBlockNum > latestBlock { | ||
o.log.Error(). | ||
Uint64("From Block", startingBlockNum). | ||
Uint64("To Block", latestBlock). | ||
Msg("The latest block is behind the starting block. This could happen due to RPC issues or possibly a reorg") | ||
// May need to `startingBlockNum = latestBlock` if this happens frequently due to reorgs | ||
continue | ||
} | ||
|
||
// Prepare the filter query with updated block range | ||
o.filterQuery.FromBlock = big.NewInt(0).SetUint64(startingBlockNum) | ||
o.filterQuery.ToBlock = big.NewInt(0).SetUint64(latestBlock) | ||
|
||
o.log.Debug(). | ||
Uint64("From Block", startingBlockNum). | ||
Uint64("To Block", latestBlock). | ||
Msg("Fetching logs for the specified range") | ||
|
||
// Fetch logs for the specified range | ||
logs, err := o.seth.Client.FilterLogs(context.Background(), o.filterQuery) | ||
if err != nil { | ||
o.log.Error().Err(err).Msg("Error fetching logs") | ||
continue | ||
} | ||
|
||
// Process the fetched logs | ||
for _, event := range logs { | ||
if o.OCRVersion == "1" { | ||
answerUpdated, err := o.ocrV1Instances[0].ParseEventAnswerUpdated(event) | ||
if err != nil { | ||
o.log.Warn(). | ||
Err(err). | ||
Str("Address", event.Address.Hex()). | ||
Uint64("Block Number", event.BlockNumber). | ||
Msg("Error parsing event as AnswerUpdated") | ||
continue | ||
} | ||
o.log.Info(). | ||
Str("Address", event.Address.Hex()). | ||
Uint64("Block Number", event.BlockNumber). | ||
Msg("Error parsing event as AnswerUpdated") | ||
continue | ||
} | ||
o.log.Info(). | ||
Str("Address", event.Address.Hex()). | ||
Uint64("Block Number", event.BlockNumber). | ||
Uint64("Round ID", answerUpdated.RoundId.Uint64()). | ||
Int64("Answer", answerUpdated.Current.Int64()). | ||
Msg("Answer Updated Event") | ||
} else if o.OCRVersion == "2" { | ||
answerUpdated, err := o.ocrV2Instances[0].ParseEventAnswerUpdated(event) | ||
if err != nil { | ||
o.log.Warn(). | ||
Err(err). | ||
Uint64("Round ID", answerUpdated.RoundId.Uint64()). | ||
Int64("Answer", answerUpdated.Current.Int64()). | ||
Msg("Answer Updated Event") | ||
} else if o.OCRVersion == "2" { | ||
answerUpdated, err := o.ocrV2Instances[0].ParseEventAnswerUpdated(event) | ||
if err != nil { | ||
o.log.Warn(). | ||
Err(err). | ||
Str("Address", event.Address.Hex()). | ||
Uint64("Block Number", event.BlockNumber). | ||
Msg("Error parsing event as AnswerUpdated") | ||
continue | ||
} | ||
o.log.Info(). | ||
Str("Address", event.Address.Hex()). | ||
Uint64("Block Number", event.BlockNumber). | ||
Msg("Error parsing event as AnswerUpdated") | ||
continue | ||
} | ||
o.log.Info(). | ||
Str("Address", event.Address.Hex()). | ||
Uint64("Block Number", event.BlockNumber). | ||
Uint64("Round ID", answerUpdated.RoundId.Uint64()). | ||
Int64("Answer", answerUpdated.Current.Int64()). | ||
Msg("Answer Updated Event") | ||
} | ||
case err = <-eventSub.Err(): | ||
backoff := time.Second | ||
for err != nil { | ||
o.log.Info(). | ||
Err(err). | ||
Str("Backoff", backoff.String()). | ||
Interface("Query", o.filterQuery). | ||
Msg("Error while subscribed to OCR Logs. Resubscribing") | ||
ctx, cancel = context.WithTimeout(testcontext.Get(o.t), backoff) | ||
eventSub, err = o.seth.Client.SubscribeFilterLogs(ctx, o.filterQuery, eventLogs) | ||
cancel() | ||
if err != nil { | ||
time.Sleep(backoff) | ||
backoff = time.Duration(math.Min(float64(backoff)*2, float64(30*time.Second))) | ||
Uint64("Round ID", answerUpdated.RoundId.Uint64()). | ||
Int64("Answer", answerUpdated.Current.Int64()). | ||
Msg("Answer Updated Event") | ||
} | ||
} | ||
|
||
// Track last checked block number and update starting block number | ||
lastCheckedBlockNum = latestBlock | ||
startingBlockNum = latestBlock + 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: can we just repurpose startingBlockNum to check for the lastCheckedBlockNum. Not a big deal but good for readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. Wanted to have a clear separation between the initial run and subsequent runs but it does not add that much value. Simpler code is always better. |
||
} | ||
} | ||
}() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of scope, but this goroutine appears to be untracked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated how this is handled and it is now tracked. Thanks for pointing it out.