Skip to content

Commit a22fd80

Browse files
committed
Merge branch 'ryan/repo-standards' into 'main'
Add informational files and update linter settings See merge request flarenetwork/FSP/flare-system-c-chain-indexer!75
2 parents 8604840 + dac977a commit a22fd80

File tree

10 files changed

+198
-21
lines changed

10 files changed

+198
-21
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @ryanc-flare @tilenflare

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ variables:
22
GOPATH: /go
33
MYSQL_ROOT_PASSWORD: root
44
MYSQL_DATABASE: flare_ftso_indexer_indexer_test
5-
GOLANG_VERSION: "1.24-trixie@sha256:73860edd0febb45d37a5220ba39a6675d67f72163c79a4cebd9d0e6985609140"
6-
GOLINT_VERSION: "v2.1.6"
5+
GOLANG_VERSION: "1.25-trixie@sha256:4f9d98ebaa759f776496d850e0439c48948d587b191fc3949b5f5e4667abef90"
6+
GOLINT_VERSION: "v2.7.0"
77

88
.gocache:
99
key: ${CI_COMMIT_REF_SLUG}

.gitlab/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @ryancollingham @tilen.marc

.golangci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: "2"
2+
run:
3+
go: "1.25.1"
4+
modules-download-mode: readonly
5+
linters:
6+
default: standard
7+
enable:
8+
- asciicheck
9+
- bidichk
10+
- bodyclose
11+
- containedctx
12+
- copyloopvar
13+
- decorder
14+
- errchkjson
15+
- errname
16+
- exhaustive
17+
- exptostd
18+
- forcetypeassert
19+
- misspell
20+
- nolintlint
21+
- unconvert
22+
- whitespace
23+
24+
settings:
25+
exhaustive:
26+
default-signifies-exhaustive: true
27+
nolintlint:
28+
require-specific: true
29+
exclusions:
30+
generated: lax
31+
paths:
32+
- third_party$
33+
- builtin$
34+
- examples$
35+
formatters:
36+
enable:
37+
- gofmt
38+
exclusions:
39+
generated: lax
40+
paths:
41+
- third_party$
42+
- builtin$
43+
- examples$
44+
45+
issues:
46+
max-same-issues: 3
47+

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to
7+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8+
9+
10+
## \[[v1.1.2](https://github.com/flare-foundation/flare-system-c-chain-indexer/tree/v1.1.2)\] - 2025-11-03
11+
12+
### Added
13+
14+
- simplify calculation of starting index within indexer
15+
- add extra env var overrides for DB configuration
16+

CONTRIBUTING.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Contributing
2+
3+
This document describes the process of contributing to this project. It is
4+
intended for anyone considering opening an issue or pull request.
5+
6+
## AI Assistance
7+
8+
> [!IMPORTANT]
9+
>
10+
> If you are using **any kind of AI assistance** to contribute to this project,
11+
> it must be disclosed in the pull request.
12+
13+
If you are using any kind of AI assistance while contributing to this project,
14+
**this must be disclosed in the pull request**, along with the extent to which
15+
AI assistance was used. Trivial tab-completion doesn't need to be disclosed, as
16+
long as it is limited to single keywords or short phrases.
17+
18+
An example disclosure:
19+
20+
> This PR was written primarily by Claude Code.
21+
22+
Or a more detailed disclosure:
23+
24+
> I consulted ChatGPT to understand the codebase but the solution was fully
25+
> authored manually by myself.
26+
27+
## Quick start
28+
29+
If you'd like to contribute, report a bug, suggest a feature or you've
30+
implemented a feature you should open an issue or pull request.
31+
32+
Any contribution to the project is expected to contain code that is formatted,
33+
linted and that the existing tests still pass. Adding unit tests for new code is
34+
also welcome.
35+
36+
## Dev environment
37+
38+
The indexer is implemented using Go - it is recommended to use version 1.24 or later. An RPC connection URL and a MySQL database are required in order to run the main indexer. Configuration should be provided via a `config.toml` file - you can copy
39+
`config.example.toml` and modify to connect to your specific RPC provider and database instance as well as set other
40+
parameters.
41+
42+
## Linting and formatting
43+
44+
`golangci-lint` is used for linting - install instructions may be found
45+
\[[here](https://golangci-lint.run/docs/welcome/install/#local-installation)\]. Once installed you can run with:
46+
47+
```
48+
$ golangci-lint run
49+
```
50+
51+
For formatting use the standard `go fmt` command:
52+
53+
```
54+
$ go fmt ./...
55+
```
56+
57+
It is recommended to set up your editor to run both of these automatically.
58+
59+
## Testing
60+
61+
Run the tests with:
62+
63+
```
64+
$ go test ./...
65+
```
66+
67+
Note that the `main_test.go` is an integration test which requires an RPC connection and MySQL database -
68+
you can edit the test config file at `testing/config_test.toml`. Environment variable overrides are also
69+
supported for convenience.
70+
71+
## Release process (if applicable)
72+
73+
Releases are made by creating a tag. The CHANGELOG.md should also be updated with the release details.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build executable
2-
FROM golang:1.24-trixie@sha256:73860edd0febb45d37a5220ba39a6675d67f72163c79a4cebd9d0e6985609140 AS builder
2+
FROM golang:1.25-trixie@sha256:4f9d98ebaa759f776496d850e0439c48948d587b191fc3949b5f5e4667abef90 AS builder
33

44
WORKDIR /build
55

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1+
<!-- LOGO -->
2+
3+
<div align="center">
4+
<a href="https://flare.network/" target="blank">
5+
<img src="https://content.flare.network/Flare-2.svg" width="300" alt="Flare Logo" />
6+
</a>
7+
<br />
8+
Flare C-Chain Indexer
9+
<br />
10+
<a href="#PROJECT_NAME">About</a>
11+
·
12+
<a href="CONTRIBUTING.md">Contributing</a>
13+
·
14+
<a href="SECURITY.md">Security</a>
15+
·
16+
<a href="CHANGELOG.md">Changelog</a>
17+
</div>
18+
119
# Flare FTSO indexer
220

321
This code implements a fast and parallelized indexer of C-chain that fetches data needed for
422
various Flare protocols. It saves the data in a MySQL database.
523

624
### Prerequisites
725

8-
The indexer is implemented in Go (tested with version 1.21). A running MySQL database to save the data is needed (we provide a
26+
The indexer is implemented in Go (tested with version 1.24). A running MySQL database to save the data is needed (we provide a
927
docker-compose.yaml file for automatic deployment of a database).
1028

1129
### Configuration

SECURITY.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Security policy
2+
3+
## Reporting a vulnerability
4+
5+
If you have found a possible vulnerability, please email
6+
`security@flare.network`.
7+
8+
## Bug bounties
9+
10+
We sincerely appreciate and encourage reports of suspected security
11+
vulnerabilities. We currently run a bug bounty program through Immunefi, where
12+
eligible researchers can earn rewards for responsibly disclosing valid security
13+
issues. Please refer to our
14+
[Immunefi](https://immunefi.com/bug-bounty/flarenetwork/information/) page for
15+
scope, rules, and submission guidelines.
16+
17+
## Vulnerability disclosures
18+
19+
Critical vulnerabilities will be disclosed via GitHub's
20+
[security advisory](https://github.com/flare-foundation/fassets/security)
21+
system.
22+

main_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type testConfig struct {
4141

4242
type IntegrationIndex struct {
4343
suite.Suite
44-
ctx context.Context
4544
cfg config.Config
4645
indexer *indexer.BlockIndexer
4746
db *gorm.DB
@@ -73,20 +72,20 @@ func TestIntegrationIndexHistory(t *testing.T) {
7372
suite.Run(t, testSuite)
7473
}
7574

76-
func (suite *IntegrationIndexContinuousSuite) SetupSuite() {
77-
err := suite.indexer.IndexContinuous(suite.ctx, startBlock)
75+
func (suite *IntegrationIndexContinuousSuite) SetupSuite(ctx context.Context) {
76+
err := suite.indexer.IndexContinuous(ctx, startBlock)
7877
require.NoError(suite.T(), err, "Could not run the indexer")
7978
}
8079

81-
func (suite *IntegrationIndexHistorySuite) SetupSuite() {
82-
lastIndex, err := suite.indexer.IndexHistory(suite.ctx)
80+
func (suite *IntegrationIndexHistorySuite) SetupSuite(ctx context.Context) {
81+
lastIndex, err := suite.indexer.IndexHistory(ctx)
8382
require.NoError(suite.T(), err, "Could not run the indexer")
8483
require.Equal(suite.T(), uint64(endBlockHistory), lastIndex, "Last indexed block does not match expected value")
8584
}
8685

87-
func (suite *IntegrationIndex) TestCheckBlocks() {
86+
func (suite *IntegrationIndex) TestCheckBlocks(ctx context.Context) {
8887
var blocks []database.Block
89-
result := suite.db.WithContext(suite.ctx).Order("hash ASC").Find(&blocks)
88+
result := suite.db.WithContext(ctx).Order("hash ASC").Find(&blocks)
9089
require.NoError(suite.T(), result.Error, "Could not find blocks")
9190

9291
suite.T().Logf("Found %d blocks", len(blocks))
@@ -97,9 +96,9 @@ func (suite *IntegrationIndex) TestCheckBlocks() {
9796
cupaloy.SnapshotT(suite.T(), blocks)
9897
}
9998

100-
func (suite *IntegrationIndex) TestCheckTransactions() {
99+
func (suite *IntegrationIndex) TestCheckTransactions(ctx context.Context) {
101100
var transactions []database.Transaction
102-
result := suite.db.WithContext(suite.ctx).Order("hash ASC").Find(&transactions)
101+
result := suite.db.WithContext(ctx).Order("hash ASC").Find(&transactions)
103102
require.NoError(suite.T(), result.Error, "Could not find transactions")
104103

105104
suite.T().Logf("Found %d transactions", len(transactions))
@@ -110,9 +109,9 @@ func (suite *IntegrationIndex) TestCheckTransactions() {
110109
cupaloy.SnapshotT(suite.T(), transactions)
111110
}
112111

113-
func (suite *IntegrationIndex) TestCheckLogs() {
112+
func (suite *IntegrationIndex) TestCheckLogs(ctx context.Context) {
114113
var logs []database.Log
115-
result := suite.db.WithContext(suite.ctx).
114+
result := suite.db.WithContext(ctx).
116115
Preload("Transaction").
117116
Order("transaction_hash ASC, log_index ASC").
118117
Find(&logs)
@@ -127,7 +126,7 @@ func (suite *IntegrationIndex) TestCheckLogs() {
127126
}
128127

129128
func (suite *IntegrationIndex) prepareSuite(isHistory bool) error {
130-
suite.ctx = context.Background()
129+
ctx := context.Background()
131130
tCfg := testConfig{}
132131

133132
_, err := toml.DecodeFile("testing/config_test.toml", &tCfg)
@@ -139,7 +138,7 @@ func (suite *IntegrationIndex) prepareSuite(isHistory bool) error {
139138

140139
suite.cfg = initConfig(tCfg, isHistory)
141140

142-
suite.db, err = database.ConnectAndInitialize(suite.ctx, &suite.cfg.DB)
141+
suite.db, err = database.ConnectAndInitialize(ctx, &suite.cfg.DB)
143142
if err != nil {
144143
return errors.Wrap(err, "Could not connect to the database")
145144
}
@@ -263,8 +262,8 @@ func checkBlocks(t *testing.T, blocks []database.Block, cfg *config.Config) {
263262

264263
func checkBlock(t *testing.T, block *database.Block, cfg *config.Config) {
265264
require.NotEmpty(t, block.Hash, "Block hash should not be empty")
266-
require.GreaterOrEqual(t, block.Number, uint64(cfg.Indexer.StartIndex))
267-
require.LessOrEqual(t, block.Number, uint64(cfg.Indexer.StopIndex))
265+
require.GreaterOrEqual(t, block.Number, cfg.Indexer.StartIndex)
266+
require.LessOrEqual(t, block.Number, cfg.Indexer.StopIndex)
268267
require.NotZero(t, block.Timestamp, "Timestamp should not be zero")
269268
}
270269

@@ -279,8 +278,8 @@ func checkTransaction(t *testing.T, tx *database.Transaction, cfg *config.Config
279278
require.NotEmpty(t, tx.Hash, "Transaction hash should not be empty")
280279
require.NotEmpty(t, tx.FunctionSig, "Function signature should not be empty")
281280
require.NotEmpty(t, tx.Input, "Input should not be empty")
282-
require.GreaterOrEqual(t, tx.BlockNumber, uint64(cfg.Indexer.StartIndex))
283-
require.LessOrEqual(t, tx.BlockNumber, uint64(cfg.Indexer.StopIndex))
281+
require.GreaterOrEqual(t, tx.BlockNumber, cfg.Indexer.StartIndex)
282+
require.LessOrEqual(t, tx.BlockNumber, cfg.Indexer.StopIndex)
284283
require.NotEmpty(t, tx.BlockHash, "Block hash should not be empty")
285284
require.NotEmpty(t, tx.FromAddress, "From address should not be empty")
286285
require.True(t, compareAddrStrs(tx.ToAddress, contractAddress), "To address should be the contract address")

0 commit comments

Comments
 (0)