Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

fix: block.put() options #793

Closed
wants to merge 2 commits into from
Closed

Conversation

mikeal
Copy link
Contributor

@mikeal mikeal commented Jun 23, 2018

So, this contains numerous fixes to block.put() some of which break the current tests because the tests are actually broken.

Prior to this patch, options passed in were simply ignored. The tests for those options showed false positives because the tests are passing in the default encoding values (dag-pb, sha2-256).

However, go-ipfs currently fails when trying to use /block/put for a dag node, you have to use /dag/put instead. So, I modified our block.put() API to check the format and call the dag put API instead, this is actually a good thing since the JS API for dag.put() does encoding for you which means adding this support to block.put() allows you to write already encoded dag nodes (which happens to be something I need anyway).

And now 3 tests are failing because those tests don't actually write a valid dag-pb node, they're just random junk buffers, and /dag/put actually validates them :)

I'll try to get around to fixing the tests and maybe writing a few extras as there's a few new features in here too (when you pass a Block instance it will use the attached cid, so you don't need to pass it in separately). But I won't get to that until next week and I wanted to get some eyeballs on this first.

@daviddias daviddias requested a review from alanshaw June 25, 2018 11:08
Copy link
Contributor

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies I didn't get round to this sooner - thanks very much for the PR 🚀 . The block API clearly needs a bit of ❤️ and attention!

hashAlg: opts.mhtype || 'sha2-256'
})

if (cid && CID.isCID(cid)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point cid could be a string, buffer or CID instance (spec). isCID only checks if the parameter is a CID instance, so currently the passed cid will be ignored if it's not a CID instance!


if (qs.format && qs.format.startsWith('dag-')) {
_send = SendOneFile(send, 'dag/put')
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mildly against adding this workaround here. I think it'll be unexpected for this method to call dag/put and without some comments or docs this behaviour will become confusing for contributors as well. It also sounds as though it's specific to go-ipfs and I'd rather not add implementation specific workarounds here in the API if we can avoid it. I'd like to know if js-ipfs has the same issue.

Is there an open issue in go-ipfs for this? It would be good to get this fixed there.

@alanshaw alanshaw mentioned this pull request Aug 30, 2018
@ghost ghost removed the ready label Sep 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants