moonstream-to / api

Building blocks for your blockchain economy
https://moonstream.to
Apache License 2.0
135 stars 49 forks source link

Postgresql Blob block storage index schematic database schema. #1000

Open Andrei-Dolgolev opened 8 months ago

Andrei-Dolgolev commented 8 months ago

We need develop index structure for provide fast access to GCS files and maintain system of storage for RDS of our cstomers.

What we store:

For now we have 5 types of structures stored per chain some of them can have additional fields or don't have some of them(that problem will be handle on crawler issue).

Json examples of all data structures (ethereum chain): https://gist.github.com/Andrei-Dolgolev/443ddd96d31ba72e939174fae3fdaae3

Important things from moonstram V2 events/transactions must include block_hash for possiblity to running forks detection and fixing.

Indexes

Blocks:

block_number, block_hash, block_timestamp -> (file_link)

Route to blocks: GCS/blockM..blockN/blocks.proto

Use cases: Connect with events/transactions/traces for fork protetction

Transactions:

Transactions_hash, from_address, to_address, block_hash -> (file_link)

Route to transactions: GCS/blockM..blockN/transactions.proto

Use cases: Get Transactions for customers RDS and decode them to tx_call by particular to_address. Possably restore some of transacrions in user database tx_table.(depends on transactions trace)

Events:

address, topic, block_hash, tx_hash ->(file_link)

Route to events: GCS/blockM..blockN/events.proto

Use cases: Get events for customer RDS by contract address.

Block trace:

Use cases: Restore internal calls to user RDS by to_address.

Transaction trace:

Use cases: Restore latest state of storage to user RDS