forked from filecoin-project/boost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: monitor sectors unsealed state (filecoin-project#1191)
* feat: monitor sectors unsealed state * feat: announce deals to indexer as newly unsealed or no longer unsealed * feat: test for unsealed state manager * feat: update metadata if seal state changes, call NotifyRemove if sector is removed * feat: better logging * feat: check sector seal state once per hour * feat: act on all deals in a sector * feat: announce sealing state changes for legacy deals also * fix: gfm type * chore: fix merge miss * feat: redeclare storage when unsealed state is checked (filecoin-project#1377) * feat: redeclare storage when unsealed state is checked This is currently needed as lotus doesnt automatically update when the fs changes * chore: fix linting * feat: make unsealedstatemanager configurable *Update default duration to 12hours from 1hour *Allow users to disabl redeclaration of storage chore: make gen * refactor: move storage list to 1hour interval --------- Co-authored-by: Jacob Heun <jacob.heun@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com>
- Loading branch information
1 parent
f6282d9
commit 6b246d2
Showing
15 changed files
with
1,105 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE TABLE IF NOT EXISTS SectorState ( | ||
MinerID INT, | ||
SectorID INT, | ||
UpdatedAt DateTime, | ||
SealState TEXT | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS index_sector_state_sector_id on SectorState(SectorID); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
DROP INDEX IF EXISTS index_sector_state_sector_id; | ||
DROP TABLE IF EXISTS SectorState; | ||
-- +goose StatementEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"time" | ||
) | ||
|
||
type SealState string | ||
|
||
const SealStateSealed SealState = "Sealed" | ||
const SealStateUnsealed SealState = "Unsealed" | ||
const SealStateRemoved SealState = "Removed" | ||
|
||
type SectorState struct { | ||
SectorID abi.SectorID | ||
UpdatedAt time.Time | ||
SealState SealState | ||
} | ||
|
||
type SectorStateDB struct { | ||
db *sql.DB | ||
} | ||
|
||
func NewSectorStateDB(db *sql.DB) *SectorStateDB { | ||
return &SectorStateDB{db} | ||
} | ||
|
||
func (sdb *SectorStateDB) List(ctx context.Context) ([]SectorState, error) { | ||
qry := "SELECT MinerID, SectorID, UpdatedAt, SealState FROM SectorState" | ||
rows, err := sdb.db.QueryContext(ctx, qry) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer rows.Close() | ||
|
||
states := make([]SectorState, 0, 16) | ||
for rows.Next() { | ||
var state SectorState | ||
err := rows.Scan(&state.SectorID.Miner, &state.SectorID.Number, &state.UpdatedAt, &state.SealState) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
states = append(states, state) | ||
} | ||
if err := rows.Err(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return states, nil | ||
} | ||
|
||
func (sdb *SectorStateDB) Update(ctx context.Context, sectorID abi.SectorID, SealState SealState) error { | ||
now := time.Now() | ||
qry := "REPLACE INTO SectorState (MinerID, SectorID, UpdatedAt, SealState) VALUES (?, ?, ?, ?)" | ||
_, err := sdb.db.ExecContext(ctx, qry, sectorID.Miner, sectorID.Number, now, SealState) | ||
return err | ||
} |
Oops, something went wrong.