@@ -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
133134func (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
315207func (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 )
0 commit comments