Skip to content

Commit f1809e9

Browse files
committed
schema: miner_sector_info_v7 model
1 parent 138a09e commit f1809e9

File tree

3 files changed

+96
-7
lines changed

3 files changed

+96
-7
lines changed

model/actors/miner/sector.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import (
1313
)
1414

1515
type MinerSectorInfo struct {
16-
Height int64 `pg:",pk,notnull,use_zero"`
17-
MinerID string `pg:",pk,notnull"`
18-
SectorID uint64 `pg:",pk,use_zero"`
19-
StateRoot string `pg:",pk,notnull"`
16+
//lint:ignore U1000 tableName is a convention used by go-pg
17+
tableName struct{} `pg:"miner_sector_infos_v7"`
18+
Height int64 `pg:",pk,notnull,use_zero"`
19+
MinerID string `pg:",pk,notnull"`
20+
SectorID uint64 `pg:",pk,use_zero"`
21+
StateRoot string `pg:",pk,notnull"`
2022

2123
SealedCID string `pg:",notnull"`
2224

@@ -34,6 +36,27 @@ type MinerSectorInfo struct {
3436
SectorKeyCID string
3537
}
3638

39+
type MinerSectorInfoV1_4 struct {
40+
//lint:ignore U1000 tableName is a convention used by go-pg
41+
tableName struct{} `pg:"miner_sector_infos"`
42+
Height int64 `pg:",pk,notnull,use_zero"`
43+
MinerID string `pg:",pk,notnull"`
44+
SectorID uint64 `pg:",pk,use_zero"`
45+
StateRoot string `pg:",pk,notnull"`
46+
47+
SealedCID string `pg:",notnull"`
48+
49+
ActivationEpoch int64 `pg:",use_zero"`
50+
ExpirationEpoch int64 `pg:",use_zero"`
51+
52+
DealWeight string `pg:"type:numeric,notnull"`
53+
VerifiedDealWeight string `pg:"type:numeric,notnull"`
54+
55+
InitialPledge string `pg:"type:numeric,notnull"`
56+
ExpectedDayReward string `pg:"type:numeric,notnull"`
57+
ExpectedStoragePledge string `pg:"type:numeric,notnull"`
58+
}
59+
3760
type MinerSectorInfoV0 struct {
3861
//lint:ignore U1000 tableName is a convention used by go-pg
3962
tableName struct{} `pg:"miner_sector_infos"`
@@ -77,6 +100,26 @@ func (msi *MinerSectorInfo) AsVersion(version model.Version) (interface{}, bool)
77100
ExpectedStoragePledge: msi.ExpectedStoragePledge,
78101
}, true
79102
case 1:
103+
switch version.Patch {
104+
// patch 1-4 do not contain SectorKeyCID
105+
case 1, 2, 3, 4:
106+
return &MinerSectorInfoV1_4{
107+
Height: msi.Height,
108+
MinerID: msi.MinerID,
109+
SectorID: msi.SectorID,
110+
StateRoot: msi.StateRoot,
111+
SealedCID: msi.SealedCID,
112+
ActivationEpoch: msi.ActivationEpoch,
113+
ExpirationEpoch: msi.ExpirationEpoch,
114+
DealWeight: msi.DealWeight,
115+
VerifiedDealWeight: msi.VerifiedDealWeight,
116+
InitialPledge: msi.InitialPledge,
117+
ExpectedDayReward: msi.ExpectedDayReward,
118+
ExpectedStoragePledge: msi.ExpectedStoragePledge,
119+
}, true
120+
default:
121+
// patch 5 contains SectorKeyCID column
122+
}
80123
return msi, true
81124
default:
82125
return nil, false

schemas/v1/5_miner_sector_snaps.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,53 @@ func init() {
77
-- add new sector event type for snapped sectors
88
ALTER TYPE {{ .SchemaName | default "public"}}.miner_sector_event_type ADD VALUE 'SECTOR_SNAPPED' AFTER 'SECTOR_TERMINATED';
99
10-
-- add a column sector_key_cid to miner_sector_infos for change in actors v7, filed is nullable.
11-
ALTER TABLE {{ .SchemaName | default "public"}}.miner_sector_infos
12-
ADD COLUMN sector_key_cid text;
10+
-- ----------------------------------------------------------------
11+
-- Name: miner_sector_infos_v7
12+
-- Model: miner.MinerSectorInfoV7
13+
-- Growth: About 180 per epoch
14+
-- ----------------------------------------------------------------
15+
CREATE TABLE {{ .SchemaName | default "public"}}.miner_sector_infos_v7 (
16+
miner_id text NOT NULL,
17+
sector_id bigint NOT NULL,
18+
state_root text NOT NULL,
19+
sealed_cid text NOT NULL,
20+
activation_epoch bigint,
21+
expiration_epoch bigint,
22+
deal_weight numeric NOT NULL,
23+
verified_deal_weight numeric NOT NULL,
24+
initial_pledge numeric NOT NULL,
25+
expected_day_reward numeric NOT NULL,
26+
expected_storage_pledge numeric NOT NULL,
27+
height bigint NOT NULL,
28+
sector_key_cid text
29+
);
30+
ALTER TABLE ONLY {{ .SchemaName | default "public"}}.miner_sector_infos_v7 ADD CONSTRAINT miner_sector_infos_v7_pkey PRIMARY KEY (height, miner_id, sector_id, state_root);
31+
CREATE INDEX miner_sector_infos_v7_height_idx ON {{ .SchemaName | default "public"}}.miner_sector_infos_v7 USING btree (height DESC);
32+
33+
-- Convert miner_sector_infos_v7 to a hypertable partitioned on height (time)
34+
-- Assume ~180 per epoch, ~300 bytes per table row
35+
-- Height chunked per 7 days so we expect 20160*5 = ~3628800 rows per chunk, ~1GiB per chunk
36+
SELECT create_hypertable(
37+
'miner_sector_infos_v7',
38+
'height',
39+
chunk_time_interval => 20160,
40+
if_not_exists => TRUE
41+
);
42+
SELECT set_integer_now_func('miner_sector_infos_v7', 'current_height', replace_if_exists => true);
43+
44+
COMMENT ON TABLE {{ .SchemaName | default "public"}}.miner_sector_infos_v7 IS 'Latest state of sectors by Miner.';
45+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.miner_id IS 'Address of the miner who owns the sector.';
46+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.sector_id IS 'Numeric identifier of the sector.';
47+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.state_root IS 'CID of the parent state root at this epoch.';
48+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.sealed_cid IS 'The root CID of the Sealed Sector’s merkle tree. Also called CommR, or "replica commitment".';
49+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.activation_epoch IS 'Epoch during which the sector proof was accepted.';
50+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.expiration_epoch IS 'Epoch during which the sector expires.';
51+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.deal_weight IS 'Integral of active deals over sector lifetime.';
52+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.verified_deal_weight IS 'Integral of active verified deals over sector lifetime.';
53+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.initial_pledge IS 'Pledge collected to commit this sector (in attoFIL).';
54+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.expected_day_reward IS 'Expected one day projection of reward for sector computed at activation time (in attoFIL).';
55+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.expected_storage_pledge IS 'Expected twenty day projection of reward for sector computed at activation time (in attoFIL).';
56+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.height IS 'Epoch at which this sector info was added/updated.';
57+
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.miner_sector_infos_v7.sector_key_cid IS 'SealedSectorCID is set when CC sector is snapped.';
1358
`)
1459
}

storage/sql.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var models = []interface{}{
4040

4141
(*miner.MinerSectorDeal)(nil),
4242
(*miner.MinerSectorInfo)(nil),
43+
(*miner.MinerSectorInfoV1_4)(nil),
4344
(*miner.MinerSectorPost)(nil),
4445
(*miner.MinerPreCommitInfo)(nil),
4546
(*miner.MinerSectorEvent)(nil),

0 commit comments

Comments
 (0)