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

Add context.rpc #801

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Add context.rpc #801

wants to merge 1 commit into from

Conversation

pkudinov
Copy link
Collaborator

@pkudinov pkudinov commented Jun 12, 2024

Implements #797

It also implements a way to configure dependencies through static methods (e.g. RpcClient.fromEnv() to Indexer that I recommend to adopt.

When deploying to dev or produciton, we need to ensure that we use a Read RPC endpoint, and not simply an archival node.

@pkudinov pkudinov requested a review from a team as a code owner June 12, 2024 23:35
@pkudinov pkudinov changed the title Add RpcClient Add context.rpc Jun 12, 2024
@pkudinov pkudinov linked an issue Jun 12, 2024 that may be closed by this pull request
@pkudinov
Copy link
Collaborator Author

@morgsmccauley kindly take it over from here in case I did not wire things properly in the streamer or some other place

Copy link
Collaborator

@morgsmccauley morgsmccauley left a comment

Choose a reason for hiding this comment

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

Left a few comments :). Did you need me to pick it up from here?

describe('RPCClient unit tests', () => {
const rpcClient = RpcClient.fromConfig({
networkId: 'mainnet',
nodeUrl: 'https://beta.rpc.mainnet.near.org',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add tests which don't rely on real endpoints? I don't want unnecessary CI failures due to network failures.


rpcClient = RpcClient.fromConfig({
networkId: 'mainnet',
nodeUrl: 'https://beta.rpc.mainnet.near.org',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar comment around adding tests which don't depend on real infrastructure. This isn't being used in integration tests so I would just remove it.

@@ -96,7 +97,9 @@ async function blockQueueProducer (workerContext: WorkerContext): Promise<void>
async function blockQueueConsumer (workerContext: WorkerContext): Promise<void> {
let previousError: string = '';
const indexerConfig: IndexerConfig = workerContext.indexerConfig;
const indexer = new Indexer(indexerConfig);
const indexer = new Indexer(indexerConfig, {
rpcClient: RpcClient.fromEnv()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We typically add defaults for injected dependencies to add convenience, could you do that please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was actually proposing to not have defaults to make configuration of this class explicit with all dependencies – the number of places it is being configured in is very low. This will also be needed for the testing framework. Happy to discuss or change my opinion if defaults indeed make things more convenient.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What benefit would the explicitness provide? For me, defaults allow us to abstract the implementation away, so therefore don't need to think about it from the user side. I hadn't really considered otherwise, interested to see your side.

return new RpcClient(config);
}

static fromEnv (): IRpcClient {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, I like it :)

}

static fromEnv (): IRpcClient {
if (!process.env.RPC_URL) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (!process.env.RPC_URL) {
if (!process.env.NEAR_RPC_ENDPOINT) {

I've deployed under this environment variable, I didn't want it to be confused with the other RPC endpoints we use internally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That actually makes sense. I was thinking to actually name it 'ARCHIVAL_RPC_ENDPOINT' – do you want me to make this change in this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, I've deployed NEAR_RPC_ENDPOINT, but can update.

@@ -63,6 +63,7 @@
"express": "^4.18.2",
"graphql": "^16.8.1",
"long": "^5.2.3",
"near-api-js": "^4.0.2",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be using @near-js packages instead, so for this I think that would mean @near-js/types and @near-js/providers.

near-api-js includes much more than we need, and @near-js is more likely to be maintained going forward.


interface Dependencies {
fetch: typeof fetch
provisioner: Provisioner
dmlHandler?: DmlHandler
indexerMeta?: IndexerMeta
parser: Parser
};
rpcClient?: IRpcClient
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
rpcClient?: IRpcClient
rpcClient: IRpcClient

I'm not sure there is any reason not to include this? dmlHandler etc is only optional because we need to get DB credentials.

This would also tidy up the context generation since it would always be defined.

@pkudinov
Copy link
Collaborator Author

Left a few comments :). Did you need me to pick it up from here?

If these are all comments, I'll make necessary fixes and let you pick it up from there

@frol
Copy link

frol commented Jul 19, 2024

@pkudinov @morgsmccauley Sorry for jumping in, but I'd like to invite you to participate in the Race of Sloths - a fun and gamified open-source contributions program. Consider mentioning @race-of-sloths user in your github comment or PR description to join!

See how the flow works here: near/nearcore#11778

@pkudinov pkudinov marked this pull request as draft August 1, 2024 21:45
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.

Add context.rpc.viewCall method
3 participants