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

feat: Migrate to NEAR Lake #326

Merged
merged 44 commits into from
Dec 14, 2022
Merged

feat: Migrate to NEAR Lake #326

merged 44 commits into from
Dec 14, 2022

Conversation

morgsmccauley
Copy link
Contributor

@morgsmccauley morgsmccauley commented Dec 9, 2022

This PR migrates the core indexing functionality to near-lake-framework by merging in the khorolets/near-indexer-for-explorer fork. Because the two branches have diverged, leading to many conflicts, it was easier to merge the fork in to a local branch, rather than creating a pull request from the fork directly.

We are in the process of phasing out the live nearcore based indexer-for-explorers, replacing them with this lake fork, which makes this a good time to merge this back in. I've pushed the current master to master-nearcore so that the previous state is still available to build in case we need it, can someone with admin access please make this branch protected?

The code is mostly identical to khorolets/near-indexer-for-explorer:master-lake, I've commented inline where things differ.

khorolets and others added 27 commits February 20, 2022 13:14
* refactor: Upgrade to NEAR Lake Framework 0.5.1

* remove .buildkite, add GH Actions workflows, drop redis requirement, fix clippy warnings

* change the version to be relative to the original indexer-for-explorer
* Update test.yml

* update rust version

* update ubuntu version in the workflows

* add libpq-dev to cross Dockerfile
* fix: Avoid recreating access key on transfer to implicit account

* refactor: Remove `AccountDeletion` logic as its also covered by `AccessKeyDeletion`

* chore: Update `CHANGELOG.md`

* refactor: use `near_lake_framework` types rather than `near_primitives`
* build: Create Cargo workspace and empty `indexer` crate

* build: Migrate crate root to workspaces
refactor: Extract database logic to library crate
… JSON RPC (#10)

* feat: Add empty `circulating_supply` crate

* feat: Add missing db adapaters/models to `database` lib

* feat: Add core circulating supply files

* refactor: Flatten/merge `circulating_supply` files

* fix: Add missing dependencies and fix broken imports

Excluding `near-indexer` and `near-client` as these will be replaced

* refactor: Make in-use circulating_supply functions public

* refactor: Replace `near_indexer::near_primitives` with `near_lake_framework::near_indexer_primitives`

* refactor: Instantiate pg pool in `main`

* refactor: Replace `ViewClient` calls with `JsonRpcClient`

* refactor: `await` circulating_supply in `main`

* chore: Rename `tracing` target `aggregated` -> `circulating_supply`

* refactor: Extract json rpc url to environment variable

* feat: Subscribe to tracing events via `RUST_LOG` env

* feat: Improve logging

* refactor: Replace `near-indexer-framework` with `near-indexer-primtives`

* fix: Base64 decode lockup state before deserializing

* feat: Print `anyhow` errors with cause

* chore: Add note to ensure API use is updated when upgrading near-core

* chore: Use kebab case for workspace crate
* chore: Update `indexer` to `10.2`

* chore: Update `indexer` to `10.3`
* chore: Move `migrations` to same dir as `Diesel.toml`

* chore: Remove unnecessary `.gitkeep`

* feat: Add missing Diesel migrations

* chore: Update `README.md` for running migrations
* feat: Enable JSON logging via environment variable

* chore: Update CHANGELOG & Cargo version
* refactor: Move indexer stream to separate thread

* feat: Standup HTTP server

* fix: Ensure lake `ReceiverStream` finishes when process exits

* feat: Serve block metrics via http

* refactor: Rename `HTTP_PORT` -> `PORT`

* chore: Update `CHANGELOG.md` and Cargo version

* refactor: Rename block metrics for clarity
* refactor: Parse `port` via CLI and env rather than just env

* refactor: Return `anyhow::Result` from `metrics::init_server`
Copy link
Member

@khorolets khorolets left a comment

Choose a reason for hiding this comment

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

I am approving this PR to avoid blocking it, though I'd wait for @telezhnaya inputs before merging.

Also, I want to draw everybody's attention to questions:

  1. Should we drop the Buildkite jobs since we can run checks via GitHub Actions and we're not going to build binaries with Buildkite anymore? (@ecp88 , @frol )
  2. Is FOSSA still a thing and we should add its check to GH Actions?
    ( @ecp88, @pkudinov )
  3. Is it worth switching to [tokio::main] instead of [actix::main]? (@telezhnaya , @frol )

@frol
Copy link
Contributor

frol commented Dec 12, 2022

Should we drop the Buildkite jobs since we can run checks via GitHub Actions and we're not going to build binaries with Buildkite anymore?

I don't know about the plans regarding Buildkite, but I would personally prefer Github Actions. Make your own judgement here.

Is it worth switching to [tokio::main] instead of [actix::main]?

I would say it is a low-priority, and should only be done after the upgrade to near-lake-framework 0.6+ (after nearcore dependencies are upgraded to 0.15+ versions, which dropped actix as their leaf dependency), also, you will need to replace actix-diesel with tokio-diesel. Yet, after all of that the only observable benefits I can see are: (1) faster cold compilation, so expect some speed up on CI; (2) lower maintenance burden as actix used to cause some complications and we have to use a forked version fo actix-diesel now.

Copy link
Contributor

@telezhnaya telezhnaya left a comment

Choose a reason for hiding this comment

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

Amazing work, thank you @morgsmccauley !

By the way, you've already migrated all the FT/NFT logic, as I see. We discussed that we need to keep the old indexer (node based) to collect FT/NFT stuff, but you've done everything we need, so we can kill the old instances, no blockers here from my side.
cc @khorolets

database/src/models/serializers.rs Show resolved Hide resolved
database/src/retriable.rs Outdated Show resolved Hide resolved
indexer/src/configs.rs Outdated Show resolved Hide resolved
indexer/src/configs.rs Show resolved Hide resolved
indexer/src/configs.rs Show resolved Hide resolved
indexer/src/main.rs Show resolved Hide resolved
indexer/src/main.rs Show resolved Hide resolved
let config: near_lake_framework::LakeConfig = opts.to_lake_config().await;
let (_, stream) = near_lake_framework::streamer(config);

tokio::spawn(async move {
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I right that we use actix only because of diesel?
Anyway, I'm with @khorolets , let's use [tokio::main]

indexer/src/main.rs Outdated Show resolved Hide resolved
@morgsmccauley
Copy link
Contributor Author

morgsmccauley commented Dec 13, 2022

Thanks heaps @telezhnaya @khorolets !!

I've addressed all comments which I could, these have been resolved.

To make things easier, I've summarised the unresolved discussions below. From the comments that @khorolets left I think the majority can be addressed in future PRs, feel free to resolve these if you agree. There are still two discussions which require decisions.

Discussion Outcome
Can we remove buildkite Needs decision
Removing 'explorer' from names Needs decision
Can we separate storing transactions/receipts Separate PR
Migrate from actix::main -> tokio::main and tokio-diesel Separate PR
Creating a single PG pool Separate PR
Clearer parameters for final_block_height Separate PR

@khorolets
Copy link
Member

@morgsmccauley morgsmccauley merged commit 5153374 into master Dec 14, 2022
@morgsmccauley morgsmccauley deleted the feat/lake-migration branch December 14, 2022 18:43
@morgsmccauley
Copy link
Contributor Author

Thanks for creating all the relevant issues @khorolets 🙏🏽

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.

5 participants