-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add initial support for identity hashes. #4910
Conversation
@@ -189,14 +190,16 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error { | |||
opts.HasBloomFilterSize = 0 | |||
} | |||
|
|||
cbs, err := bstore.CachedBlockstore(ctx, bs, opts) | |||
wbs, err := bstore.CachedBlockstore(ctx, bs, opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does w
in wbs
stand for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"wrapped"
thirdparty/idstore/idstore.go
Outdated
} | ||
|
||
func (b *idstore) PutMany(bs []blocks.Block) error { | ||
var good []blocks.Block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd preallocate this to be the size of len(bs)
as in most cases most blocks will be in this array. I'd also call it toPut
or something like that, good
sounds weird to me in this context
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
thirdparty/idstore/idstore.go
Outdated
// idstore wraps a BlockStore to add support for identity hashes | ||
type idstore struct { | ||
bs bls.Blockstore | ||
} | ||
|
||
func IdStore(bs bls.Blockstore) bls.Blockstore { | ||
func IdStore(bs bls.Blockstore) *idstore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for exporting the implementation structure instead of the interface? It is generally better to export the interface as then it is clear what contract it follows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Changed back.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Note:
The error is for the wrapping directory entry, not the hash for the 64byte file. This works:
|
In particular for the ability to use the identity hash when the data is less than a certain threshold. License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
@Stebalien @whyrusleeping since id-hashes are primary useful as an optimization to inline tiny files I want ahead and added an option to add. This change touched a lot of files since it involved changing passing around the cid The add option now has a If you are okay with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working through this. The CidOpts
struct really rubs me the wrong way but I can't think of a better way to thread this through while keeping it configurable. Maybe push it down lower (into go-block-format)?
Does this only apply to raw blocks? Ideally, it would apply to all IPLD objects.
@@ -14,6 +14,7 @@ import ( | |||
dag "github.com/ipfs/go-ipfs/merkledag" | |||
dagtest "github.com/ipfs/go-ipfs/merkledag/test" | |||
mfs "github.com/ipfs/go-ipfs/mfs" | |||
cide "github.com/ipfs/go-ipfs/thirdparty/cidextra" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is temporary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More or less, I would like to get something working first, merge this p.r. and then worry about finding a better place for the two new packages in thirdparty.
core/commands/add.go
Outdated
@@ -119,6 +121,7 @@ You can now check what blocks have been created by: | |||
cmdkit.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"), | |||
cmdkit.IntOption(cidVersionOptionName, "CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)"), | |||
cmdkit.StringOption(hashOptionName, "Hash function to use. Implies CIDv1 if not sha2-256. (experimental)").WithDefault("sha2-256"), | |||
cmdkit.IntOption(idHashLimitOptionName, "Id hash maxium size. -1 disables. (experimental)").WithDefault(-1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I wouldn't make this this configurable. I'd have a fixed option and set the size to 64 bytes. I doubt there are any valid reasons for picking a non-standard value here (other than, maybe choosing between 32 bytes and 64 bytes). I would not allow more than 64 bytes as CIDs are supposed to be small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I will add an "--inline" option and keep this option, but set the default to 64.
Note there is an internal check that prevents this value from being set to the maximum id-hash size which is currently 64.
|
||
type Opts struct { | ||
cid.Prefix | ||
idHashThres int // 0 disables, otherwise 1 + limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the +1? Zero initialize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes to allow for zero initialization. As the type is exported there is nothing preventing the user from direct initialization.
return &idstore{bs} | ||
} | ||
|
||
func extractContents(k *cid.Cid) (bool, []byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably want to move this (and maybe a few other things) to, e.g., go-block
. We'll want this stuff usable outside of go-ipfs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my earlier comment, I want to first worry about getting something working and then we can move the my two new thirdparty packages to a better location.
It also applies to protobuf objects. |
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
We are cutting down I need to object introduction of code to |
@Stebalien @Kubuxu the intent of both |
@kevina in the meantime should it be possible for me to checkout f0a4f29 and build it locally to verify whether the web gateway will read my 3rd-party blocks with identity data mixed in? Basically asking whether I should expect that specific commit to just work as far as reading identity-containing blocks is concerned? |
@mib-kd743naq yes it should be. Before this commit id-hashes where actually supported, they just where not optimized. |
@Kubuxu @whyrusleeping @Stebalien since id hashes are possible to use without this p.r. there is the very real possibility that blockes with an id-hash could be stored in the datastore and never removed. I made the |
Why not just add that option on the idstore struct and write a small go test for it? |
Great stuff! You are indeed correct that identity hashes already work. E.g. this is a single block: There is a bit of work to be done around the CLI abort however. Observe:
The Thoughts? |
|
@kevina sorry, I meant |
@Stebalien I voted against a separate package and instead added the |
Fair enough (given that I've reviewed that, I should have remembered this...).
A |
I didn't think about creating those functions because they are not really needed (but can be useful). What I think should go in |
Ah. Yeah, good point. And making this a part of |
Closing in favor of #5117. |
Still a work in progress.
Tested by hand.
Needs shareness tests.
Closes #4697
I am breaking this p.r. into two parts. For part one see #5117, part two is pending.