filecoin-project / go-data-transfer

Data Transfer Shared Component for go-filecoin & go-lotus
Other
39 stars 17 forks source link

Graphsync 2.0 refactors: Bind node part 2 - vouchers and voucher results #302

Open hannahhoward opened 2 years ago

hannahhoward commented 2 years ago

Goals

This ticket builds on #301 which adds to #300. Essentially the goal is to convert voucher/voucher result types to use go-ipld-prime schema.TypedNode.

Note that if we finish this, we now introduce breaking changes to consumers of go-data-transfer

On the other hand it continues to push usable of ipld-prime farther into the stack, removing our never ending mixing of cbor-gen & go-ipld-prime

Implementation

Currently, vouchers and voucher results are something of a bizarre type. It's based off the state of our serialization/IPLD libraries at the time go-data-transfer was first written.

  1. First, every voucher is an encoding.Encodable -- which is actually a blank interface. However, in reality, for the Encode method in the encoding package to work, Encodable must be either:
    • a go-class with cbor-gen methods
    • a go-ipld-prime node
    • a class that can write to CBOR with the old go-ipld-format

What a mess!

  1. Second, every voucher is a Registerable which is just an Encodable along with a Type method that returns a TypeIdentifier (just a string)

Oh the lack of tooling we had at the time!

Honestly, I think encoding.Encodable should just become a datamodel.Node and Registerable should just be a schema.TypedNode -- you can use Type().TypeName() to get an identifier.

There's basically two approaches to this PR -- one with a smaller change set and one with a larger one:

  1. Keep the names, but make them aliases for datamodel.Node and schema.TypedNode, and then just replace the way Encode, EncodeToNode (from #301 once complete) and the methods on the Decoder interface work (including the new one from #301 ). You'll need to make sure for schema.TypedNode that the encode methods uses the .Representation() form and the decode methods uses the Prototype.Regristration().NewBuilder()

  2. Go all in and remove the type names Encodable and Registerable entirely and replace it with direct IPLD references.

Either way, you may have to:

rvagg commented 2 years ago

FTR this has been going on in https://github.com/filecoin-project/go-data-transfer/pull/305, with further discussion over there about approaches