Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Apr 26, 2024
1 parent 30e322f commit c0b306c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
19 changes: 18 additions & 1 deletion activation/certifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"

"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/atxs"
Expand Down Expand Up @@ -275,7 +277,7 @@ func (c *CertifierClient) obtainPostFromLastAtx(ctx context.Context, nodeId type
if err != nil {
return nil, fmt.Errorf("failed to retrieve ATX: %w", err)

Check warning on line 278 in activation/certifier.go

View check run for this annotation

Codecov / codecov/patch

activation/certifier.go#L278

Added line #L278 was not covered by tests
}
atxNipost, err := atxs.Nipost(ctx, c.db, atxid)
atxNipost, err := loadNipost(ctx, c.db, atxid)
if err != nil {
return nil, errors.New("no NIPoST found in last ATX")

Check warning on line 282 in activation/certifier.go

View check run for this annotation

Codecov / codecov/patch

activation/certifier.go#L282

Added line #L282 was not covered by tests
}
Expand Down Expand Up @@ -418,3 +420,18 @@ func (d *disabledCertifier) Recertify(context.Context, types.NodeID, PoetClient)
func (d *disabledCertifier) CertifyAll(context.Context, types.NodeID, []PoetClient) map[string]*certifier.PoetCert {
return nil
}

// load NIPoST for the given ATX from the database.
func loadNipost(ctx context.Context, db sql.Executor, id types.ATXID) (*types.NIPost, error) {
var blob sql.Blob
if err := atxs.LoadBlob(ctx, db, id.Bytes(), &blob); err != nil {
return nil, fmt.Errorf("getting blob for %s: %w", id, err)

Check warning on line 428 in activation/certifier.go

View check run for this annotation

Codecov / codecov/patch

activation/certifier.go#L428

Added line #L428 was not covered by tests
}

// TODO: decide about version based on the `version` column
var atx wire.ActivationTxV1
if err := codec.Decode(blob.Bytes, &atx); err != nil {
return nil, fmt.Errorf("decoding ATX blob: %w", err)

Check warning on line 434 in activation/certifier.go

View check run for this annotation

Codecov / codecov/patch

activation/certifier.go#L434

Added line #L434 was not covered by tests
}
return wire.NiPostFromWireV1(atx.NIPost), nil
}
14 changes: 0 additions & 14 deletions sql/atxs/atxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,17 +796,3 @@ func IterateForGrading(
}
return nil
}

func Nipost(ctx context.Context, db sql.Executor, id types.ATXID) (*types.NIPost, error) {
var blob sql.Blob
if err := LoadBlob(ctx, db, id.Bytes(), &blob); err != nil {
return nil, fmt.Errorf("getting blob for %s: %w", id, err)
}

// TODO: decide about version based on the `version` column
var atx wire.ActivationTxV1
if err := codec.Decode(blob.Bytes, &atx); err != nil {
return nil, fmt.Errorf("decoding ATX blob: %w", err)
}
return wire.NiPostFromWireV1(atx.NIPost), nil
}

0 comments on commit c0b306c

Please sign in to comment.