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

uAgent almanac tracking #176

Open
bryanchriswhite opened this issue Nov 14, 2022 · 5 comments · Fixed by #187 · May be fixed by #198
Open

uAgent almanac tracking #176

bryanchriswhite opened this issue Nov 14, 2022 · 5 comments · Fixed by #187 · May be fixed by #198
Assignees
Milestone

Comments

@bryanchriswhite
Copy link

bryanchriswhite commented Nov 14, 2022

Acceptance criteria

  1. Almanac registration events are tracked by a respective entity.
  2. Live almanac registrations must be distinct from historic ones and must exclude expired registrations.
@bryanchriswhite bryanchriswhite self-assigned this Nov 14, 2022
@bryanchriswhite bryanchriswhite added this to the v0.4 milestone Nov 17, 2022
@bryanchriswhite
Copy link
Author

bryanchriswhite commented Nov 17, 2022

Proposal

To facilitate expiration, we can add some code to the block primitive handler which checks for "resolutions" which are expired/ing (and deletes them). "Resolutions" would reference "registrations", which are the entity tracking historical registration events.

Separating "resolutions" and "registrations" allows us to remove "resolution" records as they expire while still serving the basic indexer function of preserving historical state; i.e. historical registration event data is recoverable via "registrations". It is in fact prudent that we delete these records because we're then asking the block handler (each block) to do an index scan, minimum, of that table. This approach decouples the performance loss in the block handler from the cumulative number of registrations, mitigating an unnecessary slow-down that would otherwise be introduced to the block handler. There will still be a performance hit but it will instead be correlated to the number un-expired registrations ("resolutions").

Schema:

type AlmanacService @jsonField {
  protocols: [String!]
  endpoints: [String!]!
}

type AlmanacRecord @entity {
  id: ID!
  service: AlmanacService
  registration: AlmanacRegistration! @derivedFrom(field: "record")
}

type AlmanacResolution @entity {
  id: ID!
  address: String! @index
  record: AlmanacRecord!
}

type AlmanacRegistration @entity {
  id: ID!
  # TODO: account (?)
  address: String! @index
  expiryHeight: BigInt! @index
  record: AlmanacRecord!
  event: Event!
  transaction: Transaction!
  block: Block!
}

@ejfitzgerald
Copy link
Member

ejfitzgerald commented Nov 18, 2022

Makes sense to me the only thing to consider is that with the new version of the contract API

type AlmanacService @jsonField {
  protocols: [String!]
  endpoints: [String!]!
}

becomes more like

type AlmanacEndpoint @jsonField {
  endpoint: String!
  weight: Int!
}

type AlmanacService @jsonField {
  protocols: [String!]
  endpoints: [AlmanacEndpoint!]!
}

The weights work in the similar way to DNS fields

@bryanchriswhite bryanchriswhite linked a pull request Nov 22, 2022 that will close this issue
6 tasks
@bryanchriswhite
Copy link
Author

I ran into some unexpected complications regarding foreign key constraints when attempting to relate AlmanacRegistration to Event. My current hypothesis is that handleEvent may not have finished at the time which handleAlmanacRegistration is attempting to save the registration, resulting in a foreign key constraint violation as the related event hasn't been committed yet.

I also experienced an issue while trying to add the reverse relationship between AlmanacResolution and AlmanacRegistration (@derivedFrom(field: "record")):

ledger-subquery-subquery-node-1  | 2022-11-21T14:06:05.297Z <store> ERROR Having a probl
em when syncing schema SequelizeDatabaseError: syntax error at or near "'almanac_registr
ations_record_id_uindex'"   

@bryanchriswhite
Copy link
Author

bryanchriswhite commented Nov 24, 2022

Waiting for the contract-almanac v0.2 changes.

@bryanchriswhite bryanchriswhite linked a pull request Dec 1, 2022 that will close this issue
6 tasks
@bryanchriswhite
Copy link
Author

bryanchriswhite commented Dec 15, 2022

Sprint 12 > 13 update:

Registrations

Resolutions

  • E2E tests
  • Schema updates
  • Handler implementation
    • Cache / expire control flow & basic logic
    • DB query optimization on expiration (each block)
  • Migration (+ testing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants