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

doc(katana): db table layout #1442

Merged
merged 1 commit into from
Jan 25, 2024
Merged

doc(katana): db table layout #1442

merged 1 commit into from
Jan 25, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 15, 2024

Initial effort in improving documentations for katana. This adds an ER diagram loosely representing the logical model of katana's DB table schema using mermaid diagram so it can be easily embedded in markdown.


Disclaimer: This is my first ERD in a long time, so I'm definitely not sure whether it is correctly visualizing the tables relations with one another.

@kariy kariy requested a review from glihm January 15, 2024 16:51
@kariy
Copy link
Member Author

kariy commented Jan 15, 2024

erDiagram
Headers {
    KEY BlockNumber
    VALUE Header 
}
BlockHashes {
    KEY BlockNumber
    VALUE BlockHash
}
BlockNumbers {
    KEY BlockHash
    VALUE BlockNumber
}
BlockStatusses {
    KEY BlockNumber
    VALUE FinalityStatus
}
BlockBodyIndices {
    KEY BlockNumber
    VALUE StoredBlockBodyIndices
}
TxNumbers {
    KEY TxHash
    VALUE TxNumber
}
TxHashes {
    KEY TxNumber
    VALUE TxHash
}
Transactions {
    KEY TxNumber
    VALUE Tx
}
TxBlocks {
    KEY TxNumber
    VALUE BlockNumber
}
Receipts {
    KEY TxNumber
    VALUE Receipt
}
CompiledClassHashes {
    KEY ClassHash
    VALUE CompiledClassHash
}
CompiledContractClasses {
    KEY ClassHash
    VALUE StoredContractClass
}
SierraClasses {
    KEY ClassHash
    VALUE FlattenedSierraClass
}
ContractInfo {
    KEY ContractAddress
    VALUE GenericContractInfo
}
ContractStorage {
    KEY ContractAddress
    DUP_KEY StorageKey
    VALUE StorageEntry
}
ClassDeclarationBlock {
    KEY ClassHash
    VALUE BlockNumber
}
ClassDeclarations {
    KEY BlockNumber
    DUP_KEY ClassHash
    VALUE ClassHash
}
ContractInfoChangeSet {
    KEY ContractAddress
    VALUE ContractInfoChangeList
}
NonceChanges {
    KEY BlockNumber
    DUP_KEY ContractAddress
    VALUE ContractNonceChange
}
ContractClassChanges {
    KEY BlockNumber
    DUP_KEY ContractAddress
    VALUE ContractClassChange
}
StorageChangeSet {
    KEY ContractAddress
    DUP_KEY StorageKey
    VALUE StorageEntryChangeList
}
StorageChanges {
    KEY BlockNumber
    DUP_KEY ContractStorageKey
    VALUE ContractStorageEntry
}
BlockHashes ||--|| BlockNumbers : "block id"
BlockNumbers ||--|| BlockBodyIndices : "has"
BlockNumbers ||--|| Headers : "has"
BlockNumbers ||--|| BlockStatusses : "has"
BlockBodyIndices ||--o{ Transactions : "block txs"
TxHashes ||--|| TxNumbers : "tx id"
TxNumbers ||--|| Transactions : "has"
TxBlocks ||--|{ Transactions : "tx block"
Transactions ||--|| Receipts : "each tx must have a receipt"
CompiledClassHashes ||--|| CompiledContractClasses : "has"
CompiledClassHashes ||--|| SierraClasses : "has"
SierraClasses |o--|| CompiledContractClasses : "has"
ContractInfo ||--o{ ContractStorage : "a contract storage slots"
ContractInfo ||--|| CompiledClassHashes : "has"
ContractInfo }|--|{ ContractInfoChangeSet : "has"
ContractStorage }|--|{ StorageChangeSet : "has"
ContractInfoChangeSet }|--|{ NonceChanges : "has"
ContractInfoChangeSet }|--|{ ContractClassChanges : "has"
CompiledClassHashes ||--|| ClassDeclarationBlock : "has"
ClassDeclarationBlock ||--|| ClassDeclarations : "has"
BlockNumbers ||--|| ClassDeclarations : ""
StorageChangeSet }|--|{ StorageChanges : "has"
Loading

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (87599f9) 67.62% compared to head (f78115c) 67.62%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1442   +/-   ##
=======================================
  Coverage   67.62%   67.62%           
=======================================
  Files         218      218           
  Lines       21060    21060           
=======================================
  Hits        14242    14242           
  Misses       6818     6818           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Thanks for this effort, it gaves a good graphical overview of the work done on the database.

  1. I suggest to homogenize the entity names (and this tables name) at singular instead of plural.
  2. For the relationship same thing, ensuring we've a verb and consistent way to describe them. BlockHash to BlockNumber may be something like "Maps to" for instance.

@kariy
Copy link
Member Author

kariy commented Jan 16, 2024

  1. I suggest to homogenize the entity names (and this tables name) at singular instead of plural.

The entity names are the actual table names. Unless you're suggesting that we should update the table names as well, I don't think the entity names should be different than what it's trying to represent as the diagram it just trying to explain logically how the table data are related. Lmk what you think on this.

  1. For the relationship same thing, ensuring we've a verb and consistent way to describe them. BlockHash to BlockNumber may be something like "Maps to" for instance.

Make sense. I had no idea what to put so just wrote has everywhere but agree on having more descriptive relationship labels would make understanding the diagram easier. Will try to update on this.

@glihm
Copy link
Collaborator

glihm commented Jan 16, 2024

The entity names are the actual table names. Unless you're suggesting that we should update the table names as well, I don't think the entity names should be different than what it's trying to represent as the diagram it just trying to explain logically how the table data are related. Lmk what you think on this.

Yep I'll be supportive of rewording yes, but that can be done in a code refacto in subsequent work as it's also code related as you mentioned.

@kariy
Copy link
Member Author

kariy commented Jan 17, 2024

Yep I'll be supportive of rewording yes, but that can be done in a code refacto in subsequent work as it's also code related as you mentioned.

singularizing the table names would be sorta conflicting with some of the primitive types that are used as the tables' value (eg BlockNumber, TxNumber, Receipt etc) especially in the provider impl where both the table and primitive types are used.

I think having plural name for db tables is a pretty common convention. It is also a convention used by torii sql db. So I'm not keen on changing it to singular form.

@glihm
Copy link
Collaborator

glihm commented Jan 17, 2024

Yep I'll be supportive of rewording yes, but that can be done in a code refacto in subsequent work as it's also code related as you mentioned.

singularizing the table names would be sorta conflicting with some of the primitive types that are used as the tables' value (eg BlockNumber, TxNumber, Receipt etc) especially in the provider impl where both the table and primitive types are used.

I think having plural name for db tables is a pretty common convention. It is also a convention used by torii sql db. So I'm not keen on changing it to singular form.

Thanks for the feedback and context, good point.

@kariy kariy merged commit 0736cdd into dojoengine:main Jan 25, 2024
10 checks passed
@kariy kariy deleted the katana-docs branch January 25, 2024 15:42
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.

3 participants