Skip to content

Commit ef848cf

Browse files
committed
chore: fix PDP v2.2.0 breaking changes
Resolve PDP v2.2.0 breaking changes
1 parent 834ff04 commit ef848cf

File tree

3 files changed

+36
-125
lines changed

3 files changed

+36
-125
lines changed

cmd/pdptool/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ func main() {
6666
uploadFileCmd, // upload a file to a pdp service in many chunks
6767
downloadFileCmd, // download a file from curio
6868

69-
createDataSetCmd, // create a new data set on the PDP service
69+
// createDataSetCmd, // REMOVED in PDP v2.2.0 - createDataSet() no longer exists
70+
// Datasets are now created implicitly when adding the first piece via addPieces
7071
getDataSetStatusCmd, // get the status of a data set creation on the PDP service
7172
getDataSetCmd, // retrieve the details of a data set from the PDP service
7273

@@ -885,6 +886,10 @@ var uploadFileCmd = &cli.Command{
885886
},
886887
}
887888

889+
// BREAKING CHANGE: createDataSet has been removed in PDP v2.2.0
890+
// Datasets are now created implicitly when adding the first piece via addPieces
891+
// To create a dataset, use the add-pieces command with your first piece
892+
/* DISABLED - createDataSetCmd removed in PDP v2.2.0
888893
var createDataSetCmd = &cli.Command{
889894
Name: "create-data-set",
890895
Usage: "Create a new data set on the PDP service",
@@ -982,6 +987,7 @@ var createDataSetCmd = &cli.Command{
982987
return nil
983988
},
984989
}
990+
*/
985991

986992
var getDataSetStatusCmd = &cli.Command{
987993
Name: "get-data-set-create-status",

pdp/handlers.go

Lines changed: 26 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strconv"
1414
"strings"
1515

16+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1617
"github.com/ethereum/go-ethereum/common"
1718
"github.com/ethereum/go-ethereum/core/types"
1819
"github.com/ethereum/go-ethereum/ethclient"
@@ -131,8 +132,6 @@ func (p *PDPService) handlePing(w http.ResponseWriter, r *http.Request) {
131132

132133
// handleCreateDataSet handles the creation of a new data set
133134
func (p *PDPService) handleCreateDataSet(w http.ResponseWriter, r *http.Request) {
134-
ctx := r.Context()
135-
136135
// Step 1: Verify that the request is authorized using ECDSA JWT
137136
serviceLabel, err := p.AuthService(r)
138137
if err != nil {
@@ -178,76 +177,16 @@ func (p *PDPService) handleCreateDataSet(w http.ResponseWriter, r *http.Request)
178177
return
179178
}
180179

181-
// Decode extraData if provided
182-
extraDataBytes := []byte{}
183-
if reqBody.ExtraData != nil {
184-
extraDataHexStr := *reqBody.ExtraData
185-
decodedBytes, err := hex.DecodeString(strings.TrimPrefix(extraDataHexStr, "0x"))
186-
if err != nil {
187-
log.Errorf("Failed to decode hex extraData: %v", err)
188-
http.Error(w, "Invalid extraData format (must be hex encoded)", http.StatusBadRequest)
189-
return
190-
}
191-
extraDataBytes = decodedBytes
192-
}
193-
194-
// Step 3: Get the sender address from 'eth_keys' table where role = 'pdp' limit 1
195-
fromAddress, err := p.getSenderAddress(ctx)
196-
if err != nil {
197-
http.Error(w, "Failed to get sender address: "+err.Error(), http.StatusInternalServerError)
198-
return
199-
}
200-
201-
// Step 4: Manually create the transaction without requiring a Signer
202-
// Obtain the ABI of the PDPVerifier contract
203-
abiData, err := contract.PDPVerifierMetaData.GetAbi()
204-
if err != nil {
205-
http.Error(w, "Failed to get contract ABI: "+err.Error(), http.StatusInternalServerError)
206-
return
207-
}
208-
209-
// Pack the method call data
210-
data, err := abiData.Pack("createDataSet", recordKeeperAddr, extraDataBytes)
211-
if err != nil {
212-
http.Error(w, "Failed to pack method call: "+err.Error(), http.StatusInternalServerError)
213-
return
214-
}
215-
216-
// Prepare the transaction (nonce will be set to 0, SenderETH will assign it)
217-
tx := types.NewTransaction(
218-
0,
219-
contract.ContractAddresses().PDPVerifier,
220-
contract.SybilFee(),
221-
0,
222-
nil,
223-
data,
224-
)
225-
226-
// Step 5: Send the transaction using SenderETH
227-
reason := "pdp-mkdataset"
228-
txHash, err := p.sender.Send(ctx, fromAddress, tx, reason)
229-
if err != nil {
230-
http.Error(w, "Failed to send transaction: "+err.Error(), http.StatusInternalServerError)
231-
log.Errorf("Failed to send transaction: %+v", err)
232-
return
233-
}
180+
// createDataSet() has been removed in PDP v2.2.0
181+
// Datasets are now created implicitly when the first piece is added via addPieces()
182+
// To create a dataset, use the /api/pdp/add-pieces endpoint instead.
234183

235-
// Step 6: Insert into message_waits_eth and pdp_data_set_creates
236-
txHashLower := strings.ToLower(txHash.Hex())
237-
log.Infow("PDP CreateDataSet: Inserting transaction tracking",
238-
"txHash", txHashLower,
184+
http.Error(w, "createDataSet is no longer supported in PDP v2.2.0. "+
185+
"Datasets are now created implicitly when adding the first piece. "+
186+
"Please use the /api/pdp/add-pieces endpoint instead.", http.StatusNotImplemented)
187+
log.Warnw("Attempt to use deprecated createDataSet endpoint",
239188
"service", serviceLabel,
240189
"recordKeeper", recordKeeperAddr.Hex())
241-
err = p.insertMessageWaitsAndDataSetCreate(ctx, txHashLower, serviceLabel)
242-
if err != nil {
243-
log.Errorf("Failed to insert into message_waits_eth and pdp_data_set_creates: %+v", err)
244-
http.Error(w, "Internal server error", http.StatusInternalServerError)
245-
return
246-
}
247-
248-
// Step 7: Respond with 201 Created and Location header
249-
w.Header().Set("Location", path.Join("/pdp/data-sets/created", txHashLower))
250-
w.WriteHeader(http.StatusCreated)
251190
}
252191

253192
// getSenderAddress retrieves the sender address from the database where role = 'pdp' limit 1
@@ -264,53 +203,6 @@ func (p *PDPService) getSenderAddress(ctx context.Context) (common.Address, erro
264203
return address, nil
265204
}
266205

267-
// insertMessageWaitsAndDataSetCreate inserts records into message_waits_eth and pdp_data_set_creates
268-
func (p *PDPService) insertMessageWaitsAndDataSetCreate(ctx context.Context, txHashHex string, serviceLabel string) error {
269-
// Begin a database transaction
270-
_, err := p.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (bool, error) {
271-
// Insert into message_waits_eth
272-
log.Debugw("Inserting into message_waits_eth",
273-
"txHash", txHashHex,
274-
"status", "pending")
275-
_, err := tx.Exec(`
276-
INSERT INTO message_waits_eth (signed_tx_hash, tx_status)
277-
VALUES ($1, $2)
278-
`, txHashHex, "pending")
279-
if err != nil {
280-
log.Errorw("Failed to insert into message_waits_eth",
281-
"txHash", txHashHex,
282-
"error", err)
283-
return false, err // Return false to rollback the transaction
284-
}
285-
286-
// Insert into pdp_data_set_creates
287-
log.Debugw("Inserting into pdp_data_set_creates",
288-
"txHash", txHashHex,
289-
"service", serviceLabel)
290-
_, err = tx.Exec(`
291-
INSERT INTO pdp_data_set_creates (create_message_hash, service)
292-
VALUES ($1, $2)
293-
`, txHashHex, serviceLabel)
294-
if err != nil {
295-
log.Errorw("Failed to insert into pdp_data_set_creates",
296-
"txHash", txHashHex,
297-
"error", err)
298-
return false, err // Return false to rollback the transaction
299-
}
300-
301-
log.Infow("Successfully inserted orphaned transaction for watching",
302-
"txHash", txHashHex,
303-
"service", serviceLabel,
304-
"waiter_machine_id", "NULL")
305-
// Return true to commit the transaction
306-
return true, nil
307-
}, harmonydb.OptionRetry())
308-
if err != nil {
309-
return err
310-
}
311-
return nil
312-
}
313-
314206
// handleGetDataSetCreationStatus handles the GET request to retrieve the status of a data set creation
315207
func (p *PDPService) handleGetDataSetCreationStatus(w http.ResponseWriter, r *http.Request) {
316208
ctx := r.Context()
@@ -947,16 +839,30 @@ func (p *PDPService) handleAddPieceToDataSet(w http.ResponseWriter, r *http.Requ
947839
pieceDataArray = append(pieceDataArray, pieceData)
948840
}
949841

950-
// Step 6: Prepare the Ethereum transaction
951-
// Pack the method call data
842+
// Step 6: Get the listener address for the dataset from the blockchain
843+
// PDP v2.2.0: addPieces now requires the listener address as a parameter
844+
pdpVerifier, err := contract.NewPDPVerifier(contract.ContractAddresses().PDPVerifier, p.ethClient)
845+
if err != nil {
846+
http.Error(w, "Failed to create PDPVerifier contract instance: "+err.Error(), http.StatusInternalServerError)
847+
return
848+
}
849+
850+
listenerAddr, err := pdpVerifier.GetDataSetListener(&bind.CallOpts{}, dataSetId)
851+
if err != nil {
852+
http.Error(w, "Failed to get dataset listener address: "+err.Error(), http.StatusInternalServerError)
853+
return
854+
}
855+
856+
// Step 7: Prepare the Ethereum transaction
857+
// Pack the method call data with the listener address (PDP v2.2.0 requirement)
952858
// The extraDataBytes variable is now correctly populated above
953-
data, err := abiData.Pack("addPieces", dataSetId, pieceDataArray, extraDataBytes)
859+
data, err := abiData.Pack("addPieces", dataSetId, listenerAddr, pieceDataArray, extraDataBytes)
954860
if err != nil {
955861
http.Error(w, "Failed to pack method call: "+err.Error(), http.StatusInternalServerError)
956862
return
957863
}
958864

959-
// Step 7: Get the sender address from 'eth_keys' table where role = 'pdp' limit 1
865+
// Step 8: Get the sender address from 'eth_keys' table where role = 'pdp' limit 1
960866
fromAddress, err := p.getSenderAddress(ctx)
961867
if err != nil {
962868
http.Error(w, "Failed to get sender address: "+err.Error(), http.StatusInternalServerError)

tasks/pdp/task_prove.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ func (p *ProveTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done
228228
log.Infof("PDP Prove Task: dataSetId: %d, taskID: %d, proofs: %s", dataSetId, taskID, proofStr)
229229
} */
230230

231-
// If gas used is 0 fee is maximized
232-
gasFee := big.NewInt(0)
231+
// PDP v2.2.0: calculateProofFee now only takes dataSetId (estimatedGasFee parameter removed)
232+
// The contract now calculates fees internally based on dataset size and feePerTiB
233233
pdpVerifierRaw := contract.PDPVerifierRaw{Contract: pdpVerifier}
234234

235235
calcProofFeeResult := make([]any, 0)
236-
err = pdpVerifierRaw.Call(callOpts, &calcProofFeeResult, "calculateProofFee", big.NewInt(dataSetId), gasFee)
236+
err = pdpVerifierRaw.Call(callOpts, &calcProofFeeResult, "calculateProofFee", big.NewInt(dataSetId))
237237
if err != nil {
238238
return false, xerrors.Errorf("failed to calculate proof fee: %w", err)
239239
}
@@ -296,7 +296,6 @@ func (p *ProveTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done
296296
"taskID", taskID,
297297
"proofs", proofLogs,
298298
"data", hex.EncodeToString(data),
299-
"gasFeeEstimate", gasFee,
300299
"proofFee initial", proofFee.Div(proofFee, big.NewInt(3)),
301300
"proofFee 3x", proofFee,
302301
"txEth", txEth,

0 commit comments

Comments
 (0)