Skip to content

Conversation

@commoddity
Copy link
Contributor

@commoddity commoddity commented Jun 11, 2025

⚠️ Goes with PATH Changes

This PR must be reviewed in conjunction with PATH PR 297:
pokt-network/path#297

🚨 TODO_IN_THIS_PR

Do not merge until these TODOs are resolved:

  • TODO_IN_THIS_PR(@commoddity): create a new relay_test.go file the tests the process of signing and building a relay request. - relay.go

🌿 Summary

Refactor Shannon SDK by creating GatewayClient and moving relevant code from PATH to Shannon SDK.

🌱 Primary Changes:

  • Created GatewayClient struct to handle signing and validating relays with full node integration
  • Implemented FullNode interface with caching and non-caching implementations
  • Moved account, application, and session client functionality from PATH to Shannon SDK
  • Added robust configuration and validation for full node connections

🍃 Secondary changes:

  • Removed unused queryCodec and moved codec initialization to types package
  • Updated dependencies to latest poktroll version (v0.1.20)
  • Added sturdyc for caching implementation
  • Improved documentation and logging throughout the codebase

🛠️ Type of change

Select one or more from the following:

  • New feature, functionality or library
  • Code health or cleanup

🤯 Sanity Checklist

  • I have updated the GitHub Issue 'assignees', 'reviewers', 'labels', 'project', 'iteration' and 'milestone'
  • For code, I have run 'make test_all'
  • I added TODOs where applicable

@commoddity commoddity requested a review from adshmh June 11, 2025 18:28
@Olshansk Olshansk added the enhancement New feature or request label Jun 16, 2025
@Olshansk Olshansk added this to Shannon Jun 16, 2025
@Olshansk Olshansk moved this to 👀 In review in Shannon Jun 16, 2025
@commoddity commoddity marked this pull request as ready for review June 16, 2025 21:53
@commoddity commoddity changed the title [WIP][Shannon][Refactor] Create Gateway Clients and move relevant code from PATH to Shannon SDK [Shannon][Refactor] Create GatewayClient and move relevant code from PATH to Shannon SDK Jun 16, 2025
servicetypes "github.com/pokt-network/poktroll/x/service/types"
)

// TODO_IN_THIS_PR(@commoddity): create a new `relay_test.go` file the tests the process of signing and building a relay request.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_PR(@commoddity): create a new relay_test.go file the tests the process of signing and building a relay request.

return relayRequest, nil
}

// TODO_IN_THIS_PR(@commoddity): add detailed godoc comment explaining the purpose of this struct.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_PR(@commoddity): add detailed godoc comment explaining the purpose of this struct.

sdkTypes "github.com/pokt-network/shannon-sdk/types"
)

// TODO_IN_THIS_PR(@commoddity): start a "micro readme" (just with bullet points) that captures more details about full node implementations?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_PR(@commoddity): start a "micro readme" (just with bullet points) that captures more details about full node implementations?


// GetActiveSessions retrieves active sessions for a list of app addresses and a service ID.
// It verifies that each app delegates to the gateway and is staked for the requested service.
// This method encapsulates the shared logic between centralized and delegated gateway modes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be kept: IMO the first iteration of refactor should keep Gateway Mode concept entirely on PATH.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method does not deal with anything specific to the gateway mode. I've removed the comment as it was misguided and confusing.

Please see the files protocol/shannon/client_centralized.go and protocol/shannon/client_delegated.go for details.


if err := relayResponse.ValidateBasic(); err != nil {
// Even if the relay response is invalid, return it (may contain failure reason)
return relayResponse, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define custom errors for these: the current version of SDK already has that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the gateway client file to greatly improve custom error definitions and logging of said errors.

//
// - Returns a pointer instead of directly setting the signature on the input relay request to avoid implicit output.
// - Ideally, the function should accept a struct rather than a pointer, and also return an updated struct instead of a pointer.
func (s *relaySigner) SignRelayRequest(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part looks incomplete: how is a gateway (e.g. PATH) going to call this method?
SDK needs to provide this method, e.g. on the GatewayClient, for use by PATH.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this method to be on the GatewayClient struct.

See usage of the method in PATH here:

func (rc *requestContext) signRelayRequest(ctx context.Context, unsignedRelayReq *servicetypes.RelayRequest, app apptypes.Application) (*servicetypes.RelayRequest, error) {
	// Verify the relay request's metadata, specifically the session header.
	// Note: cannot use the RelayRequest's ValidateBasic() method here, as it looks for a signature in the struct, which has not been added yet at this point.
	meta := unsignedRelayReq.GetMeta()

	if meta.GetSessionHeader() == nil {
		return nil, errors.New("signRelayRequest: relay request is missing session header")
	}

	sessionHeader := meta.GetSessionHeader()
	if err := sessionHeader.ValidateBasic(); err != nil {
		return nil, fmt.Errorf("signRelayRequest: relay request session header is invalid: %w", err)
	}

	// Sign the relay request using the selected app's private key
	return rc.gatewayClient.SignRelayRequest(ctx, unsignedRelayReq, app)
}

https://github.com/buildwithgrove/path/pull/297/files#diff-0bdde7412f8b6547614d433448da04088d05680a6ea02cbf50433d8a25e5bb9eR249

// newFullNodeWithCache wraps a fullNode with:
// - Session cache: refreshes early to avoid thundering herd/latency spikes
// - Account public key cache: indefinite cache for account data
func newFullNodeWithCache(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think fullnode* structs should be private: making them public and allowing the user (e.g. PATH) to customize any required aspect e.g. GRPC settings, makes more sense.

Also, please consider the approach of making fullnode* structs useful on their own: e.g. a reliable way of interacting with the protocol for purposes other than running a gateway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been changed as part of the GatewayClientCache changes.

Everything is configurable through the config structs; please let me know if you think things should be more configurable than they are now and in which ways.

Copy link
Contributor

@adshmh adshmh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, this is a good start for the refactoring work.
Please consider making things less monolithic and more configurable, with reasonable default values/behavior.

@commoddity
Copy link
Contributor Author

commoddity commented Jun 18, 2025

Thank you for the PR, this is a good start for the refactoring work. Please consider making things less monolithic and more configurable, with reasonable default values/behavior.

@adshmh I've thought a bit about your feedback and implemented some changes.

The main one being the renaming of the "lazy" full node into a GRPCClient which is passed to a GatewayClientCache. I believe this change better clarifies the exact responsibilities of each struct. I

In addition, this introduces a new public interface, the OnchainDataFetcher which is satisfied by both GRPCClient and the GatewayClientCache which wraps the GRPCClient if caching is enabled.

As always I am open to improvements in the naming of these components. 😅

As a result of this change, most comments here are outdated, but I have gone through and addressed each one individually as well.

@commoddity commoddity requested a review from adshmh June 18, 2025 19:34
)

// GRPCClient implements OnchainDataFetcher interface.
var _ OnchainDataFetcher = &GRPCClient{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[linter-name (fail-on-found)] reported by reviewdog 🐶
var _ OnchainDataFetcher = &GRPCClient{}

)

// GatewayClientCache implements OnchainDataFetcher interface.
var _ OnchainDataFetcher = &GatewayClientCache{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[linter-name (fail-on-found)] reported by reviewdog 🐶
var _ OnchainDataFetcher = &GatewayClientCache{}

@Olshansk Olshansk marked this pull request as draft September 19, 2025 00:26
@Olshansk Olshansk changed the title [Shannon][Refactor] Create GatewayClient and move relevant code from PATH to Shannon SDK [WIP][Shannon][Refactor] Create GatewayClient and move relevant code from PATH to Shannon SDK Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

4 participants