Skip to content
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

3650 fix import cycles #3652

Merged
merged 7 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/blocks/handle_hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (opts *BlocksOptions) HandleHashes() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/blocks/handle_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (opts *BlocksOptions) HandleLogs() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/blocks/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (opts *BlocksOptions) HandleShow() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/blocks/handle_uncles.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (opts *BlocksOptions) HandleUncles() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/blocks/handle_uniq.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (opts *BlocksOptions) HandleUniq() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/blocks/handle_withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (opts *BlocksOptions) HandleWithdrawals() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/chunks/handle_check_deep.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (opts *ChunksOptions) CheckDeep(cacheMan *manifest.Manifest, report *types.
logger.Info("Checking each address in each index against its Bloom filter...")
iterFunc = func(rangeStr string, item *reporter) (err error) {
rng := base.RangeFromRangeString(item.chunk.Range)
_, path := rng.RangeToFilename(chain)
path := rng.RangeToFilename(chain)
bl, err := index.OpenBloom(index.ToBloomPath(path), true /* check */)
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/chunks/handle_truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (opts *ChunksOptions) HandleTruncate(blockNums []base.Blknum) error {
nChunksRemoved++
} else {
// We did not remove the chunk, so we need to keep track of where the truncated index ends
latestChunk = base.Max2(latestChunk, rng.Last)
latestChunk = base.Max(latestChunk, rng.Last)
bar.Prefix = fmt.Sprintf("Not removing %s", rng)
}
bar.Tick()
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (opts *ExportOptions) HandleBalances(monitorArray []monitor.Monitor) error
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (opts *ExportOptions) HandleLogs(monitorArray []monitor.Monitor) error {
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_neighbors.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (opts *ExportOptions) HandleNeighbors(monitorArray []monitor.Monitor) error
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (opts *ExportOptions) HandleReceipts(monitorArray []monitor.Monitor) error
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (opts *ExportOptions) HandleShow(monitorArray []monitor.Monitor) error {
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (opts *ExportOptions) HandleStatements(monitorArray []monitor.Monitor) erro
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (opts *ExportOptions) HandleTraces(monitorArray []monitor.Monitor) error {
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/export/handle_withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (opts *ExportOptions) HandleWithdrawals(monitorArray []monitor.Monitor) err
chain := opts.Globals.Chain
testMode := opts.Globals.TestMode
nErrors := 0
first := base.Max2(base.KnownBlock(chain, "shanghai"), opts.FirstBlock)
first := base.Max(base.KnownBlock(chain, "shanghai"), opts.FirstBlock)
filter := filter.NewFilter(
opts.Reversed,
false,
Expand Down Expand Up @@ -54,7 +54,7 @@ func (opts *ExportOptions) HandleWithdrawals(monitorArray []monitor.Monitor) err
} else {
bar := logger.NewBar(logger.BarOptions{
Prefix: mon.Address.Hex(),
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
3 changes: 1 addition & 2 deletions src/apps/chifra/internal/init/handle_dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/history"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)

func (opts *InitOptions) HandleDryRun() error {
Expand Down Expand Up @@ -41,7 +40,7 @@ func (opts *InitOptions) HandleDryRun() error {

spec := manifest.Specification()
if opts.Globals.TestMode {
nToDownload = utils.Min(10, nToDownload)
nToDownload = base.Min(10, nToDownload)
spec = "--testing-hash--"
}

Expand Down
7 changes: 3 additions & 4 deletions src/apps/chifra/internal/init/handle_init_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/manifest"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/progress"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk"
)

Expand All @@ -33,7 +32,7 @@ var nStarted int
// downloadAndReportProgress Downloads the chunks and reports progress to the progressChannel
func (opts *InitOptions) downloadAndReportProgress(chunks []types.ChunkRecord, chunkType walk.CacheType, nTotal int) ([]types.ChunkRecord, bool) {
chain := opts.Globals.Chain
sleep := utils.Max(.0125, opts.Sleep)
sleep := base.Max(.0125, opts.Sleep)
successCount := 0

failed := []types.ChunkRecord{}
Expand Down Expand Up @@ -75,7 +74,7 @@ func (opts *InitOptions) downloadAndReportProgress(chunks []types.ChunkRecord, c
if ok {
failed = append(failed, *chunk)
if errors.Is(event.Error, index.ErrWriteToDiscError) {
sleep = utils.Min(4, sleep*1.2)
sleep = base.Min(4, sleep*1.2)
successCount = 0
}
}
Expand Down Expand Up @@ -109,7 +108,7 @@ func (opts *InitOptions) downloadAndReportProgress(chunks []types.ChunkRecord, c
msg := fmt.Sprintf("Finished download of %s%s%s %s%s%s (% 4d of %4d %0.1f%%%s)", col, event.Message, colors.Off, col, rng, colors.Off, nProcessed, nTotal, pct, sleepStr)
logger.Info(msg, spaces)
if successCount%10 == 0 {
sleep = utils.Max(.0125, sleep/1.2)
sleep = base.Max(.0125, sleep/1.2)
successCount = 0
}

Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/init/handle_init_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (opts *InitOptions) prepareDownloadList(chain string, man *manifest.Manifes

nDeleted := 0
for rng, reason := range deleteMap {
_, indexPath := rng.RangeToFilename(chain)
indexPath := rng.RangeToFilename(chain)
bloomPath := index.ToBloomPath(indexPath)
indexExists := file.FileExists(indexPath)
bloomExists := file.FileExists(bloomPath)
Expand Down Expand Up @@ -160,7 +160,7 @@ func (opts *InitOptions) prepareDownloadList(chain string, man *manifest.Manifes
if downloadMap[rng] == OKAY || rng.Last < opts.FirstBlock {
continue
}
_, indexPath := rng.RangeToFilename(chain)
indexPath := rng.RangeToFilename(chain)
bloomStatus, indexStatus, err := isValidChunk(index.ToBloomPath(indexPath), chunk.BloomSize, chunk.IndexSize, opts.All)
if err != nil {
return nil, 0, nDeleted, err
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/logs/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (opts *LogsOptions) HandleShow() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/monitors/handle_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (opts *MonitorsOptions) Refresh(monitors []monitor.Monitor) (bool, error) {
fmt.Printf("%s%d-%d of %d:%s chifra export --freshen",
colors.BrightBlue,
i*batchSize,
utils.Min(((i+1)*batchSize)-1, len(monitors)),
base.Min(((i+1)*batchSize)-1, len(monitors)),
len(monitors),
colors.Green)
for _, addr := range addrs {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/receipts/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (opts *ReceiptsOptions) HandleShow() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/scrape/handle_scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (opts *ScrapeOptions) HandleScrape() error {
// }

// user supplied, but not so many to pass the chain tip.
bm.blockCount = base.Min2(base.Blknum(opts.BlockCnt), bm.meta.ChainHeight()-bm.StartBlock()+1)
bm.blockCount = base.Min(base.Blknum(opts.BlockCnt), bm.meta.ChainHeight()-bm.StartBlock()+1)
// Unripe_dist behind the chain tip.
bm.ripeBlock = bm.meta.ChainHeight() - base.Blknum(opts.Settings.UnripeDist)

Expand Down
6 changes: 3 additions & 3 deletions src/apps/chifra/internal/scrape/scrape_consolidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (bm *BlazeManager) Consolidate(blocks []base.Blknum) (error, bool) {
for _, app := range apps {
record := fmt.Sprintf("%s\t%09d\t%05d", addr, app.BlockNumber, app.TransactionIndex)
appearances = append(appearances, record)
newRange.Last = base.Max2(newRange.Last, base.Blknum(app.BlockNumber))
newRange.Last = base.Max(newRange.Last, base.Blknum(app.BlockNumber))
}
}

Expand Down Expand Up @@ -196,8 +196,8 @@ func (bm *BlazeManager) AsciiFileToAppearanceMap(fn string) (map[string][]types.
if addr == base.SentinalAddr.Hex() && txid == types.MisconfigReward {
continue
}
fileRange.First = base.Min2(fileRange.First, bn)
fileRange.Last = base.Max2(fileRange.Last, bn)
fileRange.First = base.Min(fileRange.First, bn)
fileRange.Last = base.Max(fileRange.Last, bn)
appMap[addr] = append(appMap[addr], types.AppRecord{
BlockNumber: uint32(bn),
TransactionIndex: uint32(txid),
Expand Down
3 changes: 1 addition & 2 deletions src/apps/chifra/internal/scrape/scrape_manager_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/colors"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)

// Report prints out a report of the progress of the scraper.
func (bm *BlazeManager) report(nBlocks, perChunk, nChunks, nAppsNow, nAppsFound, nAddrsFound int) {
nNeeded := perChunk - utils.Min(perChunk, nAppsNow)
nNeeded := perChunk - base.Min(perChunk, nAppsNow)
appsPerAddr := float64(nAppsFound) / float64(nAddrsFound)
pctFull := float64(nAppsNow) / float64(perChunk)

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/scrape/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (opts *ScrapeOptions) validateScrape() error {
if err != nil {
return err
}
m := base.Max2(meta.Ripe, base.Max2(meta.Staging, meta.Finalized)) + 1
m := base.Max(meta.Ripe, base.Max(meta.Staging, meta.Finalized)) + 1
if !opts.DryRun && m > meta.Latest {
fmt.Println(validate.Usage("The index ({0}) is ahead of the chain ({1}).", fmt.Sprintf("%d", m), fmt.Sprintf("%d", meta.Latest)))
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/slurp/handle_appearances.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package slurpPkg
import (
"context"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
providerPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc/provider"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)

func (opts *SlurpOptions) HandleAppearances() error {
provider, err := opts.Provider()
if err != nil {
return err
}
provider.SetPrintProgress(!opts.Globals.TestMode && !utils.IsTerminal())
provider.SetPrintProgress(!opts.Globals.TestMode && !logger.IsTerminal())
query := &providerPkg.Query{
Addresses: opts.Addresses(),
Resources: opts.Types,
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/slurp/handle_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package slurpPkg
import (
"context"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
providerPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc/provider"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)

func (opts *SlurpOptions) HandleCount() error {
provider, err := opts.Provider()
if err != nil {
return err
}
provider.SetPrintProgress(!opts.Globals.TestMode && !utils.IsTerminal())
provider.SetPrintProgress(!opts.Globals.TestMode && !logger.IsTerminal())
query := &providerPkg.Query{
Addresses: opts.Addresses(),
Resources: opts.Types,
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/slurp/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/articulate"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
providerPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc/provider"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)

func (opts *SlurpOptions) HandleShow() error {
Expand All @@ -17,7 +17,7 @@ func (opts *SlurpOptions) HandleShow() error {
if err != nil {
return err
}
provider.SetPrintProgress(!opts.Globals.TestMode && !utils.IsTerminal())
provider.SetPrintProgress(!opts.Globals.TestMode && !logger.IsTerminal())
query := &providerPkg.Query{
Addresses: opts.Addresses(),
Resources: opts.Types,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/state/handle_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (opts *StateOptions) HandleCall() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/traces/handle_counts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (opts *TracesOptions) HandleCounts() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/traces/handle_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (opts *TracesOptions) HandleFilter() error {

} else {
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode && !utils.IsTerminal(),
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(cnt),
})

Expand Down
Loading
Loading