Skip to content

Commit

Permalink
Fix misleading error (#4725)
Browse files Browse the repository at this point in the history
## Motivation
Users often get confused by the log message when the nipost_challenge.bin doesn't exist. This is a normal situation, yet the log includes "errormsg".

## Changes
Don't log an error in case the file is not found.

Additionally, includes a fix for a bug discovered during testing. The code panicked when the file was too small (for example empty).

## Test Plan
- UT
- [x] manual test
  • Loading branch information
poszu committed Jul 19, 2023
1 parent c418ee5 commit a4fb17f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,11 @@ func (b *Builder) PublishActivationTx(ctx context.Context) error {

challenge, err := b.loadChallenge()
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
logger.With().Warning("failed to load atx challenge", log.Err(err))
}
logger.With().Info("building new atx challenge",
log.Stringer("current_epoch", b.currentEpoch()),
log.Err(err),
)
challenge, err = b.buildNIPostChallenge(ctx)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions activation/nipost_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func read(path string) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("failed to get file info %s: %w", path, err)
}
if fInfo.Size() < crc64.Size {
return nil, fmt.Errorf("file %s is too small", path)
}

data := make([]byte, fInfo.Size()-crc64.Size)
checksum := crc64.New(crc64.MakeTable(crc64.ISO))
Expand Down
10 changes: 10 additions & 0 deletions activation/nipost_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ func TestReadCRC(t *testing.T) {
data: []byte("spacemesh"),
crc: []byte{0xC7, 0x11, 0x73, 0xE0, 0x53, 0xD8, 0x75, 0x0F},
errMsg: "wrong checksum 0xC71173E053D8750F, computed 0xC61072DF52D7740E",
}, {
name: "file too short",
data: []byte("123"),
crc: []byte{},
errMsg: "too small",
}, {
name: "file empty",
data: []byte(""),
crc: []byte{0xC6, 0x10, 0x72, 0xDF, 0x52, 0xD7, 0x74, 0x0E},
errMsg: "wrong checksum 0xC61072DF52D7740E, computed 0x0",
},
}

Expand Down

0 comments on commit a4fb17f

Please sign in to comment.