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

Partial fix for issue #2928 #3318

Merged
merged 2 commits into from
Oct 21, 2023
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
43 changes: 43 additions & 0 deletions src/apps/chifra/internal/chunks/handle_check_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"fmt"
"strings"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)

// CheckInternal reads the header of each chunk on disc looking for the Magic number and
Expand Down Expand Up @@ -37,5 +40,45 @@ func (opts *ChunksOptions) checkIndexChunkInternal(fileName string, report *simp
} else {
report.PassedCnt++
}

opts.checkSnaps(fileName, &indexChunk, report)

indexChunk.Close()
}

func (opts *ChunksOptions) checkSnaps(fileName string, indexChunk *index.Index, report *simpleReportCheck) {
report.VisitedCnt++
report.CheckedCnt++

// we will check the manifest since it's the gold standard
isSnap := func(fR base.FileRange, snapMarker, firstSnap uint64) bool {
return fR.Last >= firstSnap && fR.Last%snapMarker == 0
}

chain := opts.Globals.Chain
firstSnap := utils.MustParseUint(config.GetScrape(chain).FirstSnap)
snapMarker := utils.MustParseUint(config.GetScrape(chain).SnapToGrid)
appsPer := uint32(utils.MustParseUint(config.GetScrape(chain).AppsPerChunk))
if fR, err := base.RangeFromFilenameE(fileName); err != nil {
report.MsgStrings = append(report.MsgStrings, fmt.Sprintf("%s: %s", err, fileName))
} else {
if isSnap(fR, snapMarker, firstSnap) {
if fR.Last < firstSnap {
// Is there a snap_to_grid after first_snap everywhere it's supposed to be?
report.MsgStrings = append(report.MsgStrings, fmt.Sprintf("checkSnap: snap too early %s firstSnap=%d", fR, firstSnap))
} else if indexChunk.Header.AppearanceCount >= appsPer {
// For snapped chunks, nApps < apps_per_chunk.
report.MsgStrings = append(report.MsgStrings, fmt.Sprintf("contract: too many apps at %s appsPer=%d", fR, appsPer))
} else {
report.PassedCnt++
}
} else {
if indexChunk.Header.AppearanceCount < appsPer && fR.Last > 0 {
// For non-snapped chunks, nApps ≥ apps_per_chunk.
report.MsgStrings = append(report.MsgStrings, fmt.Sprintf("checkSnap: too few appearances at %s appsPer=%d", fR, appsPer))
} else {
report.PassedCnt++
}
}
}
}
7 changes: 5 additions & 2 deletions src/apps/chifra/internal/chunks/handle_check_sequential.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)

// CheckSequential checks that the range of blocks in each of three arrays (onDisc, LocalManifest, RemoteManifest)
// "cover" the range without gaps. (There may be a bug for allow_missing chains where gaps are allowed.)
// CheckSequential checks that the range of blocks in each of three arrays (onDisc,
// LocalManifest, RemoteManifest) "cover" the range without gaps. (There may be a bug
// for allow_missing chains where gaps are allowed.) It also makes sure than snap-to-grids
// happen where they should and that non-snaps have at least appsPerChunks records and
// snaps have exactly appsPerChunks records or less.
func (opts *ChunksOptions) CheckSequential(fnArray, cacheArray, remoteArray []string, allowMissing bool, report *simpleReportCheck) error {
if err := opts.checkSequential("disc", fnArray, allowMissing, report); err != nil {
return err
Expand Down