Skip to content

Commit

Permalink
Compare blocks now prints how to re-run with --diff to see differences
Browse files Browse the repository at this point in the history
  • Loading branch information
maoueh committed Jan 14, 2025
1 parent f370f93 commit 96a17bc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cmd/tools/compare/tools_compare_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ func runCompareBlocksE[B firecore.Block](chain *firecore.Chain[B]) firecore.Comm

var isDifferent bool
if existsInCurrent {
var differences []string
differences = Compare(referenceBlock, currentBlock, includeUnknownFields, registry, bytesEncoding)
differences := Compare(referenceBlock, currentBlock, includeUnknownFields, registry, bytesEncoding)

isDifferent = len(differences) > 0

Expand All @@ -226,6 +225,11 @@ func runCompareBlocksE[B firecore.Block](chain *firecore.Chain[B]) firecore.Comm
}
processState.print()

if processState.totalDifferencesFound > 0 {
fmt.Println()
fmt.Println("Re-run with --diff <specific-range> flag to see differences over a specific range of block")
}

return nil
}
}
Expand Down Expand Up @@ -295,7 +299,9 @@ type state struct {
blocksCountedInThisSegment int
differencesFound int
missingBlocks int
totalBlocksCounted int

totalBlocksCounted int
totalDifferencesFound int
}

func (s *state) process(blockNum uint64, isDifferent bool, isMissing bool) {
Expand All @@ -317,8 +323,8 @@ func (s *state) process(blockNum uint64, isDifferent bool, isMissing bool) {
s.missingBlocks++
} else if isDifferent {
s.differencesFound++
s.totalDifferencesFound++
}

}

func (s *state) print() {
Expand All @@ -339,7 +345,7 @@ func (s *state) print() {
return
}

fmt.Printf("✖ Segment %d - %s has %d different blocks and %d missing blocks (%d blocks counted)\n", s.segments[s.currentSegmentIdx].Start, endBlock, s.differencesFound, s.missingBlocks, s.totalBlocksCounted)
fmt.Printf("✖ Segment %d - %s has %d different blocks!and %d missing blocks (%d blocks counted)\n", s.segments[s.currentSegmentIdx].Start, endBlock, s.differencesFound, s.missingBlocks, s.totalBlocksCounted)
}

func Compare(reference proto.Message, current proto.Message, includeUnknownFields bool, registry *fcproto.Registry, bytesEncoding string) (differences []string) {
Expand All @@ -353,10 +359,10 @@ func Compare(reference proto.Message, current proto.Message, includeUnknownField
referenceMsg := reference.ProtoReflect()
currentMsg := current.ProtoReflect()
if referenceMsg.IsValid() && !currentMsg.IsValid() {
return []string{fmt.Sprintf("reference block is valid protobuf message, but current block is invalid")}
return []string{"reference block is valid protobuf message, but current block is invalid"}
}
if !referenceMsg.IsValid() && currentMsg.IsValid() {
return []string{fmt.Sprintf("reference block is invalid protobuf message, but current block is valid")}
return []string{"reference block is invalid protobuf message, but current block is valid"}
}

//todo: check if there is a equals that do not compare unknown fields
Expand Down

0 comments on commit 96a17bc

Please sign in to comment.