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

Use type accAddress instead of hash.Hash for resources' hash #1704

Closed
wants to merge 9 commits into from

Conversation

NicolasMahe
Copy link
Member

@NicolasMahe NicolasMahe commented Mar 5, 2020

POC of replacing resource's hash.Hash by AccAddress.

@NicolasMahe NicolasMahe changed the title Feature/hash accaddress Use type accAddress instead of hash.Hash for resources' hash Mar 5, 2020

func TestHashSerialize(t *testing.T) {
require.Equal(t, "2:cosmos1ffzdc9fkggz2srlgp6grj32uc9sg9qvzu4jym8;3:eventKey;4:1:foo:3:bar;;;;", data.HashSerialize())
require.Equal(t, "cosmos186j7ddz0046caf63h566ez5nxd23svd44ga94h", sdk.AccAddress(crypto.AddressHash([]byte(data.HashSerialize()))).String())
Copy link
Member Author

@NicolasMahe NicolasMahe Mar 5, 2020

Choose a reason for hiding this comment

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

by default, the bech32 are using cosmos prefix.
we override it with:

cfg, err := config.New()
if err != nil {
	panic(err)
}
cosmos.CustomizeConfig(cfg)

I would like to extract the prefix from the config and hardcode them somewhere so we could override the cosmos's prefix in an init function.

Copy link
Member

@antho1404 antho1404 left a comment

Choose a reason for hiding this comment

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

I like the idea a few feedaback:

  • some validate:"required,accaddress" are missing in the proto, might be good to add them just in case.
  • remove the equal_all in proto, I'm ok but we need to make sure that we really don't use it.

In general I love this PR, one thing tho, Cosmos is migrating all its types in proto for the next release so I would wait for that, instead of breaking the API to break it again on the next cosmos version, let's wait for the next cosmos version and do all this work just once

e := &Event{
InstanceHash: instanceHash,
Key: eventKey,
Data: eventData,
}
e.Hash = hash.Dump(e)
e.Hash = sdk.AccAddress(crypto.AddressHash([]byte(e.HashSerialize())))
Copy link
Member

Choose a reason for hiding this comment

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

events might not be necessary but for the sake of normalization ok :)

@@ -45,20 +47,22 @@ func (b *Builder) Create(req *api.CreateRunnerRequest) (*runnerpb.Runner, error)
}

instanceEnv := xos.EnvMergeSlices(srv.Configuration.Env, req.Env)
envHash := hash.Dump(hashserializer.StringSlice(instanceEnv))
envHash := hash.Sum([]byte(strings.Join(instanceEnv, ",")))
Copy link
Member

Choose a reason for hiding this comment

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

why not doing the same here too ;)
this way we only have one hashing function, same that events that are not needed as a cosmos address but not bad representation anyway

@@ -268,9 +268,9 @@ func convertVolumesFrom(s *service.Service, dVolumesFrom []string) ([]container.
// volumeKey creates a key for service's volume based on the sid to make sure that the volume
// will stay the same for different versions of the service.
func volumeKey(s *service.Service, dependency, volume string) string {
return hash.Dump(hashserializer.StringSlice([]string{
return hash.Sum([]byte(strings.Join([]string{
Copy link
Member

Choose a reason for hiding this comment

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

here too, cosmos address can be use

runnerAddress := sdk.AccAddress(crypto.AddressHash(run.Hash))
serviceAddress := sdk.AccAddress(crypto.AddressHash(srv.Hash))
if err := k.distributePriceShares(ctx, execAddress, runnerAddress, serviceAddress, exec.Price); err != nil {
if err := k.distributePriceShares(ctx, exec.Hash, run.Hash, srv.Hash, exec.Price); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Love how simple it is now 😍

@NicolasMahe
Copy link
Member Author

closing but discussion continue here: #1715

@NicolasMahe NicolasMahe deleted the feature/hash-accaddress branch March 10, 2020 05:32
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.

2 participants