Skip to content

Commit dd16b50

Browse files
authored
Merge branch 'cosmostation:develop' into develop
2 parents b674d00 + 7865eff commit dd16b50

20 files changed

+248
-40
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
postgres:
3+
profiles: ['disables']

docker-compose.yaml

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ services:
7474
--port=9300,
7575
]
7676
environment:
77-
- DB_HOST=cvms-indexer-db
78-
- DB_PORT=5432
79-
- DB_NAME=cvms
77+
- DB_HOST=${DB_HOST:-cvms-indexer-db}
78+
- DB_PORT=${DB_PORT:-5432}
79+
- DB_NAME=${DB_NAME:-cvms}
8080
- DB_USER=${DB_USER:-cvms}
8181
- DB_PASSWORD=${DB_PASSWORD:-mysecretpassword}
8282
- DB_RETENTION_PERIOD=${DB_RETENTION_PERIOD:-1h}
@@ -86,8 +86,6 @@ services:
8686
- ./docker/cvms/${CUSTOM_CHAINS_FILE:-custom_chains.yaml.example}:/var/lib/cvms/docker/cvms/custom_chains.yaml:ro
8787
networks:
8888
- cvms-net
89-
depends_on:
90-
- postgres
9189

9290
postgres:
9391
<<: *logging
@@ -106,27 +104,6 @@ services:
106104
- ./docker/postgres/schema:/docker-entrypoint-initdb.d/:ro
107105
- indexer-db-volume:/var/lib/postgresql/data
108106

109-
flyway:
110-
image: flyway/flyway:11.3.1
111-
container_name: flyway
112-
profiles:
113-
- migration
114-
depends_on:
115-
- postgres
116-
command: ['migrate']
117-
environment:
118-
- FLYWAY_URL=jdbc:postgresql://cvms-indexer-db:5432/cvms
119-
- FLYWAY_USER=${DB_USER:-cvms}
120-
- FLYWAY_PASSWORD=${DB_PASSWORD:-mysecretpassword}
121-
- FLYWAY_LOCATIONS=filesystem:/flyway/sql
122-
- FLYWAY_SCHEMAS=public,meta # Migrate both public and meta schemas
123-
- FLYWAY_BASELINE_ON_MIGRATE=true
124-
- FLYWAY_VALIDATE_ON_MIGRATE=true
125-
volumes:
126-
- ./docker/flyway:/flyway/sql
127-
networks:
128-
- cvms-net
129-
130107
grafana:
131108
<<: *logging
132109
image: grafana/grafana:latest
@@ -148,15 +125,14 @@ services:
148125
# public access
149126
- GF_AUTH_ANONYMOUS_ENABLED=true
150127
# applications
151-
- DB_HOST=cvms-indexer-db
152-
- DB_PORT=5432
153-
- DB_NAME=cvms
128+
- DB_HOST=${DB_HOST:-cvms-indexer-db}
129+
- DB_PORT=${DB_PORT:-5432}
130+
- DB_NAME=${DB_NAME:-cvms}
154131
- DB_USER=${DB_USER:-cvms}
155132
- DB_PASSWORD=${DB_PASSWORD:-mysecretpassword}
156133
- GF_INSTALL_PLUGINS=nline-plotlyjs-panel
157134
ports:
158135
- ${GRAFANA_SERVER_PORT:-3000}:3000
159-
# depends_on: [prometheus or postgres]
160136
networks:
161137
- cvms-net
162138

@@ -178,8 +154,9 @@ services:
178154
- ${ALERTMANAGER_SERVER_PORT:-9093}:9093
179155

180156
promtail:
181-
container_name: cvms-promtail
182157
image: grafana/promtail:latest
158+
container_name: cvms-promtail
159+
restart: 'unless-stopped'
183160
user: root
184161
volumes:
185162
- /etc/machine-id:/etc/machine-id:ro
@@ -188,27 +165,26 @@ services:
188165
- ${DOCKER_ROOT:-/var/lib/docker}/containers:/var/lib/docker/containers:ro,rslave
189166
command:
190167
- '--config.file=/etc/promtail/promtail-config.yaml'
191-
restart: 'unless-stopped'
192168
networks: ['cvms-net']
193169
depends_on: ['loki']
194170
<<: *logging
195171

196172
loki:
197-
container_name: cvms-loki
198173
image: grafana/loki:latest
174+
container_name: cvms-loki
175+
restart: 'unless-stopped'
199176
volumes:
200177
- loki-volume:/tmp
201178
- ./docker/loki:/etc/loki
202179
command:
203180
- '--config.file=/etc/loki/loki.yaml'
204-
restart: 'unless-stopped'
205181
networks: ['cvms-net']
206182
<<: *logging
207183

208184
cadvisor:
185+
image: gcr.io/cadvisor/cadvisor:v0.49.1
209186
container_name: cvms-cadvisor
210187
restart: 'unless-stopped'
211-
image: gcr.io/cadvisor/cadvisor:v0.49.1
212188
volumes:
213189
- /var/run/docker.sock:/var/run/docker.sock:ro
214190
- /:/rootfs:ro,rslave

docker/flyway/V1_01__init_meta.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ CREATE TABLE
6868
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
6969
"chain_info_id" INT NOT NULL,
7070
"covenant_btc_pk" VARCHAR(64) NOT NULL,
71+
"moniker" VARCHAR(255) NOT NULL,
7172
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info(id) ON DELETE CASCADE ON UPDATE CASCADE,
7273
PRIMARY KEY ("id", "chain_info_id"),
7374
CONSTRAINT uniq_covenant_btc_pk_by_chain UNIQUE (chain_info_id, covenant_btc_pk)
@@ -88,6 +89,7 @@ CREATE TABLE
8889
PARTITION BY
8990
LIST ("chain_info_id");
9091

92+
9193
CREATE TABLE
9294
IF NOT EXISTS "meta"."vigilante_info" (
9395
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
@@ -98,5 +100,17 @@ CREATE TABLE
98100
PRIMARY KEY ("id", "chain_info_id"),
99101
CONSTRAINT uniq_address_by_chain UNIQUE (chain_info_id, operator_address)
100102
)
103+
PARTITION BY
104+
LIST ("chain_info_id");
105+
106+
CREATE TABLE
107+
IF NOT EXISTS "meta"."message_type" (
108+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
109+
"chain_info_id" INT NOT NULL,
110+
"message_type" TEXT NOT NULL,
111+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info(id) ON DELETE CASCADE ON UPDATE CASCADE,
112+
PRIMARY KEY ("id", "chain_info_id"),
113+
CONSTRAINT uniq_message_type_by_chain UNIQUE (chain_info_id, message_type)
114+
)
101115
PARTITION BY
102116
LIST ("chain_info_id");

docker/flyway/V1_02__init_babylon_btc_lightclient.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE IF NOT EXISTS "public"."babylon_btc_lightclient" (
2+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
3+
"chain_info_id" INT NOT NULL,
4+
"height" BIGINT NOT NULL,
5+
"reporter_id" INT NOT NULL,
6+
"roll_forward_count" SMALLINT NOT NULL,
7+
"roll_back_count" SMALLINT NOT NULL,
8+
"btc_height" BIGINT NOT NULL,
9+
"is_roll_back" BOOLEAN NOT NULL,
10+
"btc_headers" TEXT NOT NUll,
11+
PRIMARY KEY ("id", "chain_info_id"),
12+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info (id) ON DELETE CASCADE ON UPDATE CASCADE,
13+
CONSTRAINT fk_reporter_id FOREIGN KEY (reporter_id, chain_info_id) REFERENCES meta.vigilante_info (id, chain_info_id),
14+
CONSTRAINT uniq_babylon_btc_lightclient_by_height UNIQUE ("chain_info_id","height","reporter_id")
15+
)
16+
PARTITION BY
17+
LIST ("chain_info_id");
18+
19+
CREATE INDEX IF NOT EXISTS babylon_btc_lightclient_idx_01 ON public.babylon_btc_lightclient (height);
20+
CREATE INDEX IF NOT EXISTS babylon_btc_lightclient_idx_02 ON public.babylon_btc_lightclient (reporter_id, height);
21+
CREATE INDEX IF NOT EXISTS babylon_btc_lightclient_idx_03 ON public.babylon_btc_lightclient USING btree (chain_info_id, reporter_id, height desc);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE IF NOT EXISTS "public"."babylon_checkpoint" (
2+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
3+
"chain_info_id" INT NOT NULL,
4+
"epoch" INT NOT NULL,
5+
"height" BIGINT NOT NULL,
6+
"timestamp" timestamptz NOT NULL,
7+
"validator_hex_address_id" INT NOT NULL,
8+
"status" SMALLINT NOT NULL,
9+
PRIMARY KEY ("id", "chain_info_id"),
10+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info (id) ON DELETE CASCADE ON UPDATE CASCADE,
11+
CONSTRAINT fk_validator_hex_address_id FOREIGN KEY (validator_hex_address_id, chain_info_id) REFERENCES meta.validator_info (id, chain_info_id),
12+
CONSTRAINT uniq_babylon_checkpoint UNIQUE ("chain_info_id","height","validator_hex_address_id")
13+
)
14+
PARTITION BY
15+
LIST ("chain_info_id");
16+
17+
CREATE INDEX IF NOT EXISTS babylon_checkpoint_idx_01 ON public.babylon_checkpoint (height);
18+
CREATE INDEX IF NOT EXISTS babylon_checkpoint_idx_02 ON public.babylon_checkpoint (validator_hex_address_id, height);
19+
CREATE INDEX IF NOT EXISTS babylon_checkpoint_idx_03 ON public.babylon_checkpoint USING btree (chain_info_id, validator_hex_address_id, height asc);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATE TABLE IF NOT EXISTS "public"."babylon_finality_provider" (
2+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
3+
"chain_info_id" INT NOT NULL,
4+
"height" BIGINT NOT NULL,
5+
"finality_provider_pk_id" INT NOT NULL,
6+
"status" SMALLINT NOT NULL,
7+
"timestamp" timestamptz NOT NULL,
8+
PRIMARY KEY ("id", "chain_info_id"),
9+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info (id) ON DELETE CASCADE ON UPDATE CASCADE,
10+
CONSTRAINT fk_finality_provider_pk_id FOREIGN KEY (finality_provider_pk_id, chain_info_id) REFERENCES meta.finality_provider_info (id, chain_info_id),
11+
CONSTRAINT uniq_babylon_finality_provider_by_height UNIQUE ("chain_info_id","height","finality_provider_pk_id")
12+
)
13+
PARTITION BY
14+
LIST ("chain_info_id");
15+
16+
CREATE INDEX IF NOT EXISTS babylon_finality_provider_idx_01 ON public.babylon_finality_provider (height);
17+
CREATE INDEX IF NOT EXISTS babylon_finality_provider_idx_02 ON public.babylon_finality_provider (finality_provider_pk_id, height);
18+
CREATE INDEX IF NOT EXISTS babylon_finality_provider_idx_03 ON public.babylon_finality_provider USING btree (chain_info_id, finality_provider_pk_id, height asc);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
CREATE TABLE IF NOT EXISTS "public"."block_data_analytics" (
2+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
3+
"chain_info_id" INT NOT NULL,
4+
"height" BIGINT NOT NULL,
5+
"timestamp" timestamptz NOT NULL,
6+
7+
"total_txs_bytes" INT NOT NULL,
8+
"total_gas_used" INT NOT NULL,
9+
"total_gas_wanted" INT NOT NULL,
10+
"success_txs_count" INT NOT NULL,
11+
"failed_txs_count" INT NOT NULL,
12+
13+
PRIMARY KEY ("id", "chain_info_id"),
14+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info (id) ON DELETE CASCADE ON UPDATE CASCADE
15+
)
16+
PARTITION BY
17+
LIST ("chain_info_id");
18+
19+
CREATE INDEX IF NOT EXISTS block_data_analytics_idx_01 ON public.block_data_analytics (height);
20+
21+
22+
CREATE TABLE IF NOT EXISTS "public"."block_message_analytics" (
23+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
24+
"chain_info_id" INT NOT NULL,
25+
"height" BIGINT NOT NULL,
26+
"timestamp" timestamptz NOT NULL,
27+
28+
"message_type_id" INT NOT NULL,
29+
"success" BOOLEAN NOT NULL,
30+
31+
PRIMARY KEY ("id", "chain_info_id"),
32+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info (id) ON DELETE CASCADE ON UPDATE CASCADE,
33+
CONSTRAINT fk_message_type_id FOREIGN KEY (message_type_id, chain_info_id) REFERENCES meta.message_type (id, chain_info_id)
34+
)
35+
PARTITION BY
36+
LIST ("chain_info_id");
37+
38+
CREATE INDEX IF NOT EXISTS block_message_analytics_idx_01 ON public.block_message_analytics (height);
39+
CREATE INDEX IF NOT EXISTS block_message_analytics_idx_02 ON public.block_message_analytics (message_type_id, height);
40+
CREATE INDEX IF NOT EXISTS block_message_analytics_idx_03 ON public.block_message_analytics USING btree (chain_info_id, success, height asc);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE IF NOT EXISTS "public"."veindexer" (
2+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
3+
"chain_info_id" INT NOT NULL,
4+
"height" BIGINT NOT NULL,
5+
"validator_hex_address_id" INT NOT NULL,
6+
"status" SMALLINT NOT NULL,
7+
"vote_extension_length" INT NOT NULL,
8+
"timestamp" timestamptz NOT NULL,
9+
PRIMARY KEY ("id", "chain_info_id"),
10+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info (id) ON DELETE CASCADE ON UPDATE CASCADE,
11+
CONSTRAINT fk_validator_hex_address_id FOREIGN KEY (validator_hex_address_id, chain_info_id) REFERENCES meta.validator_info (id, chain_info_id),
12+
CONSTRAINT uniq_validator_hex_address_by_height UNIQUE ("chain_info_id","height","validator_hex_address_id")
13+
)
14+
PARTITION BY
15+
LIST ("chain_info_id");
16+
17+
CREATE INDEX IF NOT EXISTS veindexer_idx_01 ON public.veindexer (height);
18+
CREATE INDEX IF NOT EXISTS veindexer_idx_02 ON public.veindexer (validator_hex_address_id, height);
19+
CREATE INDEX IF NOT EXISTS veindexer_idx_03 ON public.veindexer USING btree (chain_info_id, validator_hex_address_id, height asc);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- status := 0 is NaN(jailed or inactive) 1 is missed, 2 is voted, 3 is proposed
2+
CREATE TABLE IF NOT EXISTS "public"."voteindexer" (
3+
"id" BIGINT GENERATED ALWAYS AS IDENTITY,
4+
"chain_info_id" INT NOT NULL,
5+
"height" BIGINT NOT NULL,
6+
"validator_hex_address_id" INT NOT NULL,
7+
"status" SMALLINT NOT NULL,
8+
"timestamp" timestamptz NOT NULL,
9+
PRIMARY KEY ("id", "chain_info_id"),
10+
CONSTRAINT fk_chain_info_id FOREIGN KEY (chain_info_id) REFERENCES meta.chain_info (id) ON DELETE CASCADE ON UPDATE CASCADE,
11+
CONSTRAINT fk_validator_hex_address_id FOREIGN KEY (validator_hex_address_id, chain_info_id) REFERENCES meta.validator_info (id, chain_info_id),
12+
CONSTRAINT uniq_block_missed_validator_hex_address_by_height UNIQUE ("chain_info_id","height","validator_hex_address_id")
13+
)
14+
PARTITION BY
15+
LIST ("chain_info_id");
16+
17+
CREATE INDEX IF NOT EXISTS voteindexer_idx_01 ON public.voteindexer (height);
18+
CREATE INDEX IF NOT EXISTS voteindexer_idx_02 ON public.voteindexer (validator_hex_address_id, height);
19+
CREATE INDEX IF NOT EXISTS voteindexer_idx_03 ON public.voteindexer USING btree (chain_info_id, validator_hex_address_id, height asc);

docker/grafana/provisioning/datasources/datasources.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ datasources:
2222
secureJsonData:
2323
password: ${DB_PASSWORD}
2424
jsonData:
25-
database: cvms
25+
database: ${DB_NAME}
2626
sslmode: 'disable' # disable/require/verify-ca/verify-full
2727
postgresVersion: 1604 # 903=9.3, 904=9.4, 905=9.5, 906=9.6, 1000=10
2828
timescaledb: false

internal/common/indexer/repository/covenant_commitee_info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (repo *MetaRepository) UpsertCovenantCommitteeInfoList(ccInfoList []model.C
8484

8585
_, err := repo.NewInsert().
8686
Model(&ccInfoList).
87+
ExcludeColumn("id").
8788
On("CONFLICT (chain_info_id, covenant_btc_pk) DO UPDATE").
8889
Set("moniker = EXCLUDED.moniker").
8990
Exec(ctx)

internal/packages/babylon/covenant-committee/indexer/indexer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ func (idx *CovenantSignatureIndexer) Start() error {
9090
})
9191
}
9292

93-
idx.csRepo.UpsertCovenantCommitteeInfoList(newCovenantCommitteeInfoList)
93+
err = idx.csRepo.UpsertCovenantCommitteeInfoList(newCovenantCommitteeInfoList)
94+
if err != nil {
95+
return errors.Wrap(err, "failed to upsert covenant committee list")
96+
}
9497
err = idx.FetchValidatorInfoList()
9598
if err != nil {
9699
return errors.Wrap(err, "failed to fetch covenant committee list")

internal/packages/babylon/finality-provider/api/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func GetFinalityProviderUptime(exporter *common.Exporter) (types.BabylonFinality
7373
return types.BabylonFinalityProviderUptimeStatues{}, errors.Wrap(err, "failed to get finality providers in last finalized block")
7474
}
7575

76-
LastFinalizedBlockInfo := getLastFinalizedBlockInfo(votes, fps)
76+
LastFinalizedBlockInfo := getLastFinalizedBlockInfo(votes, fps, lastFinalizedBlockHeight)
7777

7878
return types.BabylonFinalityProviderUptimeStatues{
7979
SignedBlocksWindow: signedBlocksWindow,
@@ -114,7 +114,7 @@ func addActiveStatus(activeProviders []commontypes.FinalityProvider, finalityPro
114114
return finalityProviderInfos, jailedCnt, slashedCnt
115115
}
116116

117-
func getLastFinalizedBlockInfo(votes []string, fps []commontypes.FinalityProvider) types.LastFinalizedBlockInfo {
117+
func getLastFinalizedBlockInfo(votes []string, fps []commontypes.FinalityProvider, blockHeight int64) types.LastFinalizedBlockInfo {
118118
missingVotes := len(fps) - len(votes)
119119
missingVP := float64(0)
120120
finalizedVP := float64(0)
@@ -142,5 +142,6 @@ func getLastFinalizedBlockInfo(votes []string, fps []commontypes.FinalityProvide
142142
MissingVotes: float64(missingVotes),
143143
MissingVP: missingVP,
144144
FinalizedVP: finalizedVP,
145+
BlockHeight: float64(blockHeight),
145146
}
146147
}

internal/packages/babylon/finality-provider/collector/collector.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
LastFinalizedBlockMissingVotesCountMetricName = "last_finalized_block_missing_votes_count"
3030
LastFinalizedBlockMissingVPMetricName = "last_finalized_block_missing_vp"
3131
LastFinalizedBlockFinalizedVPMetricName = "last_finalized_block_finalized_vp"
32+
LastFinalizedBlockHeight = "last_finalized_block_height"
3233

3334
METRIC_NAME_FINALITY_PROVIDERS_TOTAL = "total"
3435
)
@@ -114,6 +115,12 @@ func loop(exporter *common.Exporter, p common.Packager) {
114115
Name: LastFinalizedBlockFinalizedVPMetricName,
115116
ConstLabels: packageLabels,
116117
})
118+
lastFinalizedBlockHeightMetric := p.Factory.NewGauge(prometheus.GaugeOpts{
119+
Namespace: common.Namespace,
120+
Subsystem: Subsystem,
121+
Name: LastFinalizedBlockHeight,
122+
ConstLabels: packageLabels,
123+
})
117124

118125
fpTotalMetric := p.Factory.NewGaugeVec(prometheus.GaugeOpts{
119126
Namespace: common.Namespace,
@@ -234,6 +241,7 @@ func loop(exporter *common.Exporter, p common.Packager) {
234241
lastFinalizedBlockMissingVotesCountMetric.Set(status.LastFinalizedBlockInfo.MissingVotes)
235242
lastFinalizedBlockMissingVPMetric.Set(status.LastFinalizedBlockInfo.MissingVP)
236243
lastFinalizedBlockFinalizedVPMetric.Set(status.LastFinalizedBlockInfo.FinalizedVP)
244+
lastFinalizedBlockHeightMetric.Set(status.LastFinalizedBlockInfo.BlockHeight)
237245

238246
exporter.Infof("updated metrics successfully and going to sleep %s ...", SubsystemSleep.String())
239247

internal/packages/babylon/finality-provider/types/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type LastFinalizedBlockInfo struct {
2222
MissingVotes float64
2323
MissingVP float64
2424
FinalizedVP float64
25+
BlockHeight float64
2526
}
2627

2728
type FinalityProviderTotal struct {

0 commit comments

Comments
 (0)