Skip to content

Commit 7527b8b

Browse files
committed
Merge branch 'andrius/param-refactoring' into 'main'
refactor: consolidate log_range and rename binary/module for v2 See merge request flarenetwork/FSP/flare-system-c-chain-indexer!83
2 parents af92be0 + 6c039a1 commit 7527b8b

28 files changed

Lines changed: 131 additions & 96 deletions

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@ and this project adheres to
4040

4141
- Repository structure refactored under `cmd/` and `internal/` to follow
4242
conventional Go layout. The runnable binary moved to `./cmd/indexer`.
43+
- **Binary renamed** to `flare-cchain-indexer` (previously
44+
`flare_cchain_indexer` in the Dockerfile / `flare-ftso-indexer` in legacy
45+
build snippets). Deployment scripts, container `command:` entries, and any
46+
process supervisors that reference the binary by name need to be updated.
47+
- **Go module path renamed** from `flare-ftso-indexer` to
48+
`github.com/flare-foundation/flare-system-c-chain-indexer`. The indexer is
49+
shipped as a binary, but any out-of-tree imports must be updated.
4350
- Block-by-timestamp lookup uses heuristics to narrow the search window before
4451
binary search, avoiding requests for very old blocks when running against
4552
RPC nodes with limited history.
53+
- Minimum Go toolchain version raised to 1.24.
4654

4755

4856
## \[[v1.1.2](https://github.com/flare-foundation/flare-system-c-chain-indexer/tree/v1.1.2)\] - 2025-11-03

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN go mod download
1111
COPY . ./
1212

1313
# Build the applications
14-
RUN go build -o /app/flare_cchain_indexer ./cmd/indexer
14+
RUN go build -o /app/flare-cchain-indexer ./cmd/indexer
1515

1616
FROM debian:trixie-slim@sha256:cedb1ef40439206b673ee8b33a46a03a0c9fa90bf3732f54704f99cb061d2c5a AS execution
1717

@@ -23,6 +23,6 @@ RUN apt-get update \
2323

2424
WORKDIR /app
2525

26-
COPY --from=builder /app/flare_cchain_indexer .
26+
COPY --from=builder /app/flare-cchain-indexer .
2727

28-
CMD ["./flare_cchain_indexer"]
28+
CMD ["./flare-cchain-indexer"]

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ docker-compose.yaml file for automatic deployment of a database).
2828

2929
### Configuration
3030

31-
The configuration is read from a `toml` file. Config file can be specified using the command line parameter `--config`, e.g., `./flare-ftso-indexer --config config.toml`.
31+
The configuration is read from a `toml` file. Config file can be specified using the command line parameter `--config`, e.g., `./flare-cchain-indexer --config config.toml`.
3232
The default config file name is `config.toml`.
3333
Use [`config.example.toml`](config.example.toml) as the single config template. It includes full mode/indexer/db/chain/logger/timeout examples and comments.
3434

@@ -37,6 +37,14 @@ Use [`config.example.toml`](config.example.toml) as the single config template.
3737
- `indexer.mode = "fsp"`: use this when running as part of the FSP provider stack. Required FSP transactions/logs are hardcoded and auto-applied, so you do not need to specify `[[indexer.collect_transactions]]` or `[[indexer.collect_logs]]` in config (you can still add extra entries; they are merged and deduplicated). FSP startup also does selective indexing for required reward-epoch metadata windows instead of blindly indexing full historical ranges, which makes startup significantly faster. In this mode, `indexer.start_index` and `db.history_drop` are ignored; retention is derived from `indexer.history_epochs`.
3838
- `indexer.mode = "full"`: use this for a generic C-chain indexer. In this mode you should define what to index via `[[indexer.collect_transactions]]` and `[[indexer.collect_logs]]`.
3939

40+
#### Contract addressing
41+
42+
Contracts in `[[indexer.collect_transactions]]` and `[[indexer.collect_logs]]` can be specified either by `contract_address = "0x..."` or by `contract_name = "FlareSystemsManager"`. When a name is provided, the indexer resolves it to an address at startup via the on-chain ContractRegistry, so addresses that differ across networks (or change between deployments) do not need to be hardcoded in config. FSP mode's built-in collectors all use name-based resolution.
43+
44+
#### Startup and history (full mode)
45+
46+
The behavior described in this section applies to **full mode** only. FSP mode derives its start block and retention from `indexer.history_epochs`, and ignores both `indexer.start_index` and `db.history_drop`.
47+
4048
If the C chain indexer has been previously run and there is existing data in the database,
4149
subsequent runs will resume indexing from after the last indexed block. Only when starting with an
4250
empty database will the indexer have to decide where to start. Normally this will be based on the
@@ -71,8 +79,8 @@ go run ./cmd/indexer --config config.toml
7179
or build and run the binaries with
7280

7381
```bash
74-
go build -o flare-ftso-indexer ./cmd/indexer
75-
./flare-ftso-indexer --config config.toml
82+
go build -o flare-cchain-indexer ./cmd/indexer
83+
./flare-cchain-indexer --config config.toml
7684
```
7785

7886
### Health endpoint
@@ -113,7 +121,7 @@ go tool cover -html=coverage.out
113121

114122
### Benchmarks
115123

116-
File `benchmarks/songbird_test.go` contains a benchmark test for indexing the FTSO protocol on the Songbird network. It processes 10,000 blocks and analyzes them. The test configuration is specified in `benchmarks/config_banchmark.toml`. To run the benchmark (replacing 10x with any desired number of repetitions), use:
124+
File `benchmarks/songbird_test.go` contains a benchmark test for indexing the FTSO protocol on the Songbird network. It processes 10,000 blocks and analyzes them. The test configuration is specified in `benchmarks/config_benchmark.toml`. To run the benchmark (replacing 10x with any desired number of repetitions), use:
117125

118126
```bash
119127
go test -benchmem -run=^$ -benchtime 10x -bench ^BenchmarkBlockRequests$ ./benchmarks
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ drop_table_at_start = true
1111

1212
[logger]
1313
level = "INFO"
14-
file = "../logs/flare-ftso-indexer_log"
14+
file = "../logs/flare-cchain-indexer.log"
1515
console = true
1616

1717
[chain]

benchmarks/songbird_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package benchmarks
22

33
import (
44
"context"
5-
"flare-ftso-indexer/internal/chain"
6-
"flare-ftso-indexer/internal/config"
7-
"flare-ftso-indexer/internal/contracts"
8-
"flare-ftso-indexer/internal/core"
9-
"flare-ftso-indexer/internal/database"
105
"testing"
116

7+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/chain"
8+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/config"
9+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/contracts"
10+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/core"
11+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/database"
12+
1213
"github.com/BurntSushi/toml"
1314
"github.com/flare-foundation/go-flare-common/pkg/logger"
1415
)
@@ -23,7 +24,7 @@ func BenchmarkBlockRequests(b *testing.B) {
2324
tCfg := benchmarksConfig{}
2425
tCfg.Indexer.Confirmations = 1
2526
tCfg.Chain.ChainType = 1
26-
_, err := toml.DecodeFile("config_banchmark.toml", &tCfg)
27+
_, err := toml.DecodeFile("config_benchmark.toml", &tCfg)
2728
if err != nil {
2829
logger.Fatalf("Config error: %s", err)
2930
}

cmd/indexer/main.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ package main
33
import (
44
"context"
55
"flag"
6-
"flare-ftso-indexer/internal/boff"
7-
"flare-ftso-indexer/internal/chain"
8-
"flare-ftso-indexer/internal/config"
9-
"flare-ftso-indexer/internal/contracts"
10-
"flare-ftso-indexer/internal/core"
11-
"flare-ftso-indexer/internal/database"
12-
"flare-ftso-indexer/internal/fsp"
13-
"flare-ftso-indexer/internal/health"
14-
"flare-ftso-indexer/internal/ready"
156
"fmt"
167
"os"
178
"os/signal"
189
"syscall"
1910
"time"
2011

12+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/boff"
13+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/chain"
14+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/config"
15+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/contracts"
16+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/core"
17+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/database"
18+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/fsp"
19+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/health"
20+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/ready"
21+
2122
"github.com/flare-foundation/go-flare-common/pkg/logger"
2223
"github.com/pkg/errors"
2324
"gorm.io/gorm"

cmd/indexer/main_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"testing"
99
"time"
1010

11-
"flare-ftso-indexer/internal/chain"
12-
"flare-ftso-indexer/internal/config"
13-
"flare-ftso-indexer/internal/contracts"
14-
"flare-ftso-indexer/internal/core"
15-
"flare-ftso-indexer/internal/database"
11+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/chain"
12+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/config"
13+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/contracts"
14+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/core"
15+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/database"
1616

1717
"github.com/BurntSushi/toml"
1818
"github.com/bradleyjkemp/cupaloy/v2"

config.example.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ stop_index = 0 # stop block; set 0 to index indefinitely
55
history_epochs = 0 # FSP mode only: 0=last 2 hours, >0=number of reward epochs to keep/index from
66
num_parallel_req = 100 # number of parallel requests to the chain
77
batch_size = 1000 # the number of blocks that will be pushed to a database in a batch (should be divisible by num_parallel_req)
8-
log_range = 10 # the size of the interval of blocks used to request logs in each request; suggested value is log_range = batch_size / num_parallel_req; note that a blockchain node might have an upper bound on this
8+
log_range = 1024 # max blocks per eth_getLogs request; set to your RPC's getLogs cap (typically 100-10000)
99
new_block_check_millis = 1000 # interval for checking for new blocks
1010
confirmations = 1 # number of confirmations for latest block queries
1111
no_new_blocks_delay_warning = 60 # max allowed delay between consecutive processed blocks before warning; 0 disables warning
12-
fsp_tx_lookback_seconds = 7200 # FSP mode startup tx lookback window (default 2h)
13-
fsp_log_filter_range = 1024 # FSP mode block range per FilterLogs request during metadata backfill
1412

1513
[[indexer.collect_transactions]]
1614
contract_address = "0x2cA6571Daa15ce734Bbd0Bf27D5C9D16787fc33f" # example target contract; alternatively use contract_name
@@ -24,7 +22,7 @@ topic = "undefined" # topic0 filter; use "undefined" to index all events from th
2422

2523
[logger]
2624
level = "INFO"
27-
file = "./logs/flare-ftso-indexer.log"
25+
file = "./logs/flare-cchain-indexer.log"
2826
console = true
2927

3028
[chain]

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module flare-ftso-indexer
1+
module github.com/flare-foundation/flare-system-c-chain-indexer
22

3-
go 1.23.0
3+
go 1.24.0
44

55
require (
66
github.com/BurntSushi/toml v1.5.0

internal/boff/backoff.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ package boff
44

55
import (
66
"context"
7-
"flare-ftso-indexer/internal/config"
87
"time"
98

9+
"github.com/flare-foundation/flare-system-c-chain-indexer/internal/config"
10+
1011
"github.com/cenkalti/backoff/v5"
1112
"github.com/flare-foundation/go-flare-common/pkg/logger"
1213
)

0 commit comments

Comments
 (0)