-
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
Add logs to identify when assumptions of log queuing behaviour are violated #12846
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
47012b6
Add logs to identify when assumptions of log queuing behaviour are vi…
ferglor 7ff1cd9
Add tests
ferglor 4e19065
go import
ferglor 381702a
Add changeset
ferglor 7ef5f73
Update enqueuing assumption
ferglor f6a8162
Update tests
ferglor 2710e62
Extract block tracking into a separate function
ferglor 396425e
Clean up outdated enqueued blocks
ferglor ec2aa0a
Clean up imports
ferglor 7619d2d
Ignore reord buffer in cleanup
ferglor 4bf1c35
Cleanup test name
ferglor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
Add logs for when the assumptions of how the log buffer will be used are violated #internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" | ||
|
@@ -50,6 +51,96 @@ func TestLogEventBufferV1_SyncFilters(t *testing.T) { | |
require.Equal(t, 1, buf.NumOfUpkeeps()) | ||
} | ||
|
||
type readableLogger struct { | ||
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. Why do we need this? 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. Just for the purposes of catching and validating log messages within the tests |
||
logger.Logger | ||
DebugwFn func(msg string, keysAndValues ...interface{}) | ||
NamedFn func(name string) logger.Logger | ||
WithFn func(args ...interface{}) logger.Logger | ||
} | ||
|
||
func (l *readableLogger) Debugw(msg string, keysAndValues ...interface{}) { | ||
l.DebugwFn(msg, keysAndValues...) | ||
} | ||
|
||
func (l *readableLogger) Named(name string) logger.Logger { | ||
return l | ||
} | ||
|
||
func (l *readableLogger) With(args ...interface{}) logger.Logger { | ||
return l | ||
} | ||
|
||
func TestLogEventBufferV1_Enqueueviolations(t *testing.T) { | ||
t.Run("enqueuing logs for a block older than latest seen logs a message", func(t *testing.T) { | ||
logReceived := false | ||
readableLogger := &readableLogger{ | ||
DebugwFn: func(msg string, keysAndValues ...interface{}) { | ||
if msg == "enqueuing logs from a block older than latest seen block" { | ||
logReceived = true | ||
assert.Equal(t, "logBlock", keysAndValues[0]) | ||
assert.Equal(t, int64(1), keysAndValues[1]) | ||
assert.Equal(t, "lastBlockSeen", keysAndValues[2]) | ||
assert.Equal(t, int64(2), keysAndValues[3]) | ||
} | ||
}, | ||
} | ||
|
||
logBufferV1 := NewLogBuffer(readableLogger, 10, 20, 1) | ||
|
||
buf := logBufferV1.(*logBuffer) | ||
|
||
buf.Enqueue(big.NewInt(1), | ||
logpoller.Log{BlockNumber: 2, TxHash: common.HexToHash("0x1"), LogIndex: 0}, | ||
logpoller.Log{BlockNumber: 2, TxHash: common.HexToHash("0x1"), LogIndex: 1}, | ||
) | ||
buf.Enqueue(big.NewInt(2), | ||
logpoller.Log{BlockNumber: 1, TxHash: common.HexToHash("0x2"), LogIndex: 0}, | ||
) | ||
|
||
assert.Equal(t, 1, buf.enqueuedBlocks[2]["1"]) | ||
assert.Equal(t, 1, buf.enqueuedBlocks[1]["2"]) | ||
assert.True(t, true, logReceived) | ||
}) | ||
|
||
t.Run("enqueuing logs for the same block over multiple calls logs a message", func(t *testing.T) { | ||
logReceived := false | ||
readableLogger := &readableLogger{ | ||
DebugwFn: func(msg string, keysAndValues ...interface{}) { | ||
if msg == "enqueuing logs again for a previously seen block" { | ||
logReceived = true | ||
assert.Equal(t, "blockNumber", keysAndValues[0]) | ||
assert.Equal(t, int64(3), keysAndValues[1]) | ||
assert.Equal(t, "numberOfEnqueues", keysAndValues[2]) | ||
assert.Equal(t, 2, keysAndValues[3]) | ||
} | ||
}, | ||
} | ||
|
||
logBufferV1 := NewLogBuffer(readableLogger, 10, 20, 1) | ||
|
||
buf := logBufferV1.(*logBuffer) | ||
|
||
buf.Enqueue(big.NewInt(1), | ||
logpoller.Log{BlockNumber: 1, TxHash: common.HexToHash("0x1"), LogIndex: 0}, | ||
logpoller.Log{BlockNumber: 1, TxHash: common.HexToHash("0x1"), LogIndex: 1}, | ||
) | ||
buf.Enqueue(big.NewInt(2), | ||
logpoller.Log{BlockNumber: 2, TxHash: common.HexToHash("0x2"), LogIndex: 0}, | ||
) | ||
buf.Enqueue(big.NewInt(3), | ||
logpoller.Log{BlockNumber: 3, TxHash: common.HexToHash("0x3a"), LogIndex: 0}, | ||
) | ||
buf.Enqueue(big.NewInt(3), | ||
logpoller.Log{BlockNumber: 3, TxHash: common.HexToHash("0x3b"), LogIndex: 0}, | ||
) | ||
|
||
assert.Equal(t, 1, buf.enqueuedBlocks[2]["2"]) | ||
assert.Equal(t, 1, buf.enqueuedBlocks[1]["1"]) | ||
assert.Equal(t, 2, buf.enqueuedBlocks[3]["3"]) | ||
assert.True(t, true, logReceived) | ||
}) | ||
} | ||
|
||
func TestLogEventBufferV1_Dequeue(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this logic will change with reorg handling?
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.
Yes; based on what I have in the spike for reorgs, we should have a set of block numbers available to us to perform this check against 👍