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

Feature/aggregated relays #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ volumes:
}
```

3. Execute the POST `/integrations/relayer/aggregated/relay` request with the following body to perform Iden3 issuer state publishing:

```json
{
"chain": "The name of chain submit to according to the service configuration",
"gist_hash": "The GIST hash (the same as on state contract) in 0x... hex format",
"state_hash": "The state hash (the same as on state contract) in 0x... hex format",
"waitConfirm": true
}
```

`"waitConfirm": true` - indicates if request should wait until transaction will be included into the block.
Default - `false`.

Expand Down
53 changes: 51 additions & 2 deletions docs/static/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@
"application/json"
],
"paths": {
"/integrations/relayer/aggregated/relay": {
"post": {
"operationId": "Service_AggregatedRelay",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MsgRelayResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/AggregatedRelayBody"
}
}
],
"tags": [
"Service"
]
}
},
"/integrations/relayer/gist/relay": {
"post": {
"operationId": "Service_GistRelay",
Expand Down Expand Up @@ -142,6 +174,23 @@
}
},
"definitions": {
"AggregatedRelayBody": {
"type": "object",
"properties": {
"gistHash": {
"type": "string"
},
"stateHash": {
"type": "string"
},
"chain": {
"type": "string"
},
"waitConfirm": {
"type": "boolean"
}
}
},
"MsgRelayResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -192,11 +241,11 @@
"properties": {
"@type": {
"type": "string",
"description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics."
"description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com. As of May 2023, there are no widely used type server\nimplementations and no plans to implement one.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics."
}
},
"additionalProperties": {},
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n // or ...\n if (any.isSameTypeAs(Foo.getDefaultInstance())) {\n foo = any.unpack(Foo.getDefaultInstance());\n }\n\nExample 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\nExample 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := anypb.New(foo)\n if err != nil {\n ...\n }\n ...\n foo := \u0026pb.Foo{}\n if err := any.UnmarshalTo(foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\nJSON\n\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n // or ...\n if (any.isSameTypeAs(Foo.getDefaultInstance())) {\n foo = any.unpack(Foo.getDefaultInstance());\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := anypb.New(foo)\n if err != nil {\n ...\n }\n ...\n foo := \u0026pb.Foo{}\n if err := any.UnmarshalTo(foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
},
"rpcStatus": {
"type": "object",
Expand Down
24 changes: 24 additions & 0 deletions internal/assets/migrations/003_aggregated.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- +migrate Up

create table aggregateds
(
gist text unique not null,
state_root text unique not null,
operation text unique not null,
confirmation text not null,
primary key (gist, state_root)
);

create table aggregated_transitions
(
tx text primary key not null,
gist text not null,
state_root text not null,
chain text not null
);

create index aggregated_transitions_index on aggregated_transitions (gist, state_root);

-- +migrate Down
drop table aggregateds;
drop table aggregated_transitions;
1 change: 1 addition & 0 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Run(args []string) bool {
case runAllCmd.FullCommand():
go ingester.NewService(cfg, ingester.NewStateIngester(cfg)).Run(ctx)
go ingester.NewService(cfg, ingester.NewGistIngester(cfg)).Run(ctx)
go ingester.NewService(cfg, ingester.NewAggregatedIngester(cfg)).Run(ctx)
err = services.NewServer(cfg).Run()
case migrateUpCmd.FullCommand():
err = MigrateUp(cfg)
Expand Down
34 changes: 34 additions & 0 deletions internal/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,37 @@ func (c *Core) GetIdentityGISTTransferProof(ctx context.Context, operationID str

return &result, nil
}

func (c *Core) GetIdentityAggregatedTransferProof(ctx context.Context, operationID string) (*IdentityAggregatedTransferDetails, error) {
proof, err := c.core.OperationProof(ctx, &rarimocore.QueryGetOperationProofRequest{Index: operationID})
if err != nil {
return nil, errors.Wrap(err, "failed to get the operation proof")
}

pathHashes := make([]common.Hash, 0, len(proof.Path))
for _, p := range proof.Path {
pathHashes = append(pathHashes, common.HexToHash(p))
}

signature := hexutil.MustDecode(proof.Signature)
signature[64] += 27

operation, err := c.core.Operation(context.Background(), &rarimocore.QueryGetOperationRequest{Index: operationID})
if err != nil {
return nil, errors.Wrap(err, "failed to get the operation")
}

transfer, err := pkg.GetIdentityAggregatedTransfer(operation.Operation)
if err != nil {
return nil, errors.Wrap(err, "failed to parse operation details")
}

result := IdentityAggregatedTransferDetails{Operation: transfer}

result.Proof, err = proofArgs.Pack(pathHashes, signature)
if err != nil {
return nil, errors.Wrap(err, "failed to encode the proof")
}

return &result, nil
}
5 changes: 5 additions & 0 deletions internal/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ type IdentityGISTTransferDetails struct {
Operation *rarimocore.IdentityGISTTransfer
Proof []byte
}

type IdentityAggregatedTransferDetails struct {
Operation *rarimocore.IdentityAggregatedTransfer
Proof []byte
}
4 changes: 2 additions & 2 deletions internal/data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package data

// docker run -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=postgres -p 5432:5432 postgres

//go:generate xo schema "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" -o ./ --single=schema.xo.go --src templates
//go:generate xo schema "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" -o pg --single=schema.xo.go --src=pg/templates --go-context=both
//go:generate xo schema "postgres://relayer:relayer@localhost:5435/relayer?sslmode=disable" -o ./ --single=schema.xo.go --src templates
//go:generate xo schema "postgres://relayer:relayer@localhost:5435/relayer?sslmode=disable" -o pg --single=schema.xo.go --src=pg/templates --go-context=both
Loading