Skip to content

Commit

Permalink
fix: update piece metadata to get deal details (#55)
Browse files Browse the repository at this point in the history
* use piece metadata table

* migrate UpdateActivating sectors
  • Loading branch information
LexLuthr authored Jun 12, 2024
1 parent 7220b2a commit 9c9016d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
16 changes: 14 additions & 2 deletions cmd/curio/guidedsetup/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.

migratableState := func(state sealing.SectorState) bool {
switch state {
case sealing.Proving, sealing.Available, sealing.Removed:
case sealing.Proving, sealing.Available, sealing.UpdateActivating, sealing.Removed:
return true
default:
return false
Expand Down Expand Up @@ -370,6 +370,7 @@ func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.
startEpoch := int64(0)
endEpoch := int64(0)
var pamJSON *string
var dealProposalJSONStr *string

if piece.HasDealInfo() {
dealInfo := piece.DealInfo()
Expand All @@ -387,6 +388,15 @@ func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.
ps := string(pam)
pamJSON = &ps
}
if piece.Impl().DealProposal != nil {
dealProposalJSON, err := json.Marshal(piece.Impl().DealProposal)
if err != nil {
return xerrors.Errorf("error marshalling deal proposal JSON for piece %d in sector %d: %w", j, sector.SectorNumber, err)
}
dp := string(dealProposalJSON)
dealProposalJSONStr = &dp
}

}

// Splitting the SQL statement for readability and adding new fields
Expand All @@ -405,7 +415,8 @@ func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.
start_epoch = excluded.start_epoch,
orig_end_epoch = excluded.orig_end_epoch,
f05_deal_id = excluded.f05_deal_id,
ddo_pam = excluded.ddo_pam`,
ddo_pam = excluded.ddo_pam,
f05_deal_proposal = excluded.f05_deal_proposal`,
mid,
sector.SectorNumber,
j,
Expand All @@ -417,6 +428,7 @@ func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.
endEpoch,
dealID,
pamJSON,
dealProposalJSONStr,
)
if err != nil {
b, _ := json.MarshalIndent(sector, "", " ")
Expand Down
2 changes: 2 additions & 0 deletions harmony/harmonydb/sql/20240425-sector_meta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ CREATE TABLE sectors_meta_pieces (
f05_deal_id BIGINT,
ddo_pam jsonb,

-- f05_deal_proposal jsonb added in 20240612-deal-proposal.sql

PRIMARY KEY (sp_id, sector_num, piece_num),
FOREIGN KEY (sp_id, sector_num) REFERENCES sectors_meta(sp_id, sector_num) ON DELETE CASCADE
);
2 changes: 2 additions & 0 deletions harmony/harmonydb/sql/20240612-deal-proposal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE sectors_meta_pieces
ADD COLUMN f05_deal_proposal jsonb;
9 changes: 6 additions & 3 deletions tasks/seal/task_submit_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ func (s *SubmitCommitTask) transferFinalizedSectorData(ctx context.Context, spID
start_epoch,
orig_end_epoch,
f05_deal_id,
ddo_pam
ddo_pam,
f05_deal_proposal
)
SELECT
sp_id,
Expand All @@ -344,7 +345,8 @@ func (s *SubmitCommitTask) transferFinalizedSectorData(ctx context.Context, spID
COALESCE(f05_deal_start_epoch, direct_start_epoch) as start_epoch,
COALESCE(f05_deal_end_epoch, direct_end_epoch) as orig_end_epoch,
f05_deal_id,
direct_piece_activation_manifest as ddo_pam
direct_piece_activation_manifest as ddo_pam,
f05_deal_proposal
FROM
sectors_sdr_initial_pieces
WHERE
Expand All @@ -358,7 +360,8 @@ func (s *SubmitCommitTask) transferFinalizedSectorData(ctx context.Context, spID
start_epoch = excluded.start_epoch,
orig_end_epoch = excluded.orig_end_epoch,
f05_deal_id = excluded.f05_deal_id,
ddo_pam = excluded.ddo_pam;
ddo_pam = excluded.ddo_pam,
f05_deal_proposal = excluded.f05_deal_proposal;
`, spID, sectorNum); err != nil {
return fmt.Errorf("failed to insert/update sector_meta_pieces: %w", err)
}
Expand Down
11 changes: 11 additions & 0 deletions web/api/sector/sector.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
direct_piece_activation_manifest
FROM sectors_sdr_initial_pieces
ORDER BY sp_id, sector_number`))
var mpieces []piece
apihelper.OrHTTPFail(w, c.DB.Select(r.Context(), &mpieces, `SELECT
sp_id,
sector_num,
piece_size,
COALESCE(f05_deal_id, 0) AS f05_deal_id,
f05_deal_proposal,
ddo_pam
FROM sectors_meta_pieces
ORDER BY sp_id, sector_num`))
pieces = append(pieces, mpieces...)
pieceIndex := map[sectorID][]int{}
for i, piece := range pieces {
piece := piece
Expand Down

0 comments on commit 9c9016d

Please sign in to comment.