Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Conversation

@jpeletier
Copy link
Contributor

@jpeletier jpeletier commented Jun 19, 2018

As agreed during Tuesday's roundtable review, I am fragmenting PR #704 in incremental steps to make it easier to review. The steps are these:

Steps 1-4 are created as PRs to mru-tmp-2 branch (PR #668) so the diff is viewed as incremental from that point, rather than from swarm-network-rewrite, which would include @nolash's work too and make it difficult to view what changes this PR exactly brings in.

This code is not fully refactored and "clean" as the one in PR #704. The objective of this PR is to capture the essence of this change and gather comments. Some of the issues you will see may already have been fixed.

For code that has moved, I will comment below where it has gone.

Thank you in advance for your time and patience in reviewing this. I hope you enjoy this feature!

@jpeletier jpeletier changed the title swarm/storage/mru: client-side mru signatures -- step 1/4 client-side mru signatures -- step 1/4 Jun 19, 2018
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This moved to updaterequest.go. At the end of the refactor in PR #704, it will end up where signatures actually take place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This moved to updaterequest.go. At the end of the refactor in PR #704, it will end up where signatures actually take place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these fields move to either resourceUpdate or resourceMetadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need this any more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This moved to resourcemetadata.go since it serializes a metadata chunk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also moved to resourcemetadata.go for the same reason above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bye bye ENS! :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed signer and headerGetter since we are not using ENS and also not signing inside Handler any more.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is storeTimeout gone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, what do you mean? I still see it in Handler

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I must have read the diff wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the hashPool as a shared singleton instance for the entire package so we can usit throughout mru. Package initializer init deals with creating the pool.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine, but I have a plan to move the hashpool to a separate package altogether common for all things swarm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's great, I was wondering if that hashpool concept could be shared throughout the whole app. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validator now also checks metadata chunks.
To be fixed: should check len(data) > 2 before looking at the first two bytes.

Copy link
Contributor

Choose a reason for hiding this comment

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

So now the "metadata chunk" isn't content addressed anymore? That's why we need the first two bytes (again)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The metadata chunk is still content addressed, however looking at the first two bytes at least saves calculating a hash if the incoming chunk doesn't look like a metadata chunk at first sight.

I am fine either way. We can do a hash and if it matches we mark as valid. What option would you choose?

Copy link
Contributor

@nolash nolash Jun 25, 2018

Choose a reason for hiding this comment

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

ah yes the update chunks are uint16 first two of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

parseUpdate now returns a SignedResourceUpdate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SignedResourceUpdate.Verify() deals with making sure the SignedResourceUpdate has a valid signature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ascertain ownership of the resource without having to lookup or query ENS.

In the later PR Steps, this is refactored so parseUpdate returns an error if all these checks fail, further simplifying the Validate handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed as the UpdateRequest structure takes care of these cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved all this to a new method of the new resourceMetadata structure. This method hashes and serializes the metadata in one go.
In later steps, this is further refactored, and newMetaChunk becomes a direct method of resourceMetadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this [8:] thing was driving me crazy, so now UnmarshalBinary takes care of it.

Copy link
Contributor

Choose a reason for hiding this comment

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

(chunk.SData+8) <3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check here is key to make sure we are creating an update that is ahead of what we already know exists

Copy link
Contributor

Choose a reason for hiding this comment

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

If I remember correctly code resembling this was also used in the LookupPrevious method(s). Could we share it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code in LookupPrevious doesn't look like this. What do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes right, LookupPrevious has it the other way around.

Copy link
Contributor

@nolash nolash left a comment

Choose a reason for hiding this comment

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

Please remove the binary.

I still need to go through the resource_test.go file

Copy link
Contributor

Choose a reason for hiding this comment

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

name should probably be newAccountManager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be refactored, maybe a different PR. The reason this is here and with this name is because it is a blatant copy of node.makeAccountManager, a private method of the node package and I didn't want to touch that package. Our problem is that the resource cli is the only command that uses accounts and private keys, and all the code to handle that is part of the Swarm node stuff.

A quick solution if you think others would agree is simply making that method public (?)

We would need a refactor whereupon account management is extracted out of the node domain and can be shared by the cli as well.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

We would need a refactor whereupon account management is extracted out of the node domain and can be shared by the cli as well.

Can we theoretically just sign with the RPC call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You need a private key. The idea of copying this was to reuse the account management code. So people using the swarm binary as a client can benefit of having their private keys in the same way as if they were running a node.

We can also disable this, but then users would need to point --bzzaccount to an unencrypted private key file, or we could have an additional parameter where the user can specify the path to their private key.

Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds like a wider discussion. Let's have a phone about this when all of this is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree

Copy link
Contributor

Choose a reason for hiding this comment

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

Why should there be an ephemeral dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That'd be a review question for whoever wrote that method ;-) see above to see what we do with this part of the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

A separate PR then. I'll try to remember %)

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion it is getting confusing to have all flags listed under the main command when some of them only are relevant for subcommands, like here. For example openssl has separate usage texts for different subcommands; openssl asn1parse --help openssl s_client --help. Maybe not in scope for this PR, but the relative obscurity of the resource functionality in cli, plus the fact that it's two levels of subcommands, highlights the issue even more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. The reason it is like that is that (for now), as far as I was able to see, the current cli parser captures all the flags and I couldn't put the --raw thing after the create or update command, which is what I would have liked. Do you know who could help us determine the best way to have a syntax like this:

swarm resource create --raw <name> <freq> <data>

The current cli parser would find the --raw after the create command and wouldn't let me have it there (screwed with the rest of the args)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind, I found out how to do it. It is now fixed directly in #704

Copy link
Contributor

Choose a reason for hiding this comment

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

"Create and update Mutable Resources"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. You'll see it directly in #704.

cmd/swarm/mru.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

--raw flag should be set per update, not per resource, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. What can be confusing is that, for the cli user, the create command actually creates a resource and sends off the first update in one go. I was hoping to simplify the interaction with this strategy.

Another approach would be to have a create command to create a resource which just returns the manifest hash and then the user has to invoke update to send the first update, otherwise the resource wouldn't have any content.

I am fine either way. The second approach is "cleaner": one command creates, other command updates, but also more complicated for a user. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another approach would be to have a create command to create a resource which just returns the manifest hash and then the user has to invoke update to send the first update, otherwise the resource wouldn't have any content

Yeah I remember pondering this too, and I too think it's cleaner. Let's go for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll implement this directly in #704.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nolash Finished modifying the CLI to decouple resource creation from updating according to these comments. The changes are in the last two commits of #704.
Creating a resource: swarm resource create <frequency> [--name <name>] [--data <0x Hexdata> [--rawmru]]
Updating a resource: swarm resource update <Manifest Address or ENS domain> <0x Hexdata> [--rawmru]
as you can see from the syntax, adding data during resource creation is now optional, but kept as a convenient way to create & initialize in one command.

Copy link
Contributor

Choose a reason for hiding this comment

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

cheeky but I like it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

B-)

Copy link
Contributor

Choose a reason for hiding this comment

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

hash a "new resourcehash" to get a "resourcehash" suggests slightly misleading namings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is refactored in #704 as follows:

  • New structure to hold the lookup components, UpdateLookup which contains version, period, rootAddr.
  • resourcehash -> UpdateLookup.GetUpdateAddr()
  • NewResourceHash is gone since the structure serializer is reused.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove obsolete comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gone. Multihash is now encoded explicitly as a flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe calculate these guys as global package vars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored in #704. Every structure has a very clear calculation of its length.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the multihash package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. Fixed in #704 and removed this function

@jpeletier jpeletier force-pushed the client-side-mru-step1 branch from f9235b1 to 782cbb3 Compare June 20, 2018 21:11
@jpeletier jpeletier changed the base branch from mru-publickey-in-key to mru-tmp-1 June 22, 2018 13:50
@jpeletier jpeletier requested a review from lmars as a code owner June 25, 2018 10:41
@nolash
Copy link
Contributor

nolash commented Jun 25, 2018

@zelig did you approve this earlier?

@nolash nolash requested a review from zelig June 25, 2018 12:29
@jpeletier
Copy link
Contributor Author

Note that you are only merging to the temp branch, so shouldn't be a big deal. 😉

@nolash nolash merged this pull request into ethersphere:mru-tmp-1 Jun 25, 2018
@jpeletier jpeletier changed the title client-side mru signatures -- step 1/4 client-side mru signatures -- step 1/5 Jun 26, 2018
@jpeletier jpeletier deleted the client-side-mru-step1 branch July 22, 2018 08:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants