-
Notifications
You must be signed in to change notification settings - Fork 110
client-side mru signatures -- step 1/5 #732
client-side mru signatures -- step 1/5 #732
Conversation
swarm/storage/mru/resource.go
Outdated
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.
This moved to updaterequest.go. At the end of the refactor in PR #704, it will end up where signatures actually take place.
swarm/storage/mru/resource.go
Outdated
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.
This moved to updaterequest.go. At the end of the refactor in PR #704, it will end up where signatures actually take place.
swarm/storage/mru/resource.go
Outdated
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.
All these fields move to either resourceUpdate or resourceMetadata.
swarm/storage/mru/resource.go
Outdated
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 don't need this any more
swarm/storage/mru/resource.go
Outdated
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.
This moved to resourcemetadata.go since it serializes a metadata chunk
swarm/storage/mru/resource.go
Outdated
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.
This also moved to resourcemetadata.go for the same reason above
swarm/storage/mru/resource.go
Outdated
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.
bye bye ENS! :-)
swarm/storage/mru/resource.go
Outdated
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.
Removed signer and headerGetter since we are not using ENS and also not signing inside Handler any more.
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 is storeTimeout gone?
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.
Hmm, what do you mean? I still see it in Handler
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.
Sorry, I must have read the diff wrong.
swarm/storage/mru/resource.go
Outdated
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.
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.
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.
Fine, but I have a plan to move the hashpool to a separate package altogether common for all things swarm.
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.
That's great, I was wondering if that hashpool concept could be shared throughout the whole app. 👍
swarm/storage/mru/resource.go
Outdated
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.
Validator now also checks metadata chunks.
To be fixed: should check len(data) > 2 before looking at the first two bytes.
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.
So now the "metadata chunk" isn't content addressed anymore? That's why we need the first two bytes (again)?
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.
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?
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.
ah yes the update chunks are uint16 first two of course.
swarm/storage/mru/resource.go
Outdated
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.
parseUpdate now returns a SignedResourceUpdate
swarm/storage/mru/resource.go
Outdated
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.
SignedResourceUpdate.Verify() deals with making sure the SignedResourceUpdate has a valid signature
swarm/storage/mru/resource.go
Outdated
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.
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.
swarm/storage/mru/resource.go
Outdated
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.
Removed as the UpdateRequest structure takes care of these cases.
swarm/storage/mru/resource.go
Outdated
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.
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
swarm/storage/mru/resource.go
Outdated
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.
this [8:] thing was driving me crazy, so now UnmarshalBinary takes care of it.
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.
(chunk.SData+8) <3
swarm/storage/mru/resource.go
Outdated
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.
This check here is key to make sure we are creating an update that is ahead of what we already know exists
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.
If I remember correctly code resembling this was also used in the LookupPrevious method(s). Could we share it?
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.
Code in LookupPrevious doesn't look like this. What do you mean?
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 right, LookupPrevious has it the other way around.
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.
Please remove the binary.
I still need to go through the resource_test.go file
cmd/swarm/clientaccountmanager.go
Outdated
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.
name should probably be newAccountManager
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.
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?
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 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?
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.
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.
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.
This sounds like a wider discussion. Let's have a phone about this when all of this is done.
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, I agree
cmd/swarm/clientaccountmanager.go
Outdated
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 should there be an ephemeral dir?
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.
That'd be a review question for whoever wrote that method ;-) see above to see what we do with this part of the code.
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.
A separate PR then. I'll try to remember %)
cmd/swarm/main.go
Outdated
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.
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.
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 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)
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.
Never mind, I found out how to do it. It is now fixed directly in #704
cmd/swarm/main.go
Outdated
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.
"Create and update Mutable Resources"?
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.
Changed. You'll see it directly in #704.
cmd/swarm/mru.go
Outdated
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.
--raw flag should be set per update, not per resource, no?
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. 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?
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.
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.
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.
OK, I'll implement this directly in #704.
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.
@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.
swarm/storage/mru/resource.go
Outdated
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.
cheeky but I like it
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.
B-)
swarm/storage/mru/resource.go
Outdated
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.
hash a "new resourcehash" to get a "resourcehash" suggests slightly misleading namings
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.
This is refactored in #704 as follows:
- New structure to hold the lookup components,
UpdateLookupwhich containsversion,period,rootAddr. resourcehash->UpdateLookup.GetUpdateAddr()NewResourceHashis gone since the structure serializer is reused.
swarm/storage/mru/resource.go
Outdated
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.
Please remove obsolete comment
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.
gone. Multihash is now encoded explicitly as a flag.
swarm/storage/mru/resource.go
Outdated
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.
Maybe calculate these guys as global package vars
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.
Refactored in #704. Every structure has a very clear calculation of its length.
swarm/storage/mru/resource.go
Outdated
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 not use the multihash package?
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.
ok. Fixed in #704 and removed this function
f9235b1 to
782cbb3
Compare
Rebase to PR ethereum#668 and fix all conflicts
782cbb3 to
7781846
Compare
|
@zelig did you approve this earlier? |
|
Note that you are only merging to the temp branch, so shouldn't be a big deal. 😉 |
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:
LookupParamsso that the different combinations are documented. Moved LookupParams to its own file. Reorder code and create separate files for a few structuresSteps 1-4 are created as PRs to
mru-tmp-2branch (PR #668) so the diff is viewed as incremental from that point, rather than fromswarm-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!