-
Notifications
You must be signed in to change notification settings - Fork 521
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
Frontier DB block mapping one-to-many #862
Frontier DB block mapping one-to-many #862
Conversation
Hi, @tgmichel I upgrade the substrate in the #830 and found the tests( I added some debug log, error message like below:
So is it wrong to use |
@koushiro I see yes, thank you. It's a good question and I will need to dig into it. For this PR I will just use the test runtime api. |
That's okay. We've done that in Substrate in the past as well (requiring paritydb to resync). Eventually those migration code will be removed anyway. |
client/db/src/lib.rs
Outdated
} | ||
|
||
pub fn new(config: &DatabaseSettings) -> Result<Self, String> { | ||
let db = utils::open_database(config)?; | ||
pub fn new(client: Arc<C>, config: &DatabaseSettings) -> Result<Self, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like C
is only used in DB migrations. In that case, it may be better to remove this generic from Backend
and add it to Backend::new
.
pub fn new(client: Arc<C>, config: &DatabaseSettings) -> Result<Self, String> { | |
pub fn new<C: HeaderBackend<...>>(client: Arc<C>, config: &DatabaseSettings) -> Result<Self, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grumble on the generic, and otherwise LGTM.
* WIP Frontier DB block mapping one-to-many * Fix * fmt * Cleanup * Cleanup * Cleanup * fmt skip * parity db migration * Cleanup + tests * WIP retroactively fix non-canon mapped blocks * Update tests * Fix more tests * clippy * taplo * Test transaction metadata * Use test runtime api * Remove unnecessary generic (cherry picked from commit 5bd0dc7)
* WIP Frontier DB block mapping one-to-many * Fix * fmt * Cleanup * Cleanup * Cleanup * fmt skip * parity db migration * Cleanup + tests * WIP retroactively fix non-canon mapped blocks * Update tests * Fix more tests * clippy * taplo * Test transaction metadata * Use test runtime api * Remove unnecessary generic (cherry picked from commit 5bd0dc7)
* WIP Frontier DB block mapping one-to-many * Fix * fmt * Cleanup * Cleanup * Cleanup * fmt skip * parity db migration * Cleanup + tests * WIP retroactively fix non-canon mapped blocks * Update tests * Fix more tests * clippy * taplo * Test transaction metadata * Use test runtime api * Remove unnecessary generic (cherry picked from commit 5bd0dc7)
* WIP Frontier DB block mapping one-to-many * Fix * fmt * Cleanup * Cleanup * Cleanup * fmt skip * parity db migration * Cleanup + tests * WIP retroactively fix non-canon mapped blocks * Update tests * Fix more tests * clippy * taplo * Test transaction metadata * Use test runtime api * Remove unnecessary generic
On equivocation
state_root
is the same between blocks, and so is the Ethereum header/hash. Because we are currently mapping one-to-one in the frontier db, if the future canonical block is imported first, it will be overriden by the orphan block hash.To avoid that, this PR proposes going back to one-to-many for Ethereum<>Substrate block hash mapping + required data migration. Migration includes schema change for block mapping column (now holds a
Vec<Block::Hash>
insteadBlock::Hash
) + retroactive orphan substrate block hash substitution.Note on parity-db
For the migration we need to
iter
the block mapping column to retrieve the existing keys. In contrast to RocksDb, ParityDb apparently needs the column to be indexed to do that so I changed the block mapping column configuration to bebtree_index = true
.I'm not really sure if existing data for that column will be indexed when we opening the db, so I asked in paritytech/parity-db#129
** Update on parity-db **
Apparently is not possible to iterate over column data that was configured with default values, so we cannot get the keys of a hash-indexed column of an existing db. @sorpaas so either we set the
BLOCK_MAPPING
column tobtree_index = true
to support future migrations - being btree index generally slower than default hash index - or we don't support data migration for paritydb at all until an api is provided. In any case this PR will require a re-sync for any paritydb live dbs.