Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 0 additions & 228 deletions LHDealEngine.go

This file was deleted.

146 changes: 2 additions & 144 deletions xchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,106 +259,6 @@ func main() {
}
log.Printf("Tx %s included: %d", tx.Hash().Hex(), receipt.Status)

return nil
},
},
{
Name: "dealStatus",
Usage: "Check deal status for a specific CID",
ArgsUsage: "<cid> <offerId>",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "Path to the configuration file",
Value: "./config/config.json",
},
&cli.StringFlag{
Name: "chain",
Usage: "Name of the source blockchain (e.g., ethereum, polygon)",
Required: true,
},
},
Action: func(cctx *cli.Context) error {
cfg, err := config.LoadConfig(cctx.String("config"))
if err != nil {
log.Fatal(err)
}

cidString := cctx.Args().First()
if cidString == "" {
log.Printf("Please provide a CID to check deal status")
return nil
}

offerId := cctx.Args().Get(1)
if offerId == "" {
log.Printf("Please provide offerID to check deal status")
return nil
}

// Get chain name
chainName := cctx.String("chain")
srcCfg, err := config.GetSourceConfig(cfg, chainName)
if err != nil {
log.Fatalf("Invalid chain name '%s': %v", chainName, err)
}

//Request deal status from Lighthouse Deal Engine
log.Println("Start checking deal status and process aggregation for CID", cidString)
proofResponse, err := getDealStatus(cidString, cfg.LighthouseAuth)
if err != nil {
log.Fatalf("Error in GET request: %v", err)
}
commP, proofSubtree, err := ExtractProofDetail(proofResponse.Proof)
if err != nil {
fmt.Println("Error:", err)
return nil
}
log.Println("offer ID is ", offerId)
log.Println("commP is ", commP)
log.Println("proofSubtree is ", proofSubtree)

// Dial network
client, err := ethclient.Dial(srcCfg.Api)
if err != nil {
log.Fatalf("failed to connect to Ethereum client for source chain %s at %s: %v", chainName, srcCfg.Api, err)
}

// Load onramp contract handle
contractAddress := common.HexToAddress(srcCfg.OnRampAddress)
parsedABI, err := LoadAbi(cfg.OnRampABIPath)
if err != nil {
log.Fatal(err)
}

onramp := bind.NewBoundContract(contractAddress, *parsedABI, client, client, client)
if err != nil {
log.Fatal(err)
}

// Get auth
auth, err := loadPrivateKey(cfg)
if err != nil {
log.Fatal(err)
}

inclProofs := make([]merkletree.ProofData, 1)
ids := make([]uint64, 1)
ids[0] = 42
inclProofs[0] = proofSubtree

tx, err := onramp.Transact(auth, "commitAggregate", commP.Bytes(), ids, inclProofs, common.HexToAddress(cfg.PayoutAddr))
if err != nil {
return err
}

log.Printf("Waiting for transaction: %s\n", tx.Hash().Hex())
receipt, err := bind.WaitMined(cctx.Context, client, tx)
if err != nil {
log.Fatalf("failed to wait for tx: %v", err)
}
log.Printf("Tx %s committing aggregate commp %s included: %d", tx.Hash().Hex(), commP.String(), receipt.Status)

return nil
},
},
Expand Down Expand Up @@ -613,16 +513,11 @@ func (a *aggregator) run(ctx context.Context) error {
return err
})

// Start Lighthouse Deal Engine listener
// Start aggregatation event handling
g.Go(func() error {
return a.sendingToLighthouseDe(ctx)
return a.runAggregate(ctx)
})

// Start aggregatation event handling
// g.Go(func() error {
// return a.runAggregate(ctx)
// })

// Start handling data transfer requests
g.Go(func() error {
http.HandleFunc("/", a.transferHandler)
Expand Down Expand Up @@ -668,43 +563,6 @@ const (
dealDuration = 518400 // 6 months (on mainnet)
)

// No aggregation required, just sending cid to Lighthouse Deal Engine.
func (a *aggregator) sendingToLighthouseDe(ctx context.Context) error {
log.Println("Sending files to Lighthouse Deal Engine.")
log.Println("Events count = ", len(a.ch))

for {
select {
case <-ctx.Done():
log.Printf("ctx done shutting down Lighthouse Event Listener")
return nil
case latestEvent := <-a.ch:
log.Println("Processing Offer ", latestEvent.OfferID)
log.Println("Offer CID ", latestEvent.Offer.Cid)

// Check if the offer is too big to fit in a valid aggregate on its own
sendToLighthouseDE(latestEvent.Offer.Cid, a.LighthouseAuth)
}
}
}

// Request Deal Status from Lighthouse Engine and send PoDSI to onramp contract
func processDealStatus(ctx context.Context, cfg *config.Config, cid string) error {
//Request deal status from Lighthouse Deal Engine
proofResponse, err := getDealStatus(cid, cfg.LighthouseAuth)
if err != nil {
log.Fatalf("Error in GET request: %v", err)
}
// Print or log the response body
log.Printf("PoDSI Proof: %v", proofResponse.Proof)
log.Printf("Filecoin Deal: %v", proofResponse.FilecoinDeals)

// Log the end of the process
log.Println("Process completed successfully.")

return nil
}

func (a *aggregator) runAggregate(ctx context.Context) error {
// pieces being aggregated, flushed upon commitment
// Invariant: the pieces in the pending queue can always make a valid aggregate w.r.t a.targetDealSize
Expand Down
Loading