Skip to content

Commit

Permalink
celestia-node 0.15.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferret-san committed Aug 16, 2024
1 parent 3ab47c9 commit 5547ee1
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 528 deletions.
36 changes: 19 additions & 17 deletions cmd/ipfshelper/ipfshelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"sync"

"github.com/ethereum/go-ethereum/log"
iface "github.com/ipfs/boxo/coreiface"
"github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/files"
"github.com/ipfs/interface-go-ipfs-core/path"
"github.com/ipfs/boxo/path"
"github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/core"
"github.com/ipfs/kubo/core/coreapi"
iface "github.com/ipfs/kubo/core/coreiface"
"github.com/ipfs/kubo/core/coreiface/options"
"github.com/ipfs/kubo/core/node/libp2p"
"github.com/ipfs/kubo/plugin/loader"
"github.com/ipfs/kubo/repo"
Expand Down Expand Up @@ -155,8 +155,11 @@ func normalizeCidString(cidString string) string {

func (h *IpfsHelper) DownloadFile(ctx context.Context, cidString string, destinationDir string) (string, error) {
cidString = normalizeCidString(cidString)
cidPath := path.New(cidString)
resolvedPath, err := h.api.ResolvePath(ctx, cidPath)
cidPath, err := path.NewPath(cidString)
if err != nil {
return "", fmt.Errorf("failed to resolve cidPath: %w", err)
}
resolvedPath, _, err := h.api.ResolvePath(ctx, cidPath)
if err != nil {
return "", fmt.Errorf("failed to resolve path: %w", err)
}
Expand All @@ -180,7 +183,7 @@ func (h *IpfsHelper) DownloadFile(ctx context.Context, cidString string, destina
printProgress(0, len(links))
for i, j := range permutation {
link := links[j]
if err := h.api.Pin().Add(ctx, path.IpfsPath(link.Cid), options.Pin.Recursive(true)); err != nil {
if err := h.api.Pin().Add(ctx, path.FromCid(link.Cid), options.Pin.Recursive(true)); err != nil {
return "", fmt.Errorf("failed to pin child path: %w", err)
}
printProgress(i+1, len(links))
Expand All @@ -191,7 +194,7 @@ func (h *IpfsHelper) DownloadFile(ctx context.Context, cidString string, destina
return "", fmt.Errorf("could not get file with CID: %w", err)
}
log.Info("Writing file...")
outputFilePath := filepath.Join(destinationDir, resolvedPath.Cid().String())
outputFilePath := filepath.Join(destinationDir, resolvedPath.String())
_ = os.Remove(outputFilePath)
err = files.WriteTo(rootNodeDirectory, outputFilePath)
if err != nil {
Expand All @@ -201,14 +204,14 @@ func (h *IpfsHelper) DownloadFile(ctx context.Context, cidString string, destina
return outputFilePath, nil
}

func (h *IpfsHelper) AddFile(ctx context.Context, filePath string, includeHidden bool) (path.Resolved, error) {
func (h *IpfsHelper) AddFile(ctx context.Context, filePath string, includeHidden bool) (path.ImmutablePath, error) {
fileInfo, err := os.Stat(filePath)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}
fileNode, err := files.NewSerialFile(filePath, includeHidden, fileInfo)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}
return h.api.Unixfs().Add(ctx, fileNode)
}
Expand Down Expand Up @@ -263,13 +266,12 @@ func createIpfsHelperImpl(ctx context.Context, downloadPath string, clientOnly b
}

func CanBeIpfsPath(pathString string) bool {
path := path.New(pathString)
return path.IsValid() == nil ||
strings.HasPrefix(pathString, "/ipfs/") ||
strings.HasPrefix(pathString, "/ipld/") ||
strings.HasPrefix(pathString, "/ipns/") ||
strings.HasPrefix(pathString, "ipfs://") ||
strings.HasPrefix(pathString, "ipns://")
_, err := path.NewPath(pathString)
if err != nil {
log.Error("Error creating path", "err", fmt.Errorf("failed to resolve cidPath: %w", err))
return false
}
return true
}

// TODO break abstraction for now til we figure out what fns are needed
Expand Down
120 changes: 0 additions & 120 deletions cmd/ipfshelper/ipfshelper_test.go

This file was deleted.

5 changes: 4 additions & 1 deletion das/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ func (c *CelestiaDA) Store(ctx context.Context, message []byte) ([]byte, error)
// this will trigger node to use the default gas price from celestia app
gasPrice := -1.0
for !submitted {
height, err = c.Client.Blob.Submit(ctx, []*blob.Blob{dataBlob}, gasPrice)
// add submit options
submitOptions := &blob.SubmitOptions{}
blob.WithGasPrice(gasPrice)(submitOptions)
height, err = c.Client.Blob.Submit(ctx, []*blob.Blob{dataBlob}, submitOptions)
if err != nil {
switch {
case strings.Contains(err.Error(), ErrTxTimedout.Error()), strings.Contains(err.Error(), ErrTxAlreadyInMempool.Error()), strings.Contains(err.Error(), ErrTxIncorrectAccountSequence.Error()):
Expand Down
8 changes: 4 additions & 4 deletions das/ipfs_storage_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
iface "github.com/ipfs/boxo/coreiface"
"github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/path"
"github.com/ipfs/go-cid"
"github.com/ipfs/interface-go-ipfs-core/path"
iface "github.com/ipfs/kubo/core/coreiface"
"github.com/ipfs/kubo/core/coreiface/options"
"github.com/multiformats/go-multihash"
"github.com/offchainlabs/nitro/arbstate"
"github.com/offchainlabs/nitro/cmd/ipfshelper"
Expand Down Expand Up @@ -125,7 +125,7 @@ func (s *IpfsStorageService) GetByHash(ctx context.Context, hash common.Hash) ([
return nil, err
}

ipfsPath := path.IpfsPath(thisCid)
ipfsPath := path.FromCid(thisCid)
log.Trace("Retrieving IPFS path", "path", ipfsPath.String())

parentCtx := ctx
Expand Down
Loading

0 comments on commit 5547ee1

Please sign in to comment.