Skip to main content

Unit Tests Ruff

Layer Values Monitor

A monitoring system that listens to new_report and aggregate_report events on Layer. New_report values are compared aginst trusted values and can be automatically disputed/alerted about through a discord webhook. Aggregate_report values are compared against trusted values and the related data feed contract can be paused.

NOTE: All preset thresholds are arbitrary and should be carefully considered.

Quick Start

1. Install Dependencies

Install uv package manager

https://docs.astral.sh/uv/#installation

Create and activate virtual environment

uv venv
# https://docs.astral.sh/uv/reference/cli/#uv-venv

2. Configure Environment

# Copy example environment file
cp env.example .env

# Edit .env file with your settings
nano .env

# OPTIONAL BUT RECOMMENDED: edit all config thresholds
nano config.toml

3. Run the Monitor

# Basic monitoring 
uv run layer-values-monitor --use-custom-config

Env Configuration

Required Environment Variables

Variable Description Example
URI Layer node WebSocket endpoint localhost:26657
CHAIN_ID Layer chain identifier layertest-4
DISCORD_WEBHOOK_URL_1 Discord notifications webhook 1 (none)
MAX_TABLE_ROWS Maximum rows in reports tables 1000000

Optional Environment Variables

For lighter startup commands, set these in .env:

Variable Description Default
LAYER_BINARY_PATH Path to Layer executable /usr/local/bin/layerd
LAYER_KEY_NAME Key name for transactions alice
LAYER_KEYRING_BACKEND Keyring backend type test
LAYER_KEYRING_DIR Keyring directory ~/.layer
PAYFROM_BOND Pay dispute fees from bond false
TRBBRIDGE_CONTRACT_ADDRESS TRB Bridge contract address (none)
TRBBRIDGE_CHAIN_ID Chain ID for bridge contract (default sepolia) 11155111
ETHEREUM_RPC_URL Ethereum RPC endpoint (for TRB Bridge) (none)
SAGA_EVM_RPC_URL Saga EVM RPC endpoint (none)
SAGA_PRIVATE_KEY Guardian private key (none)
SAGA_IMMEDIATE_PAUSE_THRESHOLD Power threshold for immediate pause 0.666666666666
SAGA_DELAYED_PAUSE_THRESHOLD Power threshold for delayed pause 0.333333333333
MAX_CATCHUP_BLOCKS Max blocks to process when catching up 15
CG_API_KEY CoinGecko API key for price data (none)
CMC_API_KEY CoinMarketCap API key for price data (none)

Command Line Options

Basic Usage

uv run layer-values-monitor [options]

Available Flags

Flag Description
--use-custom-config Use config.toml for query-specific settings
--enable-saga-guard Enable aggregate report and Saga contract guarding
--payfrom-bond Pay dispute fees from reporter bond, defaults to false

Global Thresholds

Set global dispute thresholds for all queries.

NOTE: If you do not want to auto dispute a certain queryId or queryType, set all threshold values to 0 for it in config.toml.

Flag Description Default
--global-percentage-alert-threshold Percentage threshold for alerts 0.1
--global-percentage-warning-threshold Warning dispute threshold 0.0
--global-percentage-minor-threshold Minor dispute threshold 0.0
--global-percentage-major-threshold Major dispute threshold 0.0
--global-range-...-threshold Range-based thresholds 0.0
--global-equality-...-threshold Equality thresholds 0.0

Configuration Strategies

Strategy 1: Full Configuration (Recommended)

Set all configuration in .env and config.toml:

uv run layer-values-monitor --use-custom-config

Strategy 2: Custom config, no optional env fields

Use custom thresholds and more command line parameters:

uv run layer-values-monitor /path/to/layerd alice test ~/.layer --payfrom-bond --use-custom-config

Strategy 3: Minimum .env setting, set thresholds in start command

Set everything via command line:

uv run layer-values-monitor \
  /path/to/layerd \
  alice \
  test \
  ~/.layer/alice \
  --payfrom-bond \
  --global-percentage-alert-threshold 0.1 \
  --global-percentage-warning-threshold 0.2 \
  --global-percentage-minor-threshold 0.4 \
  --global-percentage-major-threshold 0.6 \
  --global-range-alert-threshold 1.0 \
  --global-range-warning-threshold 1.0 \
  --global-range-minor-threshold 0 \
  --global-range-major-threshold 0 \
  --global-equality-alert-threshold 1.0 \
  --global-equality-warning-threshold 1.0 \
  --global-equality-minor-threshold 0 \
  --global-equality-major-threshold 0

Strategy 4: Global + Custom

Combine global thresholds with query-specific overrides:

uv run layer-values-monitor \
  --global-percentage-warning-threshold 0.05 \
  --use-custom-config

Query-Specific Configuration (config.toml)

# Example: BTC/USD price feed monitoring
[a6f013ee236804827b77696d350e9f0ac3e879328f2a3021d473a0b778ad78ac]
metric = "percentage"
alert_threshold = 0.05     # 5% deviation for alerts
warning_threshold = 0.10   # 10% for warning disputes
minor_threshold = 0.15     # 15% for minor disputes  
major_threshold = 0.25     # 25% for major disputes
pause_threshold = 0.50     # 50% triggers contract pause if --enable-saga-guard used
datafeed_ca = "0x9fe237b245466A5f088AfE808b27c1305E3027BC" # saga contract address

# Example: Exact equality check
[trbbridge]
metric = "equality"
alert_threshold = 1.0 # any difference triggers alert
warning_threshold = 1.0 # any difference triggers warning dispute
minor_threshold = 0.0
major_threshold = 0.0

Saga Guard

Enable automatic contract pausing when aggregate report values are incorrect. Threshold for incorrect can be set in config.toml. Only relevant for contract guardians.

Thresholds for pausing given % differences and minimum aggregate report powers configurable in config.toml

Requirements

  • Guardian permissions on target contracts
  • Valid SAGA_EVM_RPC_URL and SAGA_PRIVATE_KEY
  • Use --enable-saga-guard flag in start command

How It Works

  1. Listen for aggregate report events
  2. Compare aggregate value against trusted data sources
  3. If pause_threshold exceeded, pause configured contracts

Power-Based Pausing Logic

The system uses two power thresholds for contract pausing:

  • Immediate Pause: When aggregate report power exceeds SAGA_IMMEDIATE_PAUSE_THRESHOLD (default: 66% of total non-jailed reporting power)
  • Delayed Pause: When aggregate report power exceeds SAGA_DELAYED_PAUSE_THRESHOLD (default: 33% of total non-jailed reporting power)

Catch-Up Configuration

If the websocket disconnects/reconnects, it can process missed blocks:

  • MAX_CATCHUP_BLOCKS: Maximum number of blocks to process during catch-up (default: 15)
  • Prevents processing too many historical blocks on startup

Examples

Basic Report Monitoring

# New report monitoring with 5% auto alert threshold
# no auto disputes on spot prices
uv run layer-values-monitor \
  --global-percentage-alert-threshold 0.1 \
  --global-percentage-warning-threshold 0.0 \
  --global-percentage-minor-threshold 0.0 \
  --global-percentage-major-threshold 0.0 \

Production Setup with Saga Guard

# New report and aggregate report monitoring using config thresholds
uv run layer-values-monitor \
  --enable-saga-guard \
  --use-custom-config

Development

Run Tests

uv run pytest -v

Build Package

uv build

Linting

uv run ruff check
uv run ruff format

Logs

  • Console: INFO level and above
  • File: All logs saved to monitor_log.log
  • CSV Data: Report details saved to logs/table_*.csv

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

layer_values_monitor-0.1.5.tar.gz (132.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

layer_values_monitor-0.1.5-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file layer_values_monitor-0.1.5.tar.gz.

File metadata

  • Download URL: layer_values_monitor-0.1.5.tar.gz
  • Upload date:
  • Size: 132.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for layer_values_monitor-0.1.5.tar.gz
Algorithm Hash digest
SHA256 fd1bf89f780e73744cddccc787aa3cc1c6676937e875eeebd99e1e1a1aa43d34
MD5 1aab793d973aa72984d1a512de191b4f
BLAKE2b-256 e4d49a3ddf0126c45a398e901c144a1f466caae5cdd4c86d2f7be39138f0f4db

See more details on using hashes here.

Provenance

The following attestation bundles were made for layer_values_monitor-0.1.5.tar.gz:

Publisher: release.yml on tellor-io/layer-values-monitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file layer_values_monitor-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for layer_values_monitor-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d74c33afe6d45467eff1f6097c14aadf742485727609a4843383d6b71074d18e
MD5 289e117e3d2e81d97cb4993d4122ab0f
BLAKE2b-256 2414923c4c265be210a89c6c1f242077858dbe8406d2cb3339ceecb545dbd693

See more details on using hashes here.

Provenance

The following attestation bundles were made for layer_values_monitor-0.1.5-py3-none-any.whl:

Publisher: release.yml on tellor-io/layer-values-monitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page