Skip to content

Commit

Permalink
Rename StoreJournalRecord to RecordAndPrune
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 6, 2023
1 parent b6d7970 commit e53a7df
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dot/state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ type Telemetry interface {

// Pruner tracks state deltas and prunes keys from the storage database.
type Pruner interface {
StoreJournalRecord(deletedNodeHashes, insertedNodeHashes map[common.Hash]struct{},
RecordAndPrune(deletedNodeHashes, insertedNodeHashes map[common.Hash]struct{},
blockHash common.Hash, blockNumber uint32) error
}
2 changes: 1 addition & 1 deletion dot/state/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *StorageState) StoreTrie(ts *rtstorage.TrieState, header *types.Header)
deletedNodeHashes[nodeHash] = struct{}{}
}

err = s.pruner.StoreJournalRecord(deletedNodeHashes, insertedNodeHashes, header.Hash(), uint32(header.Number))
err = s.pruner.RecordAndPrune(deletedNodeHashes, insertedNodeHashes, header.Hash(), uint32(header.Number))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pruner/archive/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func New() *Pruner {
return &Pruner{}
}

// StoreJournalRecord for archive node doesn't do anything.
func (*Pruner) StoreJournalRecord(_, _ map[common.Hash]struct{}, _ common.Hash, _ uint32) (_ error) {
// RecordAndPrune for archive node doesn't do anything.
func (*Pruner) RecordAndPrune(_, _ map[common.Hash]struct{}, _ common.Hash, _ uint32) (_ error) {
return nil
}
6 changes: 3 additions & 3 deletions internal/pruner/full/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Pruner struct {
// highestBlockNumber is the highest block number stored in the journal.
// It is updated on disk but cached in memory as this field.
highestBlockNumber uint32
// mutex protects the in memory data members since StoreJournalRecord
// mutex protects the in memory data members since RecordAndPrune
// is called in lib/babe `epochHandler`'s `run` method which is run
// in its own goroutine.
mutex sync.RWMutex
Expand Down Expand Up @@ -87,10 +87,10 @@ func New(journalDB JournalDatabase, storageDB ChainDBNewBatcher, retainBlocks ui
return pruner, nil
}

// StoreJournalRecord stores the trie deltas impacting the storage database for a particular
// RecordAndPrune stores the trie deltas impacting the storage database for a particular
// block hash. It prunes all block numbers falling off the window of block numbers to keep,
// before inserting the new record. It is thread safe to call.
func (p *Pruner) StoreJournalRecord(deletedNodeHashes, insertedNodeHashes map[common.Hash]struct{},
func (p *Pruner) RecordAndPrune(deletedNodeHashes, insertedNodeHashes map[common.Hash]struct{},
blockHash common.Hash, blockNumber uint32) (err error) {
p.mutex.Lock()
defer p.mutex.Unlock()
Expand Down
10 changes: 5 additions & 5 deletions internal/pruner/full/pruner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_Pruner(t *testing.T) {
setNodeHashesInStorageDB(t, storageDB, []common.Hash{{1}, {2}})
logger.EXPECT().Debugf("journal data stored for block number %d and block hash %s",
uint32(0), "0x64000000...00000000")
err = pruner.StoreJournalRecord(
err = pruner.RecordAndPrune(
map[common.Hash]struct{}{}, // first block has no deleted node hashes
map[common.Hash]struct{}{{1}: {}, {2}: {}}, // inserted node hashes
common.Hash{100}, // block hash
Expand All @@ -57,7 +57,7 @@ func Test_Pruner(t *testing.T) {
setNodeHashesInStorageDB(t, storageDB, []common.Hash{{3}, {4}})
logger.EXPECT().Debugf("journal data stored for block number %d and block hash %s",
uint32(1), "0x65000000...00000000")
err = pruner.StoreJournalRecord(
err = pruner.RecordAndPrune(
map[common.Hash]struct{}{{1}: {}}, // deleted node hashes
map[common.Hash]struct{}{{3}: {}, {4}: {}}, // inserted node hashes
common.Hash{101}, // block hash
Expand All @@ -83,7 +83,7 @@ func Test_Pruner(t *testing.T) {
setNodeHashesInStorageDB(t, storageDB, []common.Hash{{5}, {6}})
logger.EXPECT().Debugf("journal data stored for block number %d and block hash %s",
uint32(1), "0x66000000...00000000")
err = pruner.StoreJournalRecord(
err = pruner.RecordAndPrune(
map[common.Hash]struct{}{{3}: {}}, // deleted node hashes
map[common.Hash]struct{}{{5}: {}, {6}: {}}, // inserted node hashes
common.Hash{102}, // block hash
Expand Down Expand Up @@ -115,7 +115,7 @@ func Test_Pruner(t *testing.T) {
logger.EXPECT().Debugf("pruned block numbers [%d..%d]", uint32(0), uint32(0))
logger.EXPECT().Debugf("journal data stored for block number %d and block hash %s",
uint32(2), "0x67000000...00000000")
err = pruner.StoreJournalRecord(
err = pruner.RecordAndPrune(
map[common.Hash]struct{}{{5}: {}}, // deleted node hashes
map[common.Hash]struct{}{{7}: {}, {8}: {}}, // inserted node hashes
common.Hash{103}, // block hash
Expand Down Expand Up @@ -152,7 +152,7 @@ func Test_Pruner(t *testing.T) {
logger.EXPECT().Debugf("pruned block numbers [%d..%d]", uint32(1), uint32(1))
logger.EXPECT().Debugf("journal data stored for block number %d and block hash %s",
uint32(3), "0x68000000...00000000")
err = pruner.StoreJournalRecord(
err = pruner.RecordAndPrune(
map[common.Hash]struct{}{{7}: {}}, // deleted node hashes
map[common.Hash]struct{}{{9}: {}, {10}: {}}, // inserted node hashes
common.Hash{104}, // block hash
Expand Down

0 comments on commit e53a7df

Please sign in to comment.