Skip to content

Commit 64d55f1

Browse files
authored
chore(log): consolidate pdp & pdpv0 loggers (#1081)
pdp logger for the shared components pdpv0 logger for pdpv0 specific components Ref: FilOzone/foc-devnet#80
1 parent 60f77a6 commit 64d55f1

5 files changed

Lines changed: 34 additions & 40 deletions

File tree

pdp/contract/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/filecoin-project/lotus/chain/types/ethtypes"
3333
)
3434

35-
var log = logging.Logger("pdp-contract")
35+
var log = logging.Logger("pdp")
3636

3737
// Standard capability keys for PDP product type (must match ServiceProviderRegistry.sol REQUIRED_PDP_KEYS Bloom filter)
3838
const (

pdp/handlers_add.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/ethereum/go-ethereum/core/types"
1717
"github.com/go-chi/chi/v5"
1818
"github.com/ipfs/go-cid"
19-
logger "github.com/ipfs/go-log/v2"
2019
"github.com/yugabyte/pgx/v5"
2120

2221
"github.com/filecoin-project/go-commp-utils/nonffi"
@@ -50,8 +49,6 @@ type SubPieceInfo struct {
5049
SubPieceOffset uint64
5150
}
5251

53-
var logAdd = logger.Logger("pdp/add")
54-
5552
func (p *PDPService) transformAddPiecesRequest(ctx context.Context, serviceLabel string, pieces []AddPieceRequest) ([]PieceData, map[string]*SubPieceInfo, error) {
5653
// Collect all subPieceCids to fetch their info in a batch
5754
subPieceCidSet := make(map[string]struct{})
@@ -341,7 +338,7 @@ func (p *PDPService) handleAddPieceToDataSet(w http.ResponseWriter, r *http.Requ
341338
// Step 4: Prepare piece information
342339
pieceDataArray, subPieceInfoMap, err := p.transformAddPiecesRequest(ctx, serviceLabel, payload.Pieces)
343340
if err != nil {
344-
logAdd.Warnf("Failed to process AddPieces request data: %+v", err)
341+
log.Warnf("Failed to process AddPieces request data: %+v", err)
345342
http.Error(w, "Failed to process request: "+err.Error(), http.StatusBadRequest)
346343
}
347344

@@ -382,48 +379,48 @@ func (p *PDPService) handleAddPieceToDataSet(w http.ResponseWriter, r *http.Requ
382379
// Step 8: Check for indexing requirements
383380
mustIndex, err := CheckIfIndexingNeeded(ctx, p.ethClient, dataSetIdUint64)
384381
if err != nil {
385-
logAdd.Errorw("Failed to check indexing requirements", "error", err, "dataSetId", dataSetId)
382+
log.Errorw("Failed to check indexing requirements", "error", err, "dataSetId", dataSetId)
386383
http.Error(w, "Internal server error", http.StatusInternalServerError)
387384
return
388385
}
389386
if mustIndex {
390-
logAdd.Infow("Data set has withIPFSIndexing enabled, pieces will be indexed", "dataSetId", dataSetId)
387+
log.Infow("Data set has withIPFSIndexing enabled, pieces will be indexed", "dataSetId", dataSetId)
391388
}
392389

393390
// Step 9: Send the transaction
394391
reason := "pdp-addpieces"
395392
txHash, err := p.sender.Send(workCtx, fromAddress, txEth, reason)
396393
if err != nil {
397394
http.Error(w, "Failed to send transaction: "+err.Error(), http.StatusInternalServerError)
398-
logAdd.Errorf("Failed to send transaction: %+v", err)
395+
log.Errorf("Failed to send transaction: %+v", err)
399396
return
400397
}
401398

402399
// Step 10: Insert database tracking records
403400
txHashLower := strings.ToLower(txHash.Hex())
404-
logAdd.Infow("PDP AddPieces: Inserting transaction tracking",
401+
log.Infow("PDP AddPieces: Inserting transaction tracking",
405402
"txHash", txHashLower,
406403
"dataSetId", dataSetIdUint64,
407404
"pieceCount", len(payload.Pieces))
408405

409406
comm, err := p.db.BeginTransaction(workCtx, func(txdb *harmonydb.Tx) (bool, error) {
410407
// Insert into message_waits_eth
411-
logAdd.Debugw("Inserting AddPieces into message_waits_eth",
408+
log.Debugw("Inserting AddPieces into message_waits_eth",
412409
"txHash", txHashLower,
413410
"status", "pending")
414411
n, err := txdb.Exec(`
415412
INSERT INTO message_waits_eth (signed_tx_hash, tx_status)
416413
VALUES ($1, $2)
417414
`, txHashLower, "pending")
418415
if err != nil {
419-
logAdd.Errorw("Failed to insert AddPieces into message_waits_eth",
416+
log.Errorw("Failed to insert AddPieces into message_waits_eth",
420417
"txHash", txHashLower,
421418
"error", err)
422419
return false, err // Return false to rollback the transaction
423420
}
424421

425422
if n != 1 {
426-
logAdd.Errorw("Failed to insert AddPieces into message_waits_eth",
423+
log.Errorw("Failed to insert AddPieces into message_waits_eth",
427424
"txHash", txHashLower,
428425
"expected_rows", 1,
429426
"actual_rows", n)
@@ -437,7 +434,7 @@ func (p *PDPService) handleAddPieceToDataSet(w http.ResponseWriter, r *http.Requ
437434
}
438435

439436
if mustIndex {
440-
logAdd.Debugw("Data set metadata exists, marking all subpieces as needing indexing", "dataSetId", dataSetId)
437+
log.Debugw("Data set metadata exists, marking all subpieces as needing indexing", "dataSetId", dataSetId)
441438
subPieceRefIDs := make([]int64, 0, len(subPieceInfoMap))
442439
for _, info := range subPieceInfoMap {
443440
subPieceRefIDs = append(subPieceRefIDs, info.PDPPieceRefID)
@@ -452,13 +449,13 @@ func (p *PDPService) handleAddPieceToDataSet(w http.ResponseWriter, r *http.Requ
452449
}, harmonydb.OptionRetry())
453450

454451
if err != nil {
455-
logAdd.Errorw("Failed to insert into database", "error", err, "txHash", txHashLower, "subPieces", subPieceInfoMap)
452+
log.Errorw("Failed to insert into database", "error", err, "txHash", txHashLower, "subPieces", subPieceInfoMap)
456453
http.Error(w, "Internal server error", http.StatusInternalServerError)
457454
return
458455
}
459456

460457
if !comm {
461-
logAdd.Errorw("Failed to commit database transaction", "txHash", txHashLower)
458+
log.Errorw("Failed to commit database transaction", "txHash", txHashLower)
462459
http.Error(w, "Internal server error", http.StatusInternalServerError)
463460
return
464461
}

pdp/handlers_create.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ import (
1414

1515
"github.com/ethereum/go-ethereum/common"
1616
"github.com/ethereum/go-ethereum/core/types"
17-
logger "github.com/ipfs/go-log/v2"
1817

1918
"github.com/filecoin-project/curio/harmony/harmonydb"
2019
"github.com/filecoin-project/curio/pdp/contract"
2120
)
2221

23-
var logCreate = logger.Logger("pdp/create")
24-
2522
// handleCreateDataSetAndAddPieces handles the creation of a new data set and adding pieces at the same time
2623
func (p *PDPService) handleCreateDataSetAndAddPieces(w http.ResponseWriter, r *http.Request) {
2724
ctx := r.Context()
@@ -83,16 +80,16 @@ func (p *PDPService) handleCreateDataSetAndAddPieces(w http.ResponseWriter, r *h
8380
// Check if indexing is needed by decoding the extraData
8481
mustIndex, err := CheckIfIndexingNeededFromExtraData(extraDataBytes)
8582
if err != nil {
86-
logCreate.Warnw("Failed to check if indexing is needed from extraData, skipping indexing", "error", err)
83+
log.Warnw("Failed to check if indexing is needed from extraData, skipping indexing", "error", err)
8784
mustIndex = false
8885
}
8986
if mustIndex {
90-
logCreate.Infow("ExtraData contains withIPFSIndexing metadata, pieces will be marked for indexing")
87+
log.Infow("ExtraData contains withIPFSIndexing metadata, pieces will be marked for indexing")
9188
}
9289

9390
pieceDataArray, subPieceInfoMap, err := p.transformAddPiecesRequest(ctx, serviceLabel, reqBody.Pieces)
9491
if err != nil {
95-
logCreate.Warnf("Failed to process AddPieces request data: %+v", err)
92+
log.Warnf("Failed to process AddPieces request data: %+v", err)
9693
http.Error(w, "Failed to process request: "+err.Error(), http.StatusBadRequest)
9794
return
9895
}
@@ -128,12 +125,12 @@ func (p *PDPService) handleCreateDataSetAndAddPieces(w http.ResponseWriter, r *h
128125
txHash, err := p.sender.Send(workCtx, fromAddress, tx, reason)
129126
if err != nil {
130127
http.Error(w, "Failed to send transaction: "+err.Error(), http.StatusInternalServerError)
131-
logCreate.Errorf("Failed to send transaction: %+v", err)
128+
log.Errorf("Failed to send transaction: %+v", err)
132129
return
133130
}
134131

135132
txHashLower := strings.ToLower(txHash.Hex())
136-
logCreate.Infow("PDP CreateDataSet: Inserting transaction tracking",
133+
log.Infow("PDP CreateDataSet: Inserting transaction tracking",
137134
"txHash", txHashLower,
138135
"service", serviceLabel,
139136
"recordKeeper", recordKeeperAddr.Hex())
@@ -151,7 +148,7 @@ func (p *PDPService) handleCreateDataSetAndAddPieces(w http.ResponseWriter, r *h
151148

152149
// Enable indexing if the extraData indicates indexing is needed
153150
if mustIndex {
154-
logCreate.Debugw("ExtraData metadata indicates indexing needed, marking all subpieces as needing indexing")
151+
log.Debugw("ExtraData metadata indicates indexing needed, marking all subpieces as needing indexing")
155152
subPieceRefIDs := make([]int64, 0, len(subPieceInfoMap))
156153
for _, info := range subPieceInfoMap {
157154
subPieceRefIDs = append(subPieceRefIDs, info.PDPPieceRefID)
@@ -165,13 +162,13 @@ func (p *PDPService) handleCreateDataSetAndAddPieces(w http.ResponseWriter, r *h
165162
}, harmonydb.OptionRetry())
166163

167164
if err != nil {
168-
logCreate.Errorf("Failed to insert into message_waits_eth, pdp_data_set_piece_adds and pdp_data_set_creates: %+v", err)
165+
log.Errorf("Failed to insert into message_waits_eth, pdp_data_set_piece_adds and pdp_data_set_creates: %+v", err)
169166
http.Error(w, "Internal server error", http.StatusInternalServerError)
170167
return
171168
}
172169

173170
if !comm {
174-
logCreate.Error("Failed to commit database transaction")
171+
log.Error("Failed to commit database transaction")
175172
http.Error(w, "Internal server error", http.StatusInternalServerError)
176173
return
177174
}
@@ -189,7 +186,7 @@ func decodeExtraData(extraDataString *string) ([]byte, error) {
189186
extraDataHexStr := *extraDataString
190187
decodedBytes, err := hex.DecodeString(strings.TrimPrefix(extraDataHexStr, "0x"))
191188
if err != nil {
192-
logCreate.Errorf("Failed to decode hex extraData: %v", err)
189+
log.Errorf("Failed to decode hex extraData: %v", err)
193190
return nil, err
194191
}
195192
return decodedBytes, nil
@@ -296,13 +293,13 @@ func (p *PDPService) handleCreateDataSet(w http.ResponseWriter, r *http.Request)
296293
txHash, err := p.sender.Send(workCtx, fromAddress, tx, reason)
297294
if err != nil {
298295
http.Error(w, "Failed to send transaction: "+err.Error(), http.StatusInternalServerError)
299-
logCreate.Errorf("Failed to send transaction: %+v", err)
296+
log.Errorf("Failed to send transaction: %+v", err)
300297
return
301298
}
302299

303300
// Step 6: Insert into message_waits_eth and pdp_data_set_creates
304301
txHashLower := strings.ToLower(txHash.Hex())
305-
logCreate.Infow("PDP CreateDataSet: Inserting transaction tracking",
302+
log.Infow("PDP CreateDataSet: Inserting transaction tracking",
306303
"txHash", txHashLower,
307304
"service", serviceLabel,
308305
"recordKeeper", recordKeeperAddr.Hex())
@@ -318,13 +315,13 @@ func (p *PDPService) handleCreateDataSet(w http.ResponseWriter, r *http.Request)
318315
}, harmonydb.OptionRetry())
319316

320317
if err != nil {
321-
logCreate.Errorf("Failed to insert database tracking records: %+v", err)
318+
log.Errorf("Failed to insert database tracking records: %+v", err)
322319
http.Error(w, "Internal server error", http.StatusInternalServerError)
323320
return
324321
}
325322

326323
if !comm {
327-
logCreate.Error("Failed to commit database transaction")
324+
log.Error("Failed to commit database transaction")
328325
http.Error(w, "Internal server error", http.StatusInternalServerError)
329326
return
330327
}
@@ -337,15 +334,15 @@ func (p *PDPService) handleCreateDataSet(w http.ResponseWriter, r *http.Request)
337334
// insertMessageWaitsAndDataSetCreate inserts records into message_waits_eth and pdp_data_set_creates
338335
func (p *PDPService) insertMessageWaitsAndDataSetCreate(tx *harmonydb.Tx, txHashHex string, serviceLabel string) error {
339336
// Insert into message_waits_eth
340-
logCreate.Debugw("Inserting into message_waits_eth",
337+
log.Debugw("Inserting into message_waits_eth",
341338
"txHash", txHashHex,
342339
"status", "pending")
343340
n, err := tx.Exec(`
344341
INSERT INTO message_waits_eth (signed_tx_hash, tx_status)
345342
VALUES ($1, $2)
346343
`, txHashHex, "pending")
347344
if err != nil {
348-
logCreate.Errorw("Failed to insert into message_waits_eth",
345+
log.Errorw("Failed to insert into message_waits_eth",
349346
"txHash", txHashHex,
350347
"error", err)
351348
return err
@@ -356,15 +353,15 @@ func (p *PDPService) insertMessageWaitsAndDataSetCreate(tx *harmonydb.Tx, txHash
356353
}
357354

358355
// Insert into pdp_data_set_creates
359-
logCreate.Debugw("Inserting into pdp_data_set_creates",
356+
log.Debugw("Inserting into pdp_data_set_creates",
360357
"txHash", txHashHex,
361358
"service", serviceLabel)
362359
n, err = tx.Exec(`
363360
INSERT INTO pdp_data_set_creates (create_message_hash, service)
364361
VALUES ($1, $2)
365362
`, txHashHex, serviceLabel)
366363
if err != nil {
367-
logCreate.Errorw("Failed to insert into pdp_data_set_creates",
364+
log.Errorw("Failed to insert into pdp_data_set_creates",
368365
"txHash", txHashHex,
369366
"error", err)
370367
return err
@@ -374,7 +371,7 @@ func (p *PDPService) insertMessageWaitsAndDataSetCreate(tx *harmonydb.Tx, txHash
374371
return fmt.Errorf("expected 1 row to be inserted into pdp_data_set_creates, got %d", n)
375372
}
376373

377-
logCreate.Infow("Successfully inserted transaction tracking records",
374+
log.Infow("Successfully inserted transaction tracking records",
378375
"txHash", txHashHex,
379376
"service", serviceLabel)
380377
return nil

pdp/handlers_upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/go-chi/chi/v5"
1717
"github.com/google/uuid"
1818
"github.com/ipfs/go-cid"
19-
logger "github.com/ipfs/go-log/v2"
19+
logging "github.com/ipfs/go-log/v2"
2020
"github.com/multiformats/go-multicodec"
2121
"github.com/multiformats/go-multihash"
2222
"github.com/yugabyte/pgx/v5"
@@ -30,7 +30,7 @@ import (
3030
"github.com/filecoin-project/curio/lib/proof"
3131
)
3232

33-
var log = logger.Logger("pdp")
33+
var log = logging.Logger("pdpv0")
3434

3535
// PieceSizeLimit in bytes
3636
var PieceSizeLimit = abi.PaddedPieceSize(proof.MaxMemtreeSize).Unpadded()

tasks/pdpv0/notify_task.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"net/http"
99
"time"
1010

11-
logger "github.com/ipfs/go-log/v2"
11+
logging "github.com/ipfs/go-log/v2"
1212
"golang.org/x/xerrors"
1313

1414
"github.com/filecoin-project/curio/harmony/harmonydb"
@@ -18,7 +18,7 @@ import (
1818
"github.com/filecoin-project/curio/lib/promise"
1919
)
2020

21-
var log = logger.Logger("pdp")
21+
var log = logging.Logger("pdpv0")
2222

2323
// NotifyPollInterval is how often to poll for uploads ready to finalize.
2424
var NotifyPollInterval = 2 * time.Second

0 commit comments

Comments
 (0)