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

in-memory child address tracking #1092

Closed
wants to merge 26 commits into from
Closed

in-memory child address tracking #1092

wants to merge 26 commits into from

Conversation

kyscott18
Copy link
Collaborator

@kyscott18 kyscott18 commented Sep 10, 2024

Closes #1091

  • better tests for getChildAddress

Realtime child address reorg handling strategy:

  • separate unfinalizedChildAddresses and finalizedChildAddresses
  • track factoryLogsPerBlock, so that unfinalizedChildAddresses can always be recomputed
  • on reorg, evict reorged blocks from factoryLogsPerBlock and recompute unfinalizedChildAddresses
  • on finalization, add child addresses from finalized blocks to finalizedChildAddresses, evict finalized blocks from factoryLogsPerBlock and recompute unfinalizedChildAddresses

Base automatically changed from kjs/concurrent-extract to v0.6 September 11, 2024 03:29
kyscott18 and others added 9 commits September 11, 2024 12:28
* remove extra config

* ready

* sqlite database

* postgres database

* fix test type errors

* fix tests

* remove stale tests

* cleanup db

* schema => table_names

* start docs

* some docs

* cleanup

* database migration

* remove maxHealthcheckDuration docs

* create schema if not exists

* drop finalized rows from reorg tables

* fix docs link

* nits

* merge

* use json operators
* remove maxBlockRange

* cleanup

* add isSuggested property to getLogsRetryRanges return

* merge

* dynamically increaing log ranges

* remove maxBlockRange docs

* fix test

* nits

* cleanup

* nits

* more cleanup

* chore: changeset

* chore: changeset
* build log events in memory

* order events by checkpoint

* .

* realtime indexing cache

* wip multichain

* more work

* start multichain tests

* merge async generators

* lol

* typesafe

* omnichain

* prune rpc request by block

* start

* fix tests

* cleanup

* ponder_realtime_is_connected metric

* status

* fix accuracy of historical to realtime handoff

* better generator

* nits

* skip refetching finalized blocks for completed networks

* revert

* ignore
* add debug log to sync

* new sync duration metric + update tui

* sum all sync metrics per network

* protects against extraneous logs being thrown

* chain specific metrics

* cleanup

* deprecate old sync metrics

* fix historical metrics and tui

* fix test

* last refactor ever

* changeset

---------

Co-authored-by: typedarray <[email protected]>
@@ -624,7 +628,7 @@ export const createRealtimeSync = (

// New block is exactly one block ahead of the local chain.
// Attempt to ingest it.
await handleBlock({ block, ...rest });
handleBlock({ block, ...rest });
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Happy path worker for the realtime queue (bottleneck for handling a new block) is now synchronous

@kyscott18 kyscott18 marked this pull request as ready for review September 13, 2024 21:13
Copy link
Collaborator

@0xOlias 0xOlias left a comment

Choose a reason for hiding this comment

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

Business logic looks good to me!

"address" in filter &&
isAddressFactory(filter.address)
) {
const addresses = await args.syncStore.getChildAddresses({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason not to use Promise.all here?

: factory.childAddressLocation === "topic2"
? 2
: 3;
log.topics;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo?

Looks good to me, but while we're here I think it's worthwhile to add a couple unit tests for this, e.g. around casing

Comment on lines +178 to +179
? finalizedChildAddresses.get(filter.address)!.has(log.address) ||
unfinalizedChildAddresses.get(filter.address)!.has(log.address)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we certain that the casing is consistent when doing these comparisons?

localChain = localChain.filter(
(lb) =>
hexToNumber(lb.number) > hexToNumber(pendingFinalizedBlock.number),
);

// add child address from newly finalized blocks to `finalizedChildAddresses`
for (const filter of factories) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, but I'd find this more readable if the factories loop came after the if (factoryLogs !== undefined) check


for (const filter of factories) {
unfinalizedChildAddresses.set(filter, new Set());
for (const { hash } of localChain) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should rename localChain to unfinalizedBlocks

Comment on lines +394 to +397
// delete reorged blocks from `factoryLogsPerBlock`
for (const { hash } of reorgedBlocks) {
factoryLogsPerBlock.delete(hash);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this happen before we recompute unfinalizedChildAddresses ? It shouldn't matter, just double checking.

Base automatically changed from v0.6 to main September 18, 2024 18:47
@kyscott18 kyscott18 closed this Sep 20, 2024
@kyscott18 kyscott18 deleted the kjs/mem-factory branch October 10, 2024 20:47
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.

Hold all factory child addresses in memory
2 participants