Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create MultiNode Adaptor #7

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open

Conversation

DylanTinianov
Copy link
Contributor

@DylanTinianov DylanTinianov commented Jan 10, 2025

Description

Ticket: https://smartcontract-it.atlassian.net/browse/BCFR-1071

Most of the code in the Solana MultiNodeClient can be reused by all chain integrations. This PR extracts all of the chain-agnostic client code through making a generic MultiNodeAdaptor. This will further extract functionality into the MultiNode and reduce new integration cost.

Generic MultiNodeAdaptor:

type MultiNodeAdaptor[HEAD Head] struct {
	cfg         *mnCfg.MultiNodeConfig
	stateMu     sync.RWMutex // protects state* fields
	subsSliceMu sync.RWMutex
	subs        map[Subscription]struct{}
    chStopInFlight chan struct{}
	chainInfoLock sync.RWMutex
	highestUserObservations ChainInfo
	latestChainInfo ChainInfo
	
	// chain-specific functions will be passed in
	latestBlock          func(ctx context.Context) (HEAD, error)
	latestFinalizedBlock func(ctx context.Context) (HEAD, error)
}

The the following methods can all be chain-agnostic and extracted:

RegisterSub(sub Subscription, stopInFLightCh chan struct{}) 
LatestBlock(ctx context.Context) (HEAD, error) 
LatestFinalizedBlock(ctx context.Context) (HEAD, error) 
SubscribeToHeads
SubscribeToFinalizedHeads
OnNewHead
OnNewFinalizedHead
AcquireQueryCtx
UnsubscribeAllExcept
Close
GetInterceptedChainInfo

All other client methods will still be implemented on the chain specific side including:

Dial(ctx context.Context) error 
IsSyncing()
Ping(ctx context.Context) 
SendTxResult

@DylanTinianov DylanTinianov self-assigned this Jan 10, 2025
@DylanTinianov DylanTinianov marked this pull request as ready for review January 10, 2025 21:06
@DylanTinianov DylanTinianov requested a review from a team as a code owner January 10, 2025 21:06
@DylanTinianov DylanTinianov force-pushed the BCFR-1071-multinode-adaptor branch from 988f9b2 to cfbc9d2 Compare January 10, 2025 22:31
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter_test.go Show resolved Hide resolved
multinode/adapter_test.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
multinode/adapter.go Outdated Show resolved Hide resolved
lifeCycleMu sync.RWMutex
lifeCycleCh chan struct{}

chainInfoLock sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this mutex protect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both ChainInfo structs below it (highestUserObservations and latestChainInfo)

Copy link
Contributor

Choose a reason for hiding this comment

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

Would you think it makes sense to spell it explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How so?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now, it might seem (unless you read the code) that chainInfoLock might only protect latestChainInfo. So, I think spelling out the protected fields explicitly would help here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated and prefixed both fields with chainInfo

Copy link
Contributor

Choose a reason for hiding this comment

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

The type is already there (ChainInfo), so I don't think the prefix is necessary - you can just comment that they are both protected by chainInfoLock.

multinode/adapter.go Outdated Show resolved Hide resolved
@pavel-raykov
Copy link
Contributor

Adaptor

Sorry, the naming seems strange - the Adapter pattern (https://refactoring.guru/design-patterns/adapter) usually helps to convert one interface to another; in this case, however, this functionality seems more like a common part - may be a "SubscriberManager"?

@DylanTinianov
Copy link
Contributor Author

DylanTinianov commented Jan 29, 2025

Adaptor

Sorry, the naming seems strange - the Adapter pattern (refactoring.guru/design-patterns/adapter) usually helps to convert one interface to another; in this case, however, this functionality seems more like a common part - may be a "SubscriberManager"?

This component adapts chain-specific client interfaces to the RPCClient interface used by MultiNode. I think the name makes sense here for the use case. I don't feel like "SubscriberManager" really describes what this component is used for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants