Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Dec 12, 2024
1 parent a063b68 commit a27453e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion internal/client/api/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type Backend[
// Commit block insertion.
CommitOperation(transaction BlockImportOperation[N, H, Hasher, Header, E]) error

// Finalize block with given `hash`.
// Finalize block with given hash.
//
// This should only be called if the parent of the given block has been finalized.
FinalizeBlock(hash H, justification *runtime.Justification) error
Expand Down
2 changes: 1 addition & 1 deletion internal/client/consensus/grandpa/justification.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (j *GrandpaJustification[Hash, N]) Target() HashNumber[Hash, N] {
}
}

// ancestryChain a utility trait implementing `grandpa.Chain` using a given set of headers.
// ancestryChain a utility trait implementing grandpa.Chain using a given set of headers.
// This is useful when validating commits, using the given set of headers to
// verify a valid ancestry route to the target commit block.
type ancestryChain[Hash runtime.Hash, N runtime.Number] struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/db/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ func TestBackend(t *testing.T) {
}

// This should also not trigger it yet, because we import a best block, but the best
// block from the POV of the db is still at `0`.
// block from the POV of the db is still at 0.
var block3 hash.H256
{
op := backend.beginOperation()
Expand Down
2 changes: 1 addition & 1 deletion internal/client/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (bdb *blockchainDB[H, N, E, Header]) LongestContaining(baseHash H, importLo
defer importLock.RUnlock()
info := bdb.Info()
if info.FinalizedNumber > (*baseHeader).Number() {
// `baseHeader` is on a dead fork.
// baseHeader is on a dead fork.
return nil, nil
}
return bdb.Leaves()
Expand Down
4 changes: 2 additions & 2 deletions internal/client/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestBlockchainDB_insertPersistedJustificationsIfPinned(t *testing.T) {
db.insertPersistedJustificationsIfPinned(someHash)
assert.False(t, db.pinnedBlocksCache.Contains(someHash))

// nothing in the db, but will pin `runtime.Justifications(nil)`
// nothing in the db, but will pin runtime.Justifications(nil)
db.pinnedBlocksCache.Pin(someHash)
err = db.insertPersistedJustificationsIfPinned(someHash)
assert.NoError(t, err)
Expand All @@ -163,7 +163,7 @@ func TestBlockchainDB_insertPersistedBodyIfPinned(t *testing.T) {
db.insertPersistedBodyIfPinned(someHash)
assert.False(t, db.pinnedBlocksCache.Contains(someHash))

// nothing in the db, but will pin `[]runtime.Extrinsic(nil)`
// nothing in the db, but will pin []runtime.Extrinsic(nil)
db.pinnedBlocksCache.Pin(someHash)
err = db.insertPersistedBodyIfPinned(someHash)
assert.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions internal/client/state-db/noncanonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var lastCanonical = []byte("last_canonical")
const maxBlocksPerLevel uint64 = 32

// nonCanonicalOverlay maintains trees of block overlays and allows discarding trees/roots.
// The overlays are added in `Insert` and removed in `Canonicalize`.
// The overlays are added in Insert and removed in Canonicalize.
type nonCanonicalOverlay[BlockHash Hash, Key Hash] struct {
lastCanonicalized *hashBlock[BlockHash]
levels deque.Deque[overlayLevel[BlockHash, Key]]
Expand Down Expand Up @@ -264,7 +264,7 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) Sync() {
}

// Canonicalize will select a top-level root and canonicalized it. Discards all sibling subtrees and the root.
// Add a set of changes of the canonicalized block to a provided `CommitSet`
// Add a set of changes of the canonicalized block to a provided CommitSet
// Return the block number of the canonicalized block
func (nco *nonCanonicalOverlay[BlockHash, Key]) Canonicalize(
hash BlockHash,
Expand Down Expand Up @@ -374,7 +374,7 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) HaveBlock(hash BlockHash) bool {
return ok
}

// RevertOne will revert a single level. Returns commit set that deletes the journal or `nil` if not
// RevertOne will revert a single level. Returns commit set that deletes the journal or nil if not
// possible.
func (nco *nonCanonicalOverlay[BlockHash, Key]) RevertOne() *CommitSet[Key] {
if nco.levels.Len() == 0 {
Expand All @@ -390,7 +390,7 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) RevertOne() *CommitSet[Key] {
return &commit
}

// Remove will revert a single block. Returns commit set that deletes the journal or `nil` if not
// Remove will revert a single block. Returns commit set that deletes the journal or nil if not
// possible.
func (nco *nonCanonicalOverlay[BlockHash, Key]) Remove(hash BlockHash) *CommitSet[Key] {
commit := CommitSet[Key]{}
Expand Down
12 changes: 6 additions & 6 deletions internal/client/state-db/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (rw *pruningWindow[BlockHash, Key]) HaveBlock(hash BlockHash, number uint64
return rw.queue.HaveBlock(hash, uint(number-rw.base))
}

// Prune next block. Expects at least one block in the window. Adds changes to `commit`.
// Prune next block. Expects at least one block in the window. Adds changes to commit.
func (rw *pruningWindow[BlockHash, Key]) PruneOne(commit *CommitSet[Key]) error {
pruned, err := rw.queue.PopFront(rw.base)
if err != nil {
Expand All @@ -113,7 +113,7 @@ func (rw *pruningWindow[BlockHash, Key]) PruneOne(commit *CommitSet[Key]) error
}
}

// Add a change set to the window. Creates a journal record and pushes it to `commit`
// Add a change set to the window. Creates a journal record and pushes it to commit
func (rw *pruningWindow[BlockHash, Key]) NoteCanonical(hash BlockHash, number uint64, commit *CommitSet[Key]) error {
if rw.base == 0 && rw.isEmpty() && number > 0 {
// This branch is taken if the node imports the target block of a warp sync.
Expand Down Expand Up @@ -159,7 +159,7 @@ type deathRowQueue[BlockHash Hash, Key Hash] interface {
type inMemDeathRowQueue[BlockHash Hash, Key Hash] struct {
// A queue of keys that should be deleted for each block in the pruning window.
deathRows deque.Deque[deathRow[BlockHash, Key]]
// An index that maps each key from `death_rows` to block number.
// An index that maps each key from death_rows to block number.
deathIndex map[Key]uint64
}

Expand Down Expand Up @@ -221,7 +221,7 @@ func (drqim *inMemDeathRowQueue[BlockHash, Key]) Import(
drqim.deathRows.PushBack(deathRow[BlockHash, Key]{hash, deletedMap})
}

// Pop out one block from the front of the queue, `base` is the block number
// Pop out one block from the front of the queue, base is the block number
// of the first block of the queue
func (drqim *inMemDeathRowQueue[BlockHash, Key]) PopFront(base uint64) (*deathRow[BlockHash, Key], error) {
if drqim.deathRows.Len() == 0 {
Expand All @@ -234,8 +234,8 @@ func (drqim *inMemDeathRowQueue[BlockHash, Key]) PopFront(base uint64) (*deathRo
return &row, nil
}

// Check if the block at the given `index` of the queue exist
// it is the caller's responsibility to ensure `index` won't be out of bounds
// Check if the block at the given index of the queue exist
// it is the caller's responsibility to ensure index won't be out of bounds
func (drqim *inMemDeathRowQueue[BlockHash, Key]) HaveBlock(hash BlockHash, index uint) haveBlock {
if drqim.deathRows.At(int(index)).hash == hash {
return haveBlockYes
Expand Down
4 changes: 2 additions & 2 deletions internal/client/state-db/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestRefWindow_ReinsertedSurvivesPending(t *testing.T) {

// Ensure that after warp syncing the state is stored correctly in the db. The warp sync target
// block is imported with all its state at once. This test ensures that after a restart
// `pruning` still knows that this block was imported.
// pruning still knows that this block was imported.
func TestRefWindow_StoreCorrectStateAfterWarpSyncing(t *testing.T) {
db := NewTestDB([]uint64{})
pruning, err := newPruningWindow[hash.H256, hash.H256](db, defaultMaxBlockConstraint)
Expand All @@ -221,7 +221,7 @@ func TestRefWindow_StoreCorrectStateAfterWarpSyncing(t *testing.T) {
assert.Equal(t, haveBlockYes, pruning.HaveBlock(h, block))

// load a new queue from db
// `cache` should be the same
// cache should be the same
pruning, err = newPruningWindow[hash.H256, hash.H256](db, defaultMaxBlockConstraint)
assert.NoError(t, err)
assert.Equal(t, haveBlockYes, pruning.HaveBlock(h, block))
Expand Down
20 changes: 10 additions & 10 deletions internal/client/state-db/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ func (sdbs *stateDBSync[BlockHash, Key]) insertBlock(
}

func (sdbs *stateDBSync[BlockHash, Key]) canonicalizeBlock(hash BlockHash) (CommitSet[Key], error) {
// NOTE: it is important that the change to `lastCanonical` (emit from
// `nonCanonicalOverlay.Canonicalize`) and the insert of the new pruning journal (emit from
// `pruningWindow.NoteCanonical`) are collected into the same `CommitSet` and are committed to
// NOTE: it is important that the change to lastCanonical (emit from
// nonCanonicalOverlay.Canonicalize) and the insert of the new pruning journal (emit from
// pruningWindow.NoteCanonical) are collected into the same CommitSet and are committed to
// the database atomically to keep their consistency when restarting the node
commit := CommitSet[Key]{}
if _, ok := sdbs.mode.(PruningModeArchiveAll); ok {
Expand Down Expand Up @@ -329,7 +329,7 @@ func (sdbs *stateDBSync[BlockHash, Key]) prune(commit *CommitSet[Key]) error {
}
}
err = sdbs.pruning.PruneOne(commit)
// this branch should not reach as previous `next_hash` don't return error
// this branch should not reach as previous next_hash don't return error
// keeping it for robustness
if err != nil {
if errors.Is(err, ErrBlockUnavailable) {
Expand All @@ -343,7 +343,7 @@ func (sdbs *stateDBSync[BlockHash, Key]) prune(commit *CommitSet[Key]) error {
}

// Revert all non-canonical blocks with the best block number.
// Returns a database commit or `None` if not possible.
// Returns a database commit or None if not possible.
// For archive an empty commit set is returned.
func (sdbs *stateDBSync[BlockHash, Key]) revertOne() *CommitSet[Key] {
switch sdbs.mode.(type) {
Expand Down Expand Up @@ -451,7 +451,7 @@ func (sdbs *stateDBSync[BlockHash, Key]) get(key Key, db NodeDB[Key]) (DBValue,
// unfinalized block may be forced.
//
// # Pruning.
// See `pruningWindow` for pruning algorithm details. `StateDB` prunes on each canonicalization until
// See pruningWindow for pruning algorithm details. StateDB prunes on each canonicalization until
// pruning constraints are satisfied.
type StateDB[BlockHash Hash, Key Hash] struct {
db stateDBSync[BlockHash, Key]
Expand Down Expand Up @@ -549,7 +549,7 @@ func (sdb *StateDB[BlockHash, Key]) CanonicalizeBlock(hash BlockHash) (CommitSet
}

// Pin prevents pruning of specified block and its descendants.
// `hint` used for further checking if the given block exists
// hint used for further checking if the given block exists
func (sdb *StateDB[BlockHash, Key]) Pin(hash BlockHash, number uint64, hint func() bool) error {
sdb.Lock()
defer sdb.Unlock()
Expand Down Expand Up @@ -579,7 +579,7 @@ func (sdb *StateDB[BlockHash, Key]) Get(key Key, db NodeDB[Key]) (DBValue, error
}

// RevertOne will revert all non-canonical blocks with the best block number.
// Returns a database commit or `nil` if not possible.
// Returns a database commit or nil if not possible.
// For archive an empty commit set is returned.
func (sdb *StateDB[BlockHash, Key]) RevertOne() *CommitSet[Key] {
sdb.Lock()
Expand All @@ -588,7 +588,7 @@ func (sdb *StateDB[BlockHash, Key]) RevertOne() *CommitSet[Key] {
}

// Remove specified non-canonical block.
// Returns a database commit or `nil` if not possible.
// Returns a database commit or nil if not possible.
func (sdb *StateDB[BlockHash, Key]) Remove(hash BlockHash) *CommitSet[Key] {
sdb.Lock()
defer sdb.Unlock()
Expand Down Expand Up @@ -621,7 +621,7 @@ func (sdb *StateDB[BlockHash, Key]) Reset(db MetaDB) error {
return nil
}

// The result returned by `StateDB.IsPruned()`
// The result returned by StateDB.IsPruned()
type IsPruned uint

const (
Expand Down

0 comments on commit a27453e

Please sign in to comment.