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

Change Confirmations to Confidence #12987

Merged
merged 6 commits into from
May 30, 2024
Merged

Change Confirmations to Confidence #12987

merged 6 commits into from
May 30, 2024

Conversation

EasterTheBunny
Copy link
Contributor

Confidence is a different approach to mapping a chain agnostic concept of confidence that
an event or transaction can or should be acted on. Confidence is intended to map to defined
levels of confirmations on EVM chains and other states on other chains.

Only two levels of Confidence exist by default to define the boundaries: Highest and
Lowest. This creates an inclusive range for all chain configurable Confidence levels and
can be treated as % confidence that an event or transaction can or should be acted on.

Copy link
Contributor

github-actions bot commented Apr 25, 2024

I see you updated files related to core. Please run pnpm changeset in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

@EasterTheBunny EasterTheBunny changed the base branch from chain-reader-event-querying2 to BCF-3144-query-key-pg-query April 26, 2024 15:01
@EasterTheBunny EasterTheBunny force-pushed the BCF-3144-query-key-pg-query branch from d370744 to 41acae7 Compare May 8, 2024 16:43
@EasterTheBunny EasterTheBunny requested review from RensR and a team May 8, 2024 16:43
@EasterTheBunny EasterTheBunny force-pushed the BCF-3144-query-key-pg-query branch from 41acae7 to 3cbb81a Compare May 8, 2024 16:47
@EasterTheBunny EasterTheBunny force-pushed the BCF-3156-confidence-level branch from 07c9165 to 610c769 Compare May 9, 2024 16:03
@EasterTheBunny EasterTheBunny force-pushed the BCF-3144-query-key-pg-query branch from 25b5a5b to a9eb077 Compare May 9, 2024 16:12
core/chains/evm/logpoller/orm.go Outdated Show resolved Hide resolved
return fmt.Sprintf("LIMIT %d", limiter.Limit.Count)
}

func (v *pgDSLParser) getLastExpression() (string, error) {
Copy link
Collaborator

@mateusz-sekara mateusz-sekara May 10, 2024

Choose a reason for hiding this comment

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

Hmm, I think I have mentioned that in a previous PR, but I believe reusing this instance doesn't give us much value, but can lead to major isues. I'm not an expert when it comes to Go GC, but most of the collectors are blazingly fast and optimized for short-living objects, memory footprint shouldn't be the case here. It would be safer to always create a new pgDSLParser on every query parsing.

For instance, you can have multiple threads (e.g. plugin) running LogPoller read queries, when reusing the same pgDSLParser instance it's not gonna work. I believe you should be able to write a concurrent test that spawns multiple routines calling FilteredLogs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callout. I'll test concurrency and maybe the best path forward is to benchmark both options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran some quick benchmarks on both options with a query containing nested expressions. The benchmark was run with the command go test -bench=BenchmarkParser -benchtime=10s -benchmem each time.

wordFilter := NewEventByWordFilter(common.HexToHash("0x42"), 8, []primitives.ValueComparator{
	{Value: "a", Operator: primitives.Gt},
	{Value: "b", Operator: primitives.Lte},
})

expressions := []query.Expression{
	{BoolExpression: query.BoolExpression{
		Expressions: []query.Expression{
			query.Timestamp(10, primitives.Eq),
			{BoolExpression: query.BoolExpression{
				Expressions: []query.Expression{
					query.TxHash(common.HexToHash("0x84").Hex()),
					{BoolExpression: query.BoolExpression{
						Expressions: []query.Expression{
							query.Confirmation(primitives.Unconfirmed),
							wordFilter,
						},
						BoolOperator: query.AND,
					}},
				},
				BoolOperator: query.OR,
			}},
		},
		BoolOperator: query.AND,
	}},
}

No changes to pgDSLParser. The expression and err are reset for each build of an expression.
goos: darwin
goarch: arm64
pkg: github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller
BenchmarkParser-10 3622035 3270 ns/op 5600 B/op 81 allocs/op
PASS
ok github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller 20.203s

Split pgDSLVistor from pgDSLParser and created a new visitor instance for each expression in the build loop.
goos: darwin
goarch: arm64
pkg: github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller
BenchmarkParser-10 3278098 4672 ns/op 5744 B/op 84 allocs/op
PASS
ok github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller 38.635s

I don't see a huge difference between the two, but there does appear to still be some time loss on allocations.

v.expression = ""
v.err = nil

return exp, err
Copy link
Collaborator

@mateusz-sekara mateusz-sekara May 10, 2024

Choose a reason for hiding this comment

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

For debugging purposes, it could be worth logging what expression was built. However, maybe in the ORM, not the parser itself

}
}

func valuesFromCursor(cursor string) (int64, string, int, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some godoc or tests showing the expected cursor format would be very helpful here


func (e *eventBinding) confirmationsFrom(confidence primitives.ConfidenceLevel) int {
// sort highest to lowest on confidence
sort.Slice(e.confidenceSteps, func(i, j int) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to sort that slice on every call? We should sort it on-write, right? When e.confidenceSteps is initialized you can just sort it once.

}

// return default of 0 if step doesn't exist
return 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't that be an error? If step doesn't exist then someone is trying to do something that is not supported and might be not aware of that because code silently fallbacks to 0

@EasterTheBunny EasterTheBunny force-pushed the BCF-3144-query-key-pg-query branch 3 times, most recently from 179ac48 to 197e35b Compare May 14, 2024 14:27
@EasterTheBunny EasterTheBunny force-pushed the BCF-3156-confidence-level branch from 610c769 to 947ca18 Compare May 14, 2024 14:57
@EasterTheBunny EasterTheBunny force-pushed the BCF-3144-query-key-pg-query branch from 39abe02 to 7d4d24a Compare May 15, 2024 14:56
Base automatically changed from BCF-3144-query-key-pg-query to develop May 16, 2024 09:31
@EasterTheBunny EasterTheBunny force-pushed the BCF-3156-confidence-level branch 2 times, most recently from 3e99497 to 9aae059 Compare May 16, 2024 20:14
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@bolekk bolekk added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@bolekk bolekk added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@archseer archseer added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@ilija42 ilija42 added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@ilija42 ilija42 added this pull request to the merge queue May 30, 2024
Merged via the queue into develop with commit 4c2c6a6 May 30, 2024
108 of 109 checks passed
@ilija42 ilija42 deleted the BCF-3156-confidence-level branch May 30, 2024 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants