-
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
CCIP-1277 LogPoller - Fixing leaky abstraction by removing Q() from the ORM interface #11200
Conversation
I see that you haven't updated any CHANGELOG files. Would it make sense to do so? |
err = lp.orm.Q().WithOpts(pg.WithParentCtx(ctx)).Transaction(func(tx pg.Queryer) error { | ||
return lp.orm.InsertLogs(convertLogs(gethLogs, blocks, lp.lggr, lp.ec.ConfiguredChainID()), pg.WithQueryer(tx)) | ||
}) | ||
err = lp.orm.InsertLogs(convertLogs(gethLogs, blocks, lp.lggr, lp.ec.ConfiguredChainID()), pg.WithParentCtx(ctx)) |
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.
This is a single query, we don't have to open TX for that
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.
Weird, not sure how it got like that!
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.
If we remove this outer tx, we need to open a tx inside InsertLogs since we may break that into multiple inserts
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.
Oh! Yes, seems like that should have always been down in the ORM. Maybe at some point there was another ORM call inside the same tx?
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.
This is my fault; I've removed that TX prematurely. We can just open TX within the insertLogs to guarantee they are inserted together.
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.
Kudos to @connorwstein for this finding!
core/chains/evm/logpoller/orm.go
Outdated
@@ -681,6 +698,20 @@ func (o *DbORM) SelectIndexedLogsWithSigsExcluding(sigA, sigB common.Hash, topic | |||
return logs, nil | |||
} | |||
|
|||
func (o *DbORM) InsertLogsWithBlock(logs []Log, block LogPollerBlock, qopts ...pg.QOpt) error { | |||
// Optimization, don't open TX when there is only block to be persisted | |||
if len(logs) == 0 { |
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.
AFAIK, opening TX requires an additional round trip to the database. This could be a nice improvement for PollAndSave ticks when no logs are emitted
30e055a
to
5981c76
Compare
7ae9d7f
to
0023762
Compare
…ng all the TX internals into the ORM implementation
0023762
to
d14c4a0
Compare
a66a61d
to
75b12e7
Compare
SonarQube Quality Gate |
…he ORM interface (#11200) * Fixing leaky abstraction by removing Q() from the ORM interface. Moving all the TX internals into the ORM implementation * Adding test * Post review fix * Post rebase fixes
Moving all the internals related to opening TXs to the ORM layer. This has a couple of advantages:
LogPollerBlock
within the ORM layer. This could be a potential improvement by removing all nested queries fromnestedBlockNumberQuery
. The codebase will be much simpler