Skip to content

Commit

Permalink
Merge pull request #5974 from spacemeshos/backport/1.5/5943
Browse files Browse the repository at this point in the history
Fix timing out querying proof in 1:N in presence of a broken Poet (#5943)
  • Loading branch information
poszu committed May 23, 2024
2 parents 52b57e7 + efdd848 commit ddad968
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

See [RELEASE](./RELEASE.md) for workflow instructions.

## Release v1.5.6

### Improvements

* [#5943](https://github.com/spacemeshos/go-spacemesh/pull/5943) Fix timing out querying proof in 1:N in a presence of a broken Poet.

Previously, every identitiy waited for the full timeout time (~20 minutes) before giving up.

## Release v1.5.5

### Improvements
Expand Down
5 changes: 3 additions & 2 deletions activation/poet.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ func (c *PoetClient) Submit(
}

func (c *PoetClient) Proof(ctx context.Context, roundID string) (*types.PoetProof, []types.Hash32, error) {
getProofsCtx, cancel := withConditionalTimeout(ctx, c.requestTimeout)
defer cancel()

c.gettingProof.Lock()
defer c.gettingProof.Unlock()

Expand All @@ -363,8 +366,6 @@ func (c *PoetClient) Proof(ctx context.Context, roundID string) (*types.PoetProo
c.logger.Warn("cached members found but proof not found in db", zap.String("round_id", roundID), zap.Error(err))
}

getProofsCtx, cancel := withConditionalTimeout(ctx, c.requestTimeout)
defer cancel()
proof, members, err := c.client.Proof(getProofsCtx, roundID)
if err != nil {
return nil, nil, fmt.Errorf("getting proof: %w", err)
Expand Down
34 changes: 34 additions & 0 deletions activation/poet_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,37 @@ func TestPoetClient_CachesProof(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(2), proofsCalled.Load())
}

func TestPoetClient_QueryProofTimeout(t *testing.T) {
t.Parallel()

block := make(chan struct{})
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
<-block
}))
defer ts.Close()
defer close(block)

server := types.PoetServer{
Address: ts.URL,
Pubkey: types.NewBase64Enc([]byte("pubkey")),
}
cfg := PoetConfig{
RequestTimeout: time.Millisecond * 100,
}
poet, err := newPoetClient(nil, server, cfg, zaptest.NewLogger(t))
require.NoError(t, err)
poet.client.client.HTTPClient = ts.Client()

start := time.Now()
eg := errgroup.Group{}
for range 50 {
eg.Go(func() error {
_, _, err := poet.Proof(context.Background(), "1")
require.ErrorIs(t, err, context.DeadlineExceeded)
return nil
})
}
eg.Wait()
require.WithinDuration(t, start.Add(cfg.RequestTimeout), time.Now(), time.Millisecond*300)
}

0 comments on commit ddad968

Please sign in to comment.