-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(halo/voter): improve errors and logs (#2437)
Add temporary logs to voter to debug duplicate vote issue. issue: #2286
- Loading branch information
1 parent
ff4cbe3
commit 9d4f7ae
Showing
9 changed files
with
122 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"strconv" | ||
|
||
"github.com/omni-network/omni/lib/xchain" | ||
) | ||
|
||
const logLimit = 5 | ||
|
||
// VoteLogs returns the logs as opinionated human-readable logging attributes. | ||
func VoteLogs(votes []*Vote) []any { | ||
var headers []*AttestHeader | ||
for _, vote := range votes { | ||
headers = append(headers, vote.GetAttestHeader()) | ||
} | ||
|
||
return AttLogs(headers) | ||
} | ||
|
||
// AttLogs returns the headers as opinionated human-readable logging attributes. | ||
func AttLogs(headers []*AttestHeader) []any { | ||
offsets := make(map[xchain.ChainVersion][]string) | ||
for _, header := range headers { | ||
offset := offsets[header.XChainVersion()] | ||
if len(offset) < logLimit { | ||
offset = append(offset, strconv.FormatUint(header.AttestOffset, 10)) | ||
} else if len(offset) == logLimit { | ||
offset = append(offset, "...") | ||
} else { | ||
continue | ||
} | ||
offsets[header.XChainVersion()] = offset | ||
} | ||
|
||
attrs := []any{slog.Int("count", len(offsets))} | ||
for chainVer, offsets := range offsets { | ||
attrs = append(attrs, slog.String( | ||
fmt.Sprintf("%d-%d", chainVer.ID, chainVer.ConfLevel), | ||
fmt.Sprint(offsets), | ||
)) | ||
} | ||
|
||
return attrs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.