Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

enhancement: don't allow missing blocks #1349

Merged
merged 29 commits into from
Sep 21, 2023
Merged

Conversation

lostman
Copy link
Contributor

@lostman lostman commented Sep 13, 2023

Description

Closes #1150.

This branch is built on top of #1337 and will be merged after.

Testing steps

We don't have any means to check the indexer's status—whether it is running or terminated with an error code, etc.

The database trigger can be observed in manual testing by adding something like this to executor.rs:

diff --git a/packages/fuel-indexer/src/executor.rs b/packages/fuel-indexer/src/executor.rs
index d771ef79..75dc9bad 100644
--- a/packages/fuel-indexer/src/executor.rs
+++ b/packages/fuel-indexer/src/executor.rs
@@ -142,7 +142,7 @@ pub fn run_executor<T: 'static + Executor + Send + Sync>(
             }
 
             // Fetch the next page of blocks, and the starting cursor for the subsequent page
-            let (block_info, next_cursor, _has_next_page) =
+            let (mut block_info, next_cursor, _has_next_page) =
                 match retrieve_blocks_from_node(
                     &client,
                     node_block_page_size,
@@ -180,6 +180,10 @@ pub fn run_executor<T: 'static + Executor + Send + Sync>(
                 continue;
             }
 
+            if block_info.len() > 10 {
+                block_info.remove(5);
+            }
+
             // The client responded with actual blocks, so attempt to index them.
             let result = executor.handle_events(block_info).await;
 

Then, running the indexer:

cargo run -p fuel-indexer -- run --fuel-node-host beta-4.fuel.network --fuel-node-port 80 --replace-indexer --run-migrations --manifest examples/fuel-explorer/fuel-explorer/fuel_explorer.manifest.yaml --remove-data

Should produce:

2023-09-13T13:00:04.812050Z ERROR fuel_indexer::ffi: 229: Failed to put_object: Error from sqlx: Database(
    PgDatabaseError {
        severity: Error,
        code: "P0001",
        message: "fuellabs_explorer.indexmetadataentity: attempted to insert value with block_height = 7 while last indexed block_height = 5. block_height values must be consecutive.",
        detail: None,
        hint: None,
        position: None,
        where: Some(
            "PL/pgSQL function ensure_block_height_consecutive() line 8 at RAISE",
        ),
        schema: None,
        table: None,
        column: None,
        data_type: None,
        constraint: None,
        file: Some(
            "pl_exec.c",
        ),
        line: Some(
            3907,
        ),
        routine: Some(
            "exec_stmt_raise",
        ),
    },
)
2023-09-13T13:00:04.812915Z ERROR fuel_indexer::executor: 892: Indexer(fuellabs.explorer) WASM execution failed: Some blocks are missing.
2023-09-13T13:00:04.813305Z ERROR fuel_indexer::executor: 199: Indexer(fuellabs.explorer) terminating due to missing blocks.

CI testing

I have added a test case that simulates missing a block by deleting a row from indexmetadataentity. The expected output is:

running 1 test
test indexing::test_no_missing_blocks ... Sep 13 17:57:02.183 ERROR fuel_indexer::ffi: Failed to put_object: Error from sqlx: Database(
    PgDatabaseError {
        severity: Error,
        code: "P0001",
        message: "fuel_indexer_test_index1.indexmetadataentity: attempted to insert value with block_height = 4 while last indexed block_height = 2. block_height values must be consecutive.",
        detail: None,
        hint: None,
        position: None,
        where: Some(
            "PL/pgSQL function ensure_block_height_consecutive() line 8 at RAISE",
        ),
        schema: None,
        table: None,
        column: None,
        data_type: None,
        constraint: None,
        file: Some(
            "pl_exec.c",
        ),
        line: Some(
            3907,
        ),
        routine: Some(
            "exec_stmt_raise",
        ),
    },
)
Sep 13 17:57:02.185 ERROR fuel_indexer::executor: Indexer(fuel_indexer_test.index1) WASM execution failed: Some blocks are missing.
Sep 13 17:57:02.185 ERROR fuel_indexer::executor: Indexer(fuel_indexer_test.index1) terminating due to missing blocks.
ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 42 filtered out; finished in 22.65s

Since missing blocks are not recoverable in the executor loop, it terminates without retries.

Changelog

  • add: database trigger to indexmetadataentity table that ensures indexed blocks must be consecutive.
  • add: MissingBlocks error code for WASM indexers returned when the database operation fails due to the exception raised by the trigger.
  • change: adjust get_start_block to return last + 1 instead of last to avoid processing the same block twice (and thus triggering an exception).
  • change: last_block_height_for_an_indexer now returns 0 if the indexer processed no blocks.

@lostman lostman changed the base branch from develop to maciej/wasm-error-codes September 13, 2023 12:27
@lostman lostman force-pushed the maciej/1150-no-missing-blocks branch from 6397703 to 4faa027 Compare September 13, 2023 13:41
@lostman lostman force-pushed the maciej/1150-no-missing-blocks branch from fff1861 to 61f4850 Compare September 15, 2023 15:48
Base automatically changed from maciej/wasm-error-codes to develop September 15, 2023 18:31
@lostman lostman marked this pull request as ready for review September 18, 2023 12:46
Copy link
Contributor

@ra0x3 ra0x3 left a comment

Choose a reason for hiding this comment

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

@lostman

  • Looks mostly OK
  • Left some small pieces of feedback

packages/fuel-indexer-schema/src/db/tables.rs Outdated Show resolved Hide resolved
packages/fuel-indexer/src/service.rs Show resolved Hide resolved
@lostman lostman requested a review from ra0x3 September 19, 2023 16:29
Copy link
Contributor

@ra0x3 ra0x3 left a comment

Choose a reason for hiding this comment

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

utACK ✅

@lostman lostman merged commit abb8abf into develop Sep 21, 2023
18 checks passed
@lostman lostman deleted the maciej/1150-no-missing-blocks branch September 21, 2023 14:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't allow the service to miss blocks
3 participants