Macros: Other: Block Reorgs - FlipsideCrypto/fsc-evm GitHub Wiki

The following macros are intended to be used to create and maintain various models. These macros can be accessed via version >=vx.y.z of the fsc-evm package. Please see the fsc-evm installation instructions in the README for more details on how to access and utilize this macro effectively.


block_reorg

Usage

This macro is used to handle blockchain reorganizations (reorgs) by deleting records from specified models that are no longer valid due to a block reorg event. The query iterates through the provided list of models and deletes records that were inserted within the specified time frame (last hours) and do not have corresponding entries in the silver__transactions table. This helps maintain data accuracy and integrity for finalized blocks.

It is designed to be used in conjunction with a GitHub Actions workflow that identifies the models to be processed and executes the macro. The GitHub Actions workflow automatically generates the list of models to be processed based on tags and model names, then passes this list to the macro along with the specified number of hours to look back.

fsc_utils.block_reorg

Parameters

Parameter Type Default Description
reorg_model_list string - A comma-separated list of model names to be processed for reorg
hours integer - The number of hours to look back for potential reorg occurrences

Example

In a DBT Model:

{{ fsc_utils.block_reorg(
    reorg_model_list='model1,model2,model3',
    hours=12
) }}

In a Github Actions Workflow: .github/workflows/dbt_run_operation_reorg.yml

Note: you must update the <blockchain>_models line to reflect the repo that the workflow is executing within.

- name: List reorg models
  id: list_models
  run: |
    reorg_model_list=$(dbt list --select "<blockchain>_models,tag:reorg" --resource-type model --output name | grep '__' | awk -F'.' '{print $NF}' | tr '\n' ',' | sed 's/,$//')
    echo "model_list=$reorg_model_list" >> $GITHUB_OUTPUT

- name: Execute block_reorg macro
  run: |
    dbt run-operation fsc_utils.block_reorg --args "{reorg_model_list: '${{ steps.list_models.outputs.model_list }}', hours: '12'}" && awk '/SQL status/ {print; next} /DELETE FROM/{getline; print} /\/\* {/ {print}' logs/dbt.log
⚠️ **GitHub.com Fallback** ⚠️