{"record":{"id":"90c18ecece932948","repo":"nautechsystems/nautilus_trader","slug":"failed-to-sync-blocks-e","errorCode":null,"errorMessage":"Failed to sync blocks: {e}","messagePattern":"Failed to sync blocks: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/blockchain/sync.rs","lineNumber":157,"sourceCode":"        database.username,\n        database.password,\n        database.database,\n    );\n    let config = BlockchainDataClientConfig::builder()\n        .chain(chain.clone())\n        .http_rpc_url(String::new().into()) // we dont need to http rpc url for block syncing\n        .use_hypersync_for_live_data(true)\n        .postgres_cache_database_config(postgres_connect_options)\n        .build();\n    let cancellation_token = tokio_util::sync::CancellationToken::new();\n    let mut data_client = BlockchainDataClientCore::new(config, None, None, cancellation_token);\n    data_client.initialize_cache_database().await;\n\n    data_client.cache.initialize_chain().await;\n    data_client\n        .sync_blocks_checked(from_block, to_block)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to sync blocks: {e}\"))?;\n\n    Ok(())\n}\n","sourceCodeStart":139,"sourceCodeEnd":161,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/cli/src/blockchain/sync.rs#L139-L161","documentation":"Wraps errors from `data_client.sync_blocks_checked(from_block, to_block)` in `run_sync_blocks`. After chain initialization, the CLI backfills blocks through the node RPC with consistency checks, and any RPC failure, missing block data, database write failure, or consistency-check violation is reported under this message. The command then aborts.","triggerScenarios":"Running `nautilus blockchain sync blocks` when the node RPC fails mid-range, the requested from/to block range exceeds provider limits or pruned history, the node returns inconsistent data failing the checked sync, or the Postgres/cache write path fails.","commonSituations":"Requesting very old blocks from a full (non-archive) node that has pruned state; syncing a huge range in one shot against a rate-limited endpoint; Postgres down or disk full during backfill; node restarting or reorging while the sync is running.","solutions":["Point at an archive node if syncing blocks older than the node's retained history.","Reduce the range via explicit --from-block/--to-block and sync in batches, resuming from the last successful block.","Retry after transient RPC/network errors; verify node health and sync status first.","Check Postgres/cache database connectivity, credentials, and disk space.","Enable debug logging to read the inner `{e}` and address the specific failing call."],"exampleFix":"// before\nnautilus blockchain sync blocks --chain ethereum   # full 0..latest against rate-limited RPC\n// after\nnautilus blockchain sync blocks --chain ethereum --from-block 18000000 --to-block 18001000","handlingStrategy":"retry","validationCode":"// ensure the node can serve the requested range\nlet latest = eth_client.block_number().await?;\nlet earliest = eth_client.get_block_by_number(1).await.is_ok();\nif !earliest { eprintln!(\"node lacks historical state; use an archive node\"); }","typeGuard":null,"tryCatchPattern":"match data_client.sync_blocks_checked(from_block, to_block).await {\n    Ok(()) => info!(\"block sync complete\"),\n    Err(e) if is_transient(&e) => { eprintln!(\"transient RPC error, retrying: {e:#}\"); }\n    Err(e) => { eprintln!(\"block sync failed: {e:#}; narrow --from-block/--to-block and retry\"); }\n}","preventionTips":["Use an archive node for blocks older than recent history.","Sync in bounded block batches instead of one giant range.","Verify node sync status before starting.","Ensure Postgres has capacity for the block volume.","Persist progress so failed syncs resume from the last synced block."],"tags":["cli","blockchain","network","rpc","database"],"backgroundTag":"network-request-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}