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 feature flag on account_changes and fungible_token_events #349

Merged
merged 6 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,17 @@ $ PGPASSWORD="password" psql -h 127.0.0.1 -U explorer databasename
```

## Deployments
Both `indexer-explorer` and `circulating-supply` binaries are run within Docker, their `Dockerfile`s can be found within their respective directoires/workspaces. Docker images are built using Google Cloud Build and then deployed to Google Cloud Run. The following commands can be used to build the Docker images:
Both `indexer-explorer` and `circulating-supply` binaries are run within Docker, their `Dockerfile`s can be found within their respective directories/workspaces. Docker images are built using Google Cloud Build and then deployed to Google Cloud Run. The following commands can be used to build the Docker images:

```bash
$ docker build -f ./indexer/Dockerfile .
$ docker build -f ./circulating-supply/Dockerfile .
```

## Features
telezhnaya marked this conversation as resolved.
Show resolved Hide resolved
The tables `account_changes` and `assets__fungible_token_events` can be enabled by [features](https://doc.rust-lang.org/cargo/reference/features.html) config in their `Cargo.toml`s files. Example:
telezhnaya marked this conversation as resolved.
Show resolved Hide resolved
```
[features]
default = ["account_changes"]
account_changes = []
```
4 changes: 4 additions & 0 deletions database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ actix-diesel = { git = "https://github.com/frol/actix-diesel", rev = "3a001986c8
near-indexer-primitives = "0.14"
near-primitives = "0.14"
near-crypto = "0.14"

[features]
default = []
fungible_token_events = []
8 changes: 8 additions & 0 deletions database/src/adapters/assets/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,28 @@ async fn collect_and_store_events(
shard: &near_indexer_primitives::IndexerShard,
block_timestamp: u64,
) -> anyhow::Result<()> {
#[cfg(feature = "fungible_token_events")]
let mut ft_events_with_outcomes = Vec::new();
let mut nft_events_with_outcomes = Vec::new();

for outcome in &shard.receipt_execution_outcomes {
let events = extract_events(outcome);
for event in events {
match event {
#[cfg(feature = "fungible_token_events")]
assets::event_types::NearEvent::Nep141(ft_event) => {
ft_events_with_outcomes.push((ft_event, outcome));
}
assets::event_types::NearEvent::Nep171(nft_event) => {
nft_events_with_outcomes.push((nft_event, outcome));
}
#[cfg(not(feature = "fungible_token_events"))]
_ => (),
}
}
}

#[cfg(feature = "fungible_token_events")]
let ft_future = assets::fungible_token_events::store_ft_events(
pool,
shard,
Expand All @@ -75,7 +80,10 @@ async fn collect_and_store_events(
block_timestamp,
&nft_events_with_outcomes,
);
#[cfg(feature = "fungible_token_events")]
futures::try_join!(ft_future, nft_future)?;
#[cfg(not(feature = "fungible_token_events"))]
futures::try_join!(nft_future)?;
Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ near-jsonrpc-client = "0.4.0-beta.0"
near-lake-framework = "0.5.2"

explorer-database = { path = "../database" }

[features]
default = []
account_changes = []
11 changes: 10 additions & 1 deletion indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,28 @@ async fn handle_message(
};

// StateChange related to Account
#[cfg(feature = "account_changes")]
let account_changes_future = adapters::account_changes::store_account_changes(
pool,
&streamer_message.shards,
&streamer_message.block.header.hash,
streamer_message.block.header.timestamp,
);
#[cfg(feature = "account_changes")]
try_join!(
execution_outcomes_future,
accounts_future,
access_keys_future,
assets_events_future,
account_changes_future
)?;

#[cfg(not(feature = "account_changes"))]
try_join!(
execution_outcomes_future,
accounts_future,
access_keys_future,
assets_events_future,
account_changes_future,
)?;
} else {
try_join!(
Expand Down