Skip to content

Commit

Permalink
Rename nameProgressLogger -> claimProgressLogger and tweak log message.
Browse files Browse the repository at this point in the history
  • Loading branch information
moodyjon authored and roylee17 committed Jun 14, 2022
1 parent 2b7f065 commit ca9b4e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions claimtrie/claimtrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type ClaimTrie struct {
// Registrered cleanup functions which are invoked in the Close() in reverse order.
cleanups []func() error

// nameLogger communicates progress of claimtrie rebuild.
nameLogger *nameProgressLogger
// claimLogger communicates progress of claimtrie rebuild.
claimLogger *claimProgressLogger
}

func New(cfg config.Config) (*ClaimTrie, error) {
Expand Down Expand Up @@ -349,17 +349,17 @@ func (ct *ClaimTrie) runFullTrieRebuild(names [][]byte, interrupt <-chan struct{
var nhns chan NameHashNext
if names == nil {
node.Log("Building the entire claim trie in RAM...")
ct.nameLogger = newNameProgressLogger("Processed", node.GetLogger())
ct.claimLogger = newClaimProgressLogger("Processed", node.GetLogger())
nhns = ct.makeNameHashNext(nil, true, interrupt)
} else {
ct.nameLogger = nil
ct.claimLogger = nil
nhns = ct.makeNameHashNext(names, false, interrupt)
}

for nhn := range nhns {
ct.merkleTrie.Update(nhn.Name, nhn.Hash, false)
if ct.nameLogger != nil {
ct.nameLogger.LogName(nhn.Name)
if ct.claimLogger != nil {
ct.claimLogger.LogName(nhn.Name)
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions claimtrie/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/btcsuite/btclog"
)

// nameProgressLogger provides periodic logging for other services in order
// claimProgressLogger provides periodic logging for other services in order
// to show users progress of certain "actions" involving some or all current
// claim names. Ex: rebuilding claimtrie.
type nameProgressLogger struct {
type claimProgressLogger struct {
totalLogName int64
recentLogName int64
lastLogNameTime time.Time
Expand All @@ -24,21 +24,21 @@ type nameProgressLogger struct {
sync.Mutex
}

// newNameProgressLogger returns a new name progress logger.
// newClaimProgressLogger returns a new name progress logger.
// The progress message is templated as follows:
// {progressAction} {numProcessed} {names|name} in the last {timePeriod} (total {totalProcessed})
func newNameProgressLogger(progressMessage string, logger btclog.Logger) *nameProgressLogger {
return &nameProgressLogger{
func newClaimProgressLogger(progressMessage string, logger btclog.Logger) *claimProgressLogger {
return &claimProgressLogger{
lastLogNameTime: time.Now(),
progressAction: progressMessage,
subsystemLogger: logger,
}
}

// LogName logs a new name as an information message to show progress
// to the user. In order to prevent spam, it limits logging to one
// message every 10 seconds with duration and totals included.
func (n *nameProgressLogger) LogName(name []byte) {
// LogName logs a new claim name as an information message to show progress
// to the user. In order to prevent spam, it limits logging to one message
// every 10 seconds with duration and totals included.
func (n *claimProgressLogger) LogName(name []byte) {
n.Lock()
defer n.Unlock()

Expand All @@ -60,13 +60,13 @@ func (n *nameProgressLogger) LogName(name []byte) {
if n.recentLogName == 1 {
nameStr = "name"
}
n.subsystemLogger.Infof("%s %d %s in the last %s (total %d)",
n.subsystemLogger.Infof("%s %d claim %s in the last %s (total %d)",
n.progressAction, n.recentLogName, nameStr, tDuration, n.totalLogName)

n.recentLogName = 0
n.lastLogNameTime = now
}

func (n *nameProgressLogger) SetLastLogTime(time time.Time) {
func (n *claimProgressLogger) SetLastLogTime(time time.Time) {
n.lastLogNameTime = time
}

0 comments on commit ca9b4e5

Please sign in to comment.