Skip to content

Commit

Permalink
Fix timing out querying proof in 1:N in presence of a broken Poet (#5943
Browse files Browse the repository at this point in the history
)

## Motivation
  • Loading branch information
poszu committed May 16, 2024
1 parent f2770a4 commit 14dbf72
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ through v1.5.x first ([#5907](https://github.com/spacemeshos/go-spacemesh/pull/5

* [#5932](https://github.com/spacemeshos/go-spacemesh/pull/5932) Fix caching malfeasance when processing new proofs

* [#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.

## (v1.5.0)

### Upgrade information
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 @@ -361,8 +364,6 @@ func (c *PoetClient) Proof(ctx context.Context, roundID string) (*types.PoetProo
}
}

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 14dbf72

Please sign in to comment.