-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: db event registry repository #42
Conversation
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.
just a tiny comment , gj ser! 🥳
registriesRepositories: { | ||
eventRegistryRepository: IEventRegistryRepository; | ||
strategyRegistryRepository: IStrategyRegistryRepository; |
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 the previous way was ok. I...Registry should be de dependency not I...RegistryRepository. Lmk if iam missing something
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've changed the way it works by creating an instance per chain but using the same repository, since it's not really necessary to load into memory the lastProcessedEvent
of another chain (if we deploy a container per chain, this is more obvious to see).
if this makes sense, the same change applies for strategies (we create an instance per chain) but didn't want to mix and make the change for StrategyRegistry too. if we go for this approach, i'll make the change in another PR
if smth it's not clear, we can discuss it offline 😄
const strategyRegistry = await InMemoryCachedStrategyRegistry.initialize( | ||
new Logger({ className: "InMemoryCachedStrategyRegistry" }), | ||
new DatabaseStrategyRegistry( | ||
new Logger({ className: "DatabaseStrategyRegistry" }), | ||
strategyRegistryRepository, | ||
), | ||
); | ||
const eventsRegistry = new DatabaseEventRegistry( | ||
new Logger({ className: "DatabaseEventRegistry" }), | ||
eventRegistryRepository, | ||
); |
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.
is there a reason why you are doing this outside the SharedDependenciesService
?
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.
sweet
this.cache.set(chainId, { ...event, chainId }); | ||
} | ||
|
||
/** |
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.
/** |
xd
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.
Mostly minor naming stuff, pretty complete PR
private constructor( | ||
private readonly logger: ILogger, | ||
private readonly eventRegistry: IEventsRegistry, | ||
cache: Map<ChainId, ProcessedEvent>, |
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.
Extremely minor, but maybe renaming it to initialEntries
or initialCache
and making it optional would make this a little bit more explanatory?
cache: Map<ChainId, ProcessedEvent>, | |
initialCache?: Map<ChainId, ProcessedEvent>, |
Nothing serious though, feel free to dismiss this comment if you prefer it the way it is.
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.
the goal of this class this is a proxied cache so it always is initialized with a pre-filled cache that fallbacks to the main registry implementation and given that constructor is private i think it's the same to have it optional or not
const cachedEvent = this.cache.get(chainId); | ||
if (cachedEvent) { | ||
return cachedEvent; | ||
} |
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've got no idea on the business logic but worth asking; should you include some kind of TTL for this cache?
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.
is not really necessary since we're processing one event at time and saving on each iteration, tbh here we just save a really few calls to the DB
// Verify no additional calls to underlying registry | ||
expect(mockEventRegistry.getLastProcessedEvent).toHaveBeenCalledTimes(1); | ||
}); | ||
|
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.
What if the other registry fails while saving?
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.
that's a really good question sir
cc @0xkenj1 we can discuss it offline if this is is a retriable error or not
const CHAIN_ID_TYPE = "integer"; | ||
|
||
await db.schema | ||
.createTable("events") |
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.
Does using last_events
as the table name fit better to this use case? It feels weird having a table named events
with a chainId
primary key.
.createTable("events") | |
.createTable("last_events") |
🤖 Linear
Closes GIT-188
Description
We want to persist the last event processed for each chain so we can safely stop and resume the indexer from where we left off.
EventRegistryRepository
to store the last processed event per chainDBEventsRegistry
that interfaces with the repoDBEventRegistry
(InMemoryCachedEventRegistry) and loads into memory the data stored on DB on initevents
forDBEventsRegistry
repoChecklist before requesting a review