Skip to content

Commit

Permalink
Initialize nearcore correctly via environmental variables, remove obs…
Browse files Browse the repository at this point in the history
…olete log targets in fastnear
  • Loading branch information
Fly-Style committed Nov 30, 2024
1 parent e671faf commit bff2158
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
43 changes: 21 additions & 22 deletions docker-compose-fastnear.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,6 @@ services:
networks:
- nffl

nearcore-setup:
image: debian:bookworm
container_name: nearcore-setup
volumes:
- near_cli_data:/near-cli
- near_cli_keys:/root/.near-credentials
entrypoint: sh
command:
- -c
- |
rm -rf /near-cli/*
rm -rf /root/.near-credentials/*
networks:
- nffl

indexer:
image: nffl-fast-indexer:latest
container_name: nffl-indexer
Expand All @@ -165,11 +150,6 @@ services:
condition: service_healthy
mainnet-anvil-setup:
condition: service_completed_successfully
nearcore-setup:
condition: service_completed_successfully
volumes:
- near_cli_data:/root/.near
- near_cli_keys:/root/.near-credentials
expose:
- 9090 # prometheus port
command:
Expand All @@ -186,21 +166,40 @@ services:
networks:
- nffl

nearcore-setup:
image: debian:bookworm
container_name: nearcore-setup
depends_on:
indexer:
condition: service_started
volumes:
- near_cli_data:/near-cli
- near_cli_keys:/root/.near-credentials
entrypoint: sh
command:
- -c
- |
rm -rf /near-cli/*
rm -rf /root/.near-credentials/*
networks:
- nffl

nearcore:
image: nearprotocol/nearcore:2.4.0-a83c18490cf4dafaedca01458f365dc5871bd293 # The version is important
container_name: nearcore
depends_on:
nearcore-setup:
condition: service_completed_successfully
indexer:
condition: service_started
ports:
- "3030:3030"
volumes:
- near_cli_data:/root/.near
- near_cli_keys:/root/.near-credentials
environment:
- NEAR_HOME=/root/.near
- INIT=1
- CHAIN_ID=localnet
- ACCOUNT_ID=test.near
networks:
- nffl

Expand Down
3 changes: 1 addition & 2 deletions indexer/FastIndexer.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ RUN apt-get update -qq && \
g++ \
pkg-config \
libssl-dev \
wget \
llvm \
clang

Expand All @@ -31,7 +30,7 @@ FROM debian:bookworm-slim as runtime
WORKDIR /indexer-app
ARG TARGET="release"

RUN apt update && apt install -yy openssl ca-certificates jq curl
RUN apt update && apt install -yy openssl ca-certificates

COPY --from=builder /tmp/indexer/target/${TARGET}/indexer .
COPY ./indexer/entrypoint.sh ./entrypoint.sh
Expand Down
39 changes: 20 additions & 19 deletions indexer/src/fastnear_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl FastNearIndexer {
addresses_to_rollup_ids: HashMap<AccountId, u32>,
channel_width: usize,
) -> Self {
debug!(FASTNEAR_INDEXER, "Creating new FastNearIndexer");
debug!("Creating new FastNearIndexer");
Self {
fastnear_address: fastnear_address.to_string(),
client: Client::new(),
Expand All @@ -48,7 +48,7 @@ impl FastNearIndexer {
}

pub fn run(&self) -> Receiver<PublishData> {
info!(FASTNEAR_INDEXER, "Starting FastNearIndexer");
info!("Starting FastNearIndexer");
let block_receiver = self.stream_latest_blocks();
let (publish_sender, publish_receiver) = mpsc::channel(self.channel_width);

Expand All @@ -66,11 +66,11 @@ impl FastNearIndexer {
publish_sender: Sender<PublishData>,
addresses_to_rollup_ids: HashMap<AccountId, u32>,
) {
debug!(FASTNEAR_INDEXER, "Starting block processing");
debug!("Starting block processing");
while let Some(block) = block_receiver.recv().await {
trace!(FASTNEAR_INDEXER, "Received block: {:?}", block.block.header.height);
trace!("Received block: {:?}", block.block.header.height);
if let Err(e) = Self::parse_and_publish_block(block, &publish_sender, &addresses_to_rollup_ids).await {
error!(FASTNEAR_INDEXER, "Error parsing and publishing block: {:?}", e);
error!("Error parsing and publishing block: {:?}", e);
}
}
}
Expand All @@ -80,13 +80,13 @@ impl FastNearIndexer {
publish_sender: &Sender<PublishData>,
addresses_to_rollup_ids: &HashMap<AccountId, u32>,
) -> Result<(), Error> {
debug!(FASTNEAR_INDEXER, "Parsing block: {:?}", block.block.header.height);
debug!("Parsing block: {:?}", block.block.header.height);
for shard in block.shards {
for receipt_execution_outcome in shard.receipt_execution_outcomes {
let receiver_id = &receipt_execution_outcome.receipt.receiver_id;
debug!(FASTNEAR_INDEXER, "Processing receipt for receiver_id: {}", receiver_id);
debug!("Processing receipt for receiver_id: {}", receiver_id);
if let Some(rollup_id) = addresses_to_rollup_ids.get(receiver_id) {
trace!(FASTNEAR_INDEXER, "Processing receipt for rollup_id: {}", rollup_id);
trace!("Processing receipt for rollup_id: {}", rollup_id);
if !Self::is_successful_execution(&receipt_execution_outcome) {
trace!(
FASTNEAR_INDEXER,
Expand All @@ -108,7 +108,7 @@ impl FastNearIndexer {
tx_hash,
block_hash: block.block.header.hash,
};
debug!(FASTNEAR_INDEXER, "Sending candidate data for rollup_id: {}", rollup_id);
debug!("Sending candidate data for rollup_id: {}", rollup_id);
Self::send(&candidate_data, publish_sender).await?;
}
}
Expand All @@ -119,7 +119,7 @@ impl FastNearIndexer {
}

pub fn stream_latest_blocks(&self) -> mpsc::Receiver<BlockWithTxHashes> {
info!(FASTNEAR_INDEXER, "Starting block stream");
info!("Starting block stream");
let (block_sender, block_receiver) = mpsc::channel(self.channel_width);
let client = self.client.clone();
let fastnear_address = self.fastnear_address.clone();
Expand All @@ -130,15 +130,15 @@ impl FastNearIndexer {
Ok(block) => {
let block_height = block.block.header.height;
if block_sender.send(block).await.is_err() {
error!(FASTNEAR_INDEXER, "Failed to send block to channel");
error!("Failed to send block to channel");
break;
}
info!(
FASTNEAR_INDEXER,
"Successfully fetched and sent latest block with id: {}", block_height
);
}
Err(e) => error!(FASTNEAR_INDEXER, "Error fetching latest block: {:?}", e),
Err(e) => error!("Error fetching latest block: {:?}", e),
}
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
Expand All @@ -148,7 +148,7 @@ impl FastNearIndexer {
}

async fn fetch_latest_block(client: &Client, fastnear_address: &str) -> Result<BlockWithTxHashes, Error> {
debug!(FASTNEAR_INDEXER, "Fetching latest block");
debug!("Fetching latest block");
let response = client
.get(fastnear_address)
.send()
Expand All @@ -166,7 +166,7 @@ impl FastNearIndexer {
candidate_data: &PartialCandidateDataWithBlockTxHash,
sender: &Sender<PublishData>,
) -> Result<(), Error> {
trace!(FASTNEAR_INDEXER, "Sending candidate data: {:?}", candidate_data);
trace!("Sending candidate data: {:?}", candidate_data);
for data in &candidate_data.payloads {
let publish_data = PublishData {
publish_options: PublishOptions {
Expand All @@ -192,12 +192,12 @@ impl FastNearIndexer {
receipt_execution_outcome.execution_outcome.outcome.status,
ExecutionStatusView::SuccessValue(ref value) if value.is_empty()
);
trace!(FASTNEAR_INDEXER, "Execution successful: {}", is_successful);
trace!("Execution successful: {}", is_successful);
is_successful
}

fn receipt_filter_map(receipt_enum_view: ReceiptEnumView, rollup_id: u32) -> Option<PartialCandidateData> {
trace!(FASTNEAR_INDEXER, "Filtering receipt for rollup_id: {}", rollup_id);
trace!("Filtering receipt for rollup_id: {}", rollup_id);
let payloads = match receipt_enum_view {
ReceiptEnumView::Action { actions, .. } => actions
.into_iter()
Expand All @@ -207,7 +207,7 @@ impl FastNearIndexer {
};

if payloads.is_empty() {
trace!(FASTNEAR_INDEXER, "No payloads found for rollup_id: {}", rollup_id);
trace!("No payloads found for rollup_id: {}", rollup_id);
return None;
}

Expand All @@ -217,11 +217,11 @@ impl FastNearIndexer {
fn extract_args(action: ActionView) -> Option<Vec<u8>> {
match action {
ActionView::FunctionCall { method_name, args, .. } if method_name == "submit" => {
trace!(FASTNEAR_INDEXER, "Extracted args for 'submit' method");
trace!("Extracted args for 'submit' method");
Some(args.into())
}
_ => {
trace!(FASTNEAR_INDEXER, "Skipped non-'submit' method");
trace!("Skipped non-'submit' method");
None
}
}
Expand All @@ -247,6 +247,7 @@ mod tests {
#[cfg(feature = "it_tests")]
use std::collections::HashMap;

#[cfg(all(test, feature = "it_tests"))]
const FASTNEAR_DEFAULT_ENDPOINT: &str = "https://testnet.neardata.xyz/v0/last_block/final";

#[cfg(all(test, feature = "it_tests"))]
Expand Down

0 comments on commit bff2158

Please sign in to comment.