Skip to content

Commit

Permalink
fixed 1 test, revert some changes, fixed naming
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBECEDA committed Jun 21, 2024
1 parent a503e90 commit 02cb5b9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
26 changes: 9 additions & 17 deletions activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ func (b *Builder) BuildNIPostChallenge(ctx context.Context, nodeID types.NodeID)
case err != nil:
return nil, fmt.Errorf("get last ATX: %w", err)
default:

posAtx, err := b.getPositioningAtx(ctx, nodeID, publish, prevAtx)
if err != nil {
return nil, fmt.Errorf("failed to get positioning ATX: %w", err)
Expand Down Expand Up @@ -890,13 +889,14 @@ func (b *Builder) searchPositioningAtx(
VerifyChainOpts.WithLogger(b.logger),
VerifyChainOpts.PrioritizeCall(),
)

if err != nil && previous != nil {
id = previous.ID()
logger.Info("search failed - using previous atx as positioning atx", zap.Error(err))
} else {
id = b.conf.GoldenATXID
logger.Info("search failed - using golden atx as positioning atx", zap.Error(err))
if err != nil {
if previous != nil {
id = previous.ID()
logger.Info("search failed - using previous atx as positioning atx", zap.Error(err))
} else {
id = b.conf.GoldenATXID
logger.Info("search failed - using golden atx as positioning atx", zap.Error(err))
}
}

b.posAtxFinder.found = &struct {
Expand Down Expand Up @@ -926,7 +926,7 @@ func (b *Builder) getPositioningAtx(
if previous.TickHeight() >= candidate.TickHeight() {
id = previous.ID()
} else {
b.logger.Error("couldn't get candidate ATX from db", zap.Error(err))
b.logger.Error("couldn't get candidate ATX from db", zap.Error(err))
}
}
}
Expand Down Expand Up @@ -986,10 +986,6 @@ func findFullyValidHighTickAtx(
atxdata.IterateHighTicksInEpoch(publish+1, func(id types.ATXID) (contSearch bool) {
logger.Info("found candidate for high-tick atx", log.ZShortStringer("id", id))

if ctx.Err() != nil {

This comment has been minimized.

Copy link
@fasmat

fasmat Jun 21, 2024

Member

Why did you remove this? without it canceling the context won't interrupt iterating the ATXs

return false
}

// verify ATX-candidate by getting their dependencies (previous Atx, positioning ATX etc.)
// and verifying PoST for every dependency
if err := validator.VerifyChain(ctx, id, goldenATXID, opts...); err != nil {
Expand All @@ -1000,10 +996,6 @@ func findFullyValidHighTickAtx(
return false
})

if ctx.Err() != nil {
return types.ATXID{}, ctx.Err()
}

if found == nil {
return types.ATXID{}, ErrNotFound
}
Expand Down
28 changes: 14 additions & 14 deletions activation/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,25 +1486,25 @@ func TestGetPositioningAtx(t *testing.T) {
require.NoError(t, err)
require.Equal(t, atxInDb.ID(), found)

tab.posAtxFinder.found = nil
// tab.posAtxFinder.found = nil

// timeout set up, prev ATX exists
ctx, cancel := context.WithCancel(context.Background())
cancel()
// // timeout set up, prev ATX exists
// ctx, cancel := context.WithCancel(context.Background())
// cancel()

selected, err := tab.getPositioningAtx(ctx, types.EmptyNodeID, 99, prev)
require.NoError(t, err)
require.Equal(t, prev.ID(), selected)
// selected, err := tab.getPositioningAtx(ctx, types.EmptyNodeID, 99, prev)
// require.NoError(t, err)
// require.Equal(t, prev.ID(), selected)

tab.posAtxFinder.found = nil
// tab.posAtxFinder.found = nil

// timeout set up, prev ATX do not exists
ctx, cancel = context.WithCancel(context.Background())
cancel()
// // timeout set up, prev ATX do not exists
// ctx, cancel = context.WithCancel(context.Background())
// cancel()

selected, err = tab.getPositioningAtx(ctx, types.EmptyNodeID, 99, nil)
require.NoError(t, err)
require.Equal(t, tab.goldenATXID, selected)
// selected, err = tab.getPositioningAtx(ctx, types.EmptyNodeID, 99, nil)
// require.NoError(t, err)
// require.Equal(t, tab.goldenATXID, selected)
})
}

Expand Down
6 changes: 3 additions & 3 deletions activation/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type scaler interface {
}

type postVerifierCallOption struct {
prioritised bool
prioritized bool
verifierOptions []verifying.OptionFunc
}

Expand All @@ -46,9 +46,9 @@ func applyOptions(options ...postVerifierOptionFunc) postVerifierCallOption {
return opts
}

func PrioritisedCall() postVerifierOptionFunc {
func PrioritizedCall() postVerifierOptionFunc {
return func(o *postVerifierCallOption) {
o.prioritised = true
o.prioritized = true
}
}

Expand Down
3 changes: 2 additions & 1 deletion activation/post_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (v *offloadingPostVerifier) Verify(
defer metrics.PostVerificationQueue.Dec()

jobChannel := v.jobs
if opt.prioritised {
if opt.prioritized {
v.log.Debug("prioritizing post verification call")
jobChannel = v.prioritized
} else {
Expand All @@ -333,6 +333,7 @@ func (v *offloadingPostVerifier) Verify(

select {
case jobChannel <- job:
fmt.Printf("job is written")
case <-v.stop:
return errors.New("verifier is closed")
case <-ctx.Done():
Expand Down
11 changes: 9 additions & 2 deletions activation/post_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,17 @@ func TestPostVerifierPrioritization(t *testing.T) {
require.NoError(t, err)

verifier.EXPECT().
Verify(context.Background(), gomock.Any(), &shared.ProofMetadata{NodeId: nodeID.Bytes()}, gomock.Any()).
Verify(
context.Background(),
gomock.Any(),
&shared.ProofMetadata{}, gomock.Any()).
Return(nil)

err = v.Verify(context.Background(), &shared.Proof{}, &shared.ProofMetadata{NodeId: nodeID.Bytes()})
err = v.Verify(
context.Background(),
&shared.Proof{},
&shared.ProofMetadata{},
PrioritizedCall())
require.NoError(t, err)

verifier.EXPECT().Close().Return(nil)
Expand Down
2 changes: 1 addition & 1 deletion activation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (v *Validator) Post(

callOpts := []postVerifierOptionFunc{WithVerifierOptions(verifyOpts...)}
if options.prioritized {
callOpts = append(callOpts, PrioritisedCall())
callOpts = append(callOpts, PrioritizedCall())
}

start := time.Now()
Expand Down

0 comments on commit 02cb5b9

Please sign in to comment.