go-spacemesh icon indicating copy to clipboard operation
go-spacemesh copied to clipboard

Change poet client to cache the full response of the `v1/info`

Open fasmat opened this issue 6 months ago • 2 comments

Description

From a discussion on PR #6116: https://github.com/spacemeshos/go-spacemesh/pull/6116#discussion_r1706623480

The whole info response should be cached instead of just the types.CertifierInfo field of the response.

Affected code

The poet client already caches part of the response returned from the v1/info endpoint via these two methods:

https://github.com/spacemeshos/go-spacemesh/blob/15ebc7b1881eaba3c6ac5f6c8a03126a2df10fc0/activation/poet.go#L618-L641

This should be changed so that the whole response is cached:

func (c *poetService) getInfo(ctx context.Context) (*types.PoetInfo, error) {
	info, err := c.infoCache.get(func() (*types.PoetInfo, error) {
		info, err := c.client.Info(ctx)
		if err != nil {
			return nil, fmt.Errorf("getting info: %w", err)
		}
		return info, nil
	})
	if err != nil {
		return nil, err
	}
	return info, nil
}

simplifying verifyPhaseShiftConfiguration to the following:

func (c *poetService) verifyPhaseShiftConfiguration(ctx context.Context) error {
	info, err := c.getInfo(ctx)
	if err != nil {
		return err
	}

	if info.PhaseShift != c.expectedPhaseShift {
		return ErrIncompatiblePhaseShift
	}

	return nil
}

fasmat avatar Aug 07 '24 09:08 fasmat