Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Blockheight and Version #11

Merged
merged 7 commits into from
Aug 26, 2024
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
3 changes: 2 additions & 1 deletion internal/light-client/event-listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (el *EventListener) ProcessLogs() {

log.Debugf("Event ChainID: %v", event.ChainId)
log.Debugf("Event StorageURL: %v", event.StorageURL)
log.Debugf("Event BlockHeight: %v", event.BlockHeight)

// strip the ipfs://
parsedURL, err := url.Parse(event.StorageURL)
Expand All @@ -107,6 +108,6 @@ func (el *EventListener) ProcessLogs() {
continue
}

el.sampler.ProcessEvent(parsedURL.Host)
el.sampler.ProcessEvent(parsedURL.Host, event.BlockHeight)
}
}
13 changes: 9 additions & 4 deletions internal/light-client/publisher/publisher.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package publisher

import (
"cloud.google.com/go/pubsub"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/covalenthq/das-ipfs-pinner/common"
"google.golang.org/api/option"
"io"
"os"
"time"

"cloud.google.com/go/pubsub"
"google.golang.org/api/option"
)

type Publisher struct {
Expand All @@ -29,6 +30,8 @@ type message struct {
Commitment string `json:"commitment"`
Proof string `json:"proof"`
Cell string `json:"cell"`
BlockHeight uint64 `json:"block_height"`
Version string `json:"version"`
}

// Define a struct with only the `project_id` field
Expand Down Expand Up @@ -66,7 +69,7 @@ func NewPublisher(topicID, credsFile, clientId string) (*Publisher, error) {
}

// Publish to Pubsub
func (p *Publisher) PublishToCS(cid string, rowIndex int, colIndex int, status bool, commitment []byte, proof []byte, cell []byte) error {
func (p *Publisher) PublishToCS(cid string, rowIndex int, colIndex int, status bool, commitment []byte, proof []byte, cell []byte, blockHeight uint64) error {
ctx := context.Background()

// Create a Pub/Sub client using the credentials
Expand All @@ -89,6 +92,8 @@ func (p *Publisher) PublishToCS(cid string, rowIndex int, colIndex int, status b
Commitment: base64.StdEncoding.EncodeToString(commitment),
Proof: base64.StdEncoding.EncodeToString(proof),
Cell: base64.StdEncoding.EncodeToString(cell),
BlockHeight: blockHeight,
Version: fmt.Sprintf("%s-%s", common.Version, common.GitCommit),
}

// Marshal the message into JSON.
Expand Down
4 changes: 2 additions & 2 deletions internal/light-client/sampler/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewSampler(ipfsAddr string, samplingDelay uint, pub *publisher.Publisher) (
}

// ProcessEvent handles events asynchronously by processing the provided CID.
func (s *Sampler) ProcessEvent(cidStr string) {
func (s *Sampler) ProcessEvent(cidStr string, blockHeight uint64) {
go func(cidStr string) {
rawCid, err := cid.Decode(cidStr)
if err != nil {
Expand Down Expand Up @@ -160,7 +160,7 @@ func (s *Sampler) ProcessEvent(cidStr string) {

log.Infof("Verification result for [%d, %d]: %v", rowindex, colindex, res)

if err := s.pub.PublishToCS(cidStr, rowindex, colindex, res, commitment, proof, cell); err != nil {
if err := s.pub.PublishToCS(cidStr, rowindex, colindex, res, commitment, proof, cell, blockHeight); err != nil {
log.Errorf("Failed to publish to Cloud Storage: %v", err)
return
}
Expand Down
Loading