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

[Indexer] Implements state indexer #1186

Merged
merged 6 commits into from
Nov 30, 2023
Merged

[Indexer] Implements state indexer #1186

merged 6 commits into from
Nov 30, 2023

Conversation

baichuan3
Copy link
Collaborator

Summary

Part of #1028, Implements state indexer

  1. Create a global Object table: (object_id, owner, flag, JSON (V), key_type), and store V according to JSON. Global states table only store table objects and raw objects.
CREATE TABLE global_states
(
  object_id          VARCHAR        NOT NULL       PRIMARY KEY,
  owner              VARCHAR        NOT NULL,
  flag               SMALLINT       NOT NULL,
  value              VARCHAR        NOT NULL,
  key_type           VARCHAR        NOT NULL,
  size               BIGINT         NOT NULL,
  created_at         BIGINT         NOT NULL,
  updated_at         BIGINT         NOT NULL
);
  1. Create a leaf table: (object_id, key_hash, JSON (V), key_type), and store V according to JSON.
CREATE TABLE leaf_states
(
  id                 VARCHAR        NOT NULL      PRIMARY KEY,
  object_id          VARCHAR        NOT NULL,
  key_hash           VARCHAR        NOT NULL,
  value              VARCHAR        NOT NULL,
  value_type         VARCHAR        NOT NULL,
  created_at         BIGINT         NOT NULL,
  updated_at         BIGINT         NOT NULL,
  UNIQUE (object_id, key_hash)
);
  1. The state indexer currently does not provide RPC query, and will provide query through GraphQL later.
  2. Diesel for SQLite don't support batch update yet, so implements batch update directly via raw SQL.

TODO

  1. Since table creation may be lazy, create global table if the table does not exist.
  2. Update table size if ObjectID is table hanlde.

Copy link

vercel bot commented Nov 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
rooch ⬜️ Ignored (Inspect) Nov 29, 2023 1:53pm

for (key, op) in table_change.entries.into_iter() {
match op {
Op::Modify(value) => {
let key_hash = format!("0x{}", hex::encode(key.as_slice()));
Copy link
Contributor

Choose a reason for hiding this comment

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

The key here is not hash but the key's bcs binary. So, the field name should be key.

Copy link
Collaborator Author

@baichuan3 baichuan3 Nov 30, 2023

Choose a reason for hiding this comment

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

key in SQLite is a keyword. Or use key_str?

@jolestar jolestar merged commit e574b8c into main Nov 30, 2023
5 of 6 checks passed
@jolestar jolestar deleted the state_indexer branch November 30, 2023 01:03
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.

[Indexer] Implement state indexer
2 participants