-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor the node key as
version + local nonce(seq id)
(#676)
Co-authored-by: Marko <[email protected]>
- Loading branch information
1 parent
a9766cf
commit e46665c
Showing
28 changed files
with
1,065 additions
and
1,053 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,15 @@ | ||
# Key Format | ||
|
||
Nodes, orphans, and roots are stored under the database with different key formats to ensure there are no key collisions and a structured key from which we can extract useful information. | ||
Nodes and fastNodes are stored under the database with different key formats to ensure there are no key collisions and a structured key from which we can extract useful information. | ||
|
||
### Nodes | ||
|
||
Node KeyFormat: `n|<node.hash>` | ||
Node KeyFormat: `n|node.nodeKey.version|node.nodeKey.nonce` | ||
|
||
Nodes are marshalled and stored under nodekey with prefix `n` to prevent collisions and then appended with the node's hash. | ||
|
||
### Orphans | ||
### FastNodes | ||
|
||
Orphan KeyFormat: `o|toVersion|fromVersion|hash` | ||
FastNode KeyFormat: `f|node.key` | ||
|
||
Orphans are marshalled nodes stored with prefix `o` to prevent collisions. You can extract the toVersion, fromVersion and hash from the orphan key by using: | ||
|
||
```golang | ||
// orphanKey: o|50|30|0xABCD | ||
var toVersion, fromVersion int64 | ||
var hash []byte | ||
orphanKeyFormat.Scan(orphanKey, &toVersion, &fromVersion, hash) | ||
|
||
/* | ||
toVersion = 50 | ||
fromVersion = 30 | ||
hash = 0xABCD | ||
*/ | ||
``` | ||
|
||
The order of the orphan KeyFormat matters. Since deleting a version `v` will delete all orphans whose `toVersion = v`, we can easily retrieve all orphans from nodeDb by iterating over the key prefix: `o|v`. | ||
|
||
### Roots | ||
|
||
Root KeyFormat: `r|<version>` | ||
|
||
Root hash of the IAVL tree at version `v` is stored under the key `r|v` (prefixed with `r` to avoid collision). | ||
FastNodes are marshalled nodes stored with prefix `f` to prevent collisions. You can extract fast nodes from the database by iterating over the keys with prefix `f`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.