-
Notifications
You must be signed in to change notification settings - Fork 2
fix: wrap spoke pool indexer in a sql transaction #271
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
fix: wrap spoke pool indexer in a sql transaction #271
Conversation
@@ -16,6 +21,7 @@ export class SwapBeforeBridgeRepository extends dbUtils.BlockchainEventRepositor | |||
swapBeforeBridgeEvents: SwapBeforeBridgeEvent[], | |||
chainId: number, | |||
lastFinalisedBlock: number, | |||
transactionalEntityManager?: EntityManager, |
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.
Any chance we can make a singleton for this EntityManager
? Without it we need to pass this variable down to a lot of inner functions
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 don't think it's possible to make a singleton because this instance must be limited to the scope of the callback passed as a parameter to createTransaction()
function
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.
great work!
: this.postgres.getRepository(entities.ExecutedRelayerRefundRoot); | ||
const relayHashInfoRepository = transactionalEntityManager | ||
? transactionalEntityManager.getRepository(entities.RelayHashInfo) | ||
: this.postgres.getRepository(entities.RelayHashInfo); |
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 makes sense to make it compatible with tests, but i wonder if we should somehow require this when running for real, i dont think we ever want this to run without it in prod
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 agree, I need to find a way to make it required. It's easy for someone less familiar with the code to miss using it
This PR wraps the execution of
SpokePoolIndexerDataHandler.processBlockRange()
in a SQL transaction. In case of throwing an error, the database should be reverted to the state prior to the block range being processed.fetchEventsByRange
is not included in the SQL transactiontransactionalEntityManager
transactionalEntityManager
is marked as optional. In such cases the queries are executed using theDataSource
instanceExample:
pg_advisory_xact_lock
that gets released automatically after the transaction ends get replaced with session livedpg_advisory_lock
which needs to be unlockedexplicitly
The following pattern has been using in the
SpokePoolProcessor
: