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

Outdated go-ipld-prime reference #22

Closed
eduardonunesp opened this issue Jul 16, 2021 · 4 comments
Closed

Outdated go-ipld-prime reference #22

eduardonunesp opened this issue Jul 16, 2021 · 4 comments

Comments

@eduardonunesp
Copy link

The reference to go-ipld-prime is outdated which is causing errors of compatibility with some components like ipld.LinkBuilder, ipld.Loader and ipld.Storer. Right now the version of go-ipld-prime is v0.10.0 and this repo is using the version v0.7.0.

Proof of concept

package main

import (
	"fmt"
	"testing"

	hamt "github.com/ipld/go-ipld-adl-hamt"
	ipld "github.com/ipld/go-ipld-prime"
	_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
)

func errCheck(err error) {
	if err != nil {
		panic(err)
	}
}

func basicValue(node ipld.Node) interface{} {
	if node == nil {
		panic("unexpected nil ipld.Node")
	}
	var val interface{}
	var err error
	switch kind := node.Kind(); kind {
	case ipld.Kind_Null:
		return nil
	case ipld.Kind_Bool:
		val, err = node.AsBool()
	case ipld.Kind_Int:
		val, err = node.AsInt()
	case ipld.Kind_Float:
		val, err = node.AsFloat()
	case ipld.Kind_String:
		val, err = node.AsString()
	case ipld.Kind_Bytes:
		val, err = node.AsBytes()
	default:
		panic(fmt.Sprintf("node does not have a basic kind: %v\n", kind))
	}
	errCheck(err)
	return val
}

func main(t *testing.T) {
	t.Parallel()

	builder := hamt.Prototype{}.NewBuilder()
	assembler, err := builder.BeginMap(0)
	errCheck(err)

	assembler.AssembleKey().AssignString("foo")
	assembler.AssembleValue().AssignString("bar")
	assembler.Finish()

	node := builder.Build()

	valNode, err := node.LookupByString("foo")
	errCheck(err)
	val := basicValue(valNode)
	fmt.Println("val", val)
}
$ go build
# github.com/ipld/go-ipld-adl-hamt
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/builder.go:77:38: undefined: ipld.LinkBuilder
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/builder.go:77:63: undefined: ipld.Loader
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/builder.go:77:83: undefined: ipld.Storer
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:23:14: undefined: ipld.LinkBuilder
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:24:14: undefined: ipld.Loader
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:25:14: undefined: ipld.Storer
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:28:35: undefined: ipld.LinkBuilder
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:28:60: undefined: ipld.Loader
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:28:80: undefined: ipld.Storer
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:197:23: element.x.Load undefined (type ipld.Link has no field or method Load)
../../.go/pkg/mod/github.com/ipld/go-ipld-adl-hamt@v0.0.0-20210329145020-b2c8ddbaab06/node.go:197:23: too many errors```
@willscott
Copy link
Member

this hamt library is currently used primarily within a lotus context. That larger ecosystem of code remains stuck on ipld-prime v0.7 until the merge of filecoin-project/lotus#6375

@eduardonunesp
Copy link
Author

I thought that lotus project was based on https://github.com/filecoin-project/go-hamt-ipld, any chance to guys help me to update for new ipld, looks like the linking stuff was largely updated

mvdan added a commit that referenced this issue Jul 18, 2021
This mainly adapts the codebase to use LinkSystem, a breaking change
introduced in v0.9.0 back in March 2021.

The public API needs to change a little bit too, accordingly.
Links should be loaded and created just as before,
and all tests continue passing with no changes.

Just one other breaking change to note: the codecs no longer expose an
"Encoder" func, as that's now "Encode".

Fixes #22.
@mvdan
Copy link
Contributor

mvdan commented Jul 18, 2021

@eduardonunesp you're right that all production use cases should be on the non-primified go-hamt-ipld for now, though one of the main benefits of this ADL is Filecoin compatibility, so we still want to remain compatible.

That said, you should be able to use the branch from #23 for the time being. Filecoin should upgrade its ipld-prime version over the next few weeks, at which point we'll be able to merge that PR.

@eduardonunesp
Copy link
Author

Thank you very much @mvdan and @willscott

mvdan added a commit that referenced this issue Jul 22, 2021
This mainly adapts the codebase to use LinkSystem, a breaking change
introduced in v0.9.0 back in March 2021.

The public API needs to change a little bit too, accordingly.
Links should be loaded and created just as before,
and all tests continue passing with no changes.

Just one other breaking change to note: the codecs no longer expose an
"Encoder" func, as that's now "Encode".

Finally, re-generate code.

Fixes #22.
mvdan added a commit that referenced this issue Jul 22, 2021
This mainly adapts the codebase to use LinkSystem, a breaking change
introduced in v0.9.0 back in March 2021.

The public API needs to change a little bit too, accordingly.
Links should be loaded and created just as before,
and all tests continue passing with no changes.

Just one other breaking change to note: the codecs no longer expose an
"Encoder" func, as that's now "Encode".

Finally, re-generate code.

Fixes #22.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants