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

feat(blockstore): implement blockstore #85

Merged
merged 3 commits into from
Sep 17, 2014
Merged

feat(blockstore): implement blockstore #85

merged 3 commits into from
Sep 17, 2014

Conversation

btc
Copy link
Contributor

@btc btc commented Sep 16, 2014

This PR adds a simple datastore wrapper so we don't need to repeat boilerplate pack/unpacking in places where the datastore is used.

type Blockstore interface {
    Get(u.Key) (*blocks.Block, error)
    Put(blocks.Block) error
}

How is this different from the blockservice?

The blockservice falls back to querying the exchange (bitswap) when values aren't present in the blockstore.

Where does this belong?

I'm not so sure myself. Either as a top-level package or as as util/blockstore. Due to circular dependencies there are a number of places where it certainly cannot go (dht, bitswap, blockservice, etc.)

@btc btc added the status/in-progress In progress label Sep 16, 2014
@jbenet
Copy link
Member

jbenet commented Sep 16, 2014

lol, LGTM. i think top level or under util/blockservice both make sense

@btc btc added codereview and removed status/in-progress In progress labels Sep 16, 2014
@btc btc self-assigned this Sep 16, 2014
// behavior in tests. Thus, it is left up to the caller to select the msgData
// that will determine the blocks key.
func NewBlockOrFail(t *testing.T, msgData string) blocks.Block {
block, blockCreationErr := blocks.NewBlock([]byte(msgData))
Copy link
Member

Choose a reason for hiding this comment

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

Im curious what input data could lead to a 'bad' block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Multihash sum only fails when given an invalid hash type. Which, if were calling util.Hash, is guaranteed to be valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we prove the code can't regress?

If multihash stipulates in its contract that it can fail, it's something we have to respect. If the belief is that multihash could provide a stronger contract, it's something to inspect within go-multihash. From the looks of it, the mh's error is there to guard against modifications that break that lib.

Copy link
Member

Choose a reason for hiding this comment

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

hmm... no. but if thats something we are worried about, throwing tests around util.Hash might be a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would tests around util.Hash remove the need to bubble up util.Hash's error return value when the function is used?

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I feel like they would. Just my opinion though.

Copy link
Member

Choose a reason for hiding this comment

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

Also, since we are vendoring multihash, we should do our due dilligence to make sure we arent updating a version of a lib that may break our code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are the benefits of ignoring the error?

If a function can return an error, the caller should explicitly handle that error. It's never a good idea to start making exceptions to this rule. When callers start ignoring the contracts stipulated by the libraries they use, the system becomes a house of cards.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, i agree with that. I was just being a proponent of adding more tests, including around util.Hash

@btc
Copy link
Contributor Author

btc commented Sep 17, 2014

SGTM

@jbenet @whyrusleeping LGTU?

@jbenet
Copy link
Member

jbenet commented Sep 17, 2014

LGTM except for:

careful, it's not threadsafe. i think this thing will get used all over the place. I think it may be useful to either add an internal mutex, or just wrap the incoming datastore in a LockDatastore that does this generically. (needs to be written, but trivial)

@whyrusleeping
Copy link
Member

Oh yeah, this would be the perfect place to add thread safety to the datastores.

@btc
Copy link
Contributor Author

btc commented Sep 17, 2014

Created an issue to remind us to address the thread-safety issues.

#87

Still, these changes here are a strict improvment over the existing state of affairs. Let's merge this one in for now. Ready when you are. @jbenet

btc pushed a commit that referenced this pull request Sep 17, 2014
feat(blockstore): implement blockstore
@btc btc merged commit 2a7dcb0 into master Sep 17, 2014
@btc btc removed the codereview label Sep 17, 2014
@btc btc deleted the feat/blockstore branch September 17, 2014 04:22
@btc btc removed their assignment Mar 30, 2015
ribasushi pushed a commit that referenced this pull request Jul 4, 2021
This time I've actually tested this as best I can (without, you know, adding
actual unit tests).

fixes #85
ariescodescream pushed a commit to ariescodescream/go-ipfs that referenced this pull request Oct 23, 2021
gx: update go-cid, go-multibase, base32
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
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

Successfully merging this pull request may close these issues.

3 participants