Skip to content

Commit

Permalink
Add code for post validation to activation malfeasance handler
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Nov 4, 2024
1 parent 1e3423f commit e3b99be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions activation/malfeasance2_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type MalfeasanceHandlerV2 struct {
cdb *datastore.CachedDB

Check failure on line 19 in activation/malfeasance2_handler.go

View workflow job for this annotation

GitHub Actions / lint

field `cdb` is unused (unused)
tortoise system.Tortoise

Check failure on line 20 in activation/malfeasance2_handler.go

View workflow job for this annotation

GitHub Actions / lint

field `tortoise` is unused (unused)
edVerifier *signing.EdVerifier
validator nipostValidatorV2
}

func NewMalfeasanceHandlerV2(
Expand All @@ -28,6 +29,7 @@ func NewMalfeasanceHandlerV2(
cdb *datastore.CachedDB,
tortoise system.Tortoise,
edVerifier *signing.EdVerifier,
validator nipostValidatorV2,
) *MalfeasanceHandlerV2 {
return &MalfeasanceHandlerV2{
syncer: syncer,
Expand All @@ -36,9 +38,22 @@ func NewMalfeasanceHandlerV2(
cdb: cdb,
tortoise: tortoise,
edVerifier: edVerifier,
validator: validator,
}

Check warning on line 42 in activation/malfeasance2_handler.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance2_handler.go#L33-L42

Added lines #L33 - L42 were not covered by tests
}

func (mh *MalfeasanceHandlerV2) PostV2Idx(
ctx context.Context,
nodeId types.NodeID,
commitmentAtxId types.ATXID,
post *types.Post,
challenge []byte,
numUnits uint32,
idx int,
) error {
return mh.validator.PostV2(ctx, nodeId, commitmentAtxId, post, challenge, numUnits, PostIndex(idx))

Check warning on line 54 in activation/malfeasance2_handler.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance2_handler.go#L53-L54

Added lines #L53 - L54 were not covered by tests
}

// TODO(mafa): call this validate in the handler for publish/gossip.
// TODO(mafa): extend this validate to return nil if `peer` == self.
func (mh *MalfeasanceHandlerV2) Validate(ctx context.Context, data []byte) ([]types.NodeID, error) {
Expand Down
12 changes: 12 additions & 0 deletions activation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (e *ErrAtxNotFound) Is(target error) bool {
}

type validatorOptions struct {
postIdx *int
postSubsetSeed []byte
prioritized bool
}
Expand All @@ -53,6 +54,14 @@ func PostSubset(seed []byte) validatorOption {
}
}

// PostIndex configures the validator to validate only the POST index at the given `idx`.
func PostIndex(idx int) validatorOption {
return func(o *validatorOptions) {
o.postIdx = new(int)
*o.postIdx = idx
}

Check warning on line 62 in activation/validation.go

View check run for this annotation

Codecov / codecov/patch

activation/validation.go#L58-L62

Added lines #L58 - L62 were not covered by tests
}

func PrioritizeCall() validatorOption {
return func(o *validatorOptions) {
o.prioritized = true
Expand Down Expand Up @@ -204,6 +213,9 @@ func (v *Validator) Post(
}

verifyOpts := []verifying.OptionFunc{verifying.WithLabelScryptParams(v.scrypt)}
if options.postIdx != nil {
verifyOpts = append(verifyOpts, verifying.SelectedIndex(*options.postIdx))
}

Check warning on line 218 in activation/validation.go

View check run for this annotation

Codecov / codecov/patch

activation/validation.go#L217-L218

Added lines #L217 - L218 were not covered by tests
if options.postSubsetSeed != nil {
verifyOpts = append(verifyOpts, verifying.Subset(v.cfg.K3, options.postSubsetSeed))
}
Expand Down

0 comments on commit e3b99be

Please sign in to comment.