Skip to content

Commit

Permalink
feat(connector-besu): add gRPC support for operations
Browse files Browse the repository at this point in the history
1. The Besu connector now can be reached via the gRPC interface.
2. The same operations are exposed as via HTTP+SocketIO
3. gRPC supports bi-directional streaming so the block watching is also
supported and test coverage verifies that it works.
4. To see an example of how to use the gRPC client of the Besu connector
read the source code of the test case that provides the verification that
the functionality works:
```
packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/
integration/grpc-services/connector-besu-grpc-services.test.ts
```

Depends on #3173

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed May 29, 2024
1 parent 6994e5b commit ab676d2
Show file tree
Hide file tree
Showing 107 changed files with 9,119 additions and 7 deletions.
15 changes: 13 additions & 2 deletions packages/cactus-plugin-ledger-connector-besu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,29 @@
],
"scripts": {
"benchmark": "tsx ./src/test/typescript/benchmark/run-plugin-ledger-connector-besu-benchmark.ts .tmp/benchmark-results/plugin-ledger-connector-besu/run-plugin-ledger-connector-besu-benchmark.ts.log",
"codegen": "run-p 'codegen:*'",
"codegen": "run-s 'codegen:*'",
"codegen:openapi": "npm run generate-sdk",
"generate-sdk": "run-p 'generate-sdk:*'",
"codegen:proto": "run-s proto:openapi proto:protoc-gen-ts",
"generate-sdk": "run-s 'generate-sdk:*'",
"generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore",
"proto:openapi": "yarn run --top-level openapi-generator-cli generate -i ./src/main/json/openapi.json -g protobuf-schema --model-name-suffix=PB --language-specific-primitives=google.protobuf.Any --type-mappings=AnyType=google.protobuf.Any --type-mappings=object=google.protobuf.Any --additional-properties=packageName=org.hyperledger.cacti.plugin.ledger.connector.besu -o ./src/main/proto/generated/openapi/ -t=./src/main/mustache/openapi-generator/templates/protobuf-schema/ --ignore-file-override ../../openapi-generator-ignore",
"proto:protoc-gen-ts": "yarn run --top-level grpc_tools_node_protoc --plugin=protoc-gen-ts=../../node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:./src/main/typescript/generated/proto/protoc-gen-ts/ --proto_path ./src/main/proto/generated/openapi/ --proto_path ./src/main/proto/generated/openapi/models/ --proto_path ./src/main/proto/ ./src/main/proto/generated/openapi/services/*.proto ./src/main/proto/services/*.proto",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev",
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web",
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js",
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js"
},
"dependencies": {
"@grpc/grpc-js": "1.10.3",
"@hyperledger/cactus-common": "2.0.0-alpha.2",
"@hyperledger/cactus-core": "2.0.0-alpha.2",
"@hyperledger/cactus-core-api": "2.0.0-alpha.2",
"axios": "1.6.0",
"express": "4.19.2",
"google-protobuf": "3.21.2",
"http-errors": "2.0.0",
"http-errors-enhanced-cjs": "2.0.1",
"joi": "17.9.1",
"openapi-types": "12.1.3",
"prom-client": "13.2.0",
Expand All @@ -78,16 +84,21 @@
"devDependencies": {
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-alpha.2",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.2",
"@openapitools/openapi-generator-cli": "2.7.0",
"@types/benchmark": "2.1.5",
"@types/body-parser": "1.19.4",
"@types/express": "4.17.21",
"@types/fs-extra": "9.0.13",
"@types/google-protobuf": "3.15.5",
"@types/http-errors": "2.0.4",
"@types/uuid": "9.0.8",
"benchmark": "2.1.4",
"body-parser": "1.20.2",
"fs-extra": "10.1.0",
"grpc-tools": "1.12.4",
"grpc_tools_node_protoc_ts": "5.3.3",
"key-encoder": "2.0.3",
"npm-run-all2": "6.1.2",
"protobufjs": "7.2.5",
"socket.io": "4.5.4",
"tsx": "4.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@
"Complete"
]
},
"WatchBlocksV1Request": {
"type": "object",
"required": ["event"],
"properties": {
"event": {
"$ref": "#/components/schemas/WatchBlocksV1"
}
}
},
"Web3BlockHeader": {
"type": "object",
"required": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{>partial_header}}
syntax = "proto3";

package {{#lambda.lowercase}}{{{packageName}}}.{{{apiPackage}}}.{{{classname}}};{{/lambda.lowercase}}

import "google/protobuf/empty.proto";
{{#imports}}
{{#import}}
import "{{{modelPackage}}}/{{{.}}}.proto";
{{/import}}
{{/imports}}

service {{classname}} {
{{#operations}}
{{#operation}}
{{#description}}
// {{{.}}}
{{/description}}
rpc {{operationId}} ({{#hasParams}}{{operationId}}Request{{/hasParams}}{{^hasParams}}google.protobuf.Empty{{/hasParams}}) returns ({{#vendorExtensions.x-grpc-response}}{{.}}{{/vendorExtensions.x-grpc-response}}{{^vendorExtensions.x-grpc-response}}{{operationId}}Response{{/vendorExtensions.x-grpc-response}});

{{/operation}}
{{/operations}}
}

{{#operations}}
{{#operation}}
{{#hasParams}}
message {{operationId}}Request {
{{#allParams}}
{{#description}}
// {{{.}}}
{{/description}}
{{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{paramName}} = {{vendorExtensions.x-protobuf-index}};
{{/allParams}}

}

{{/hasParams}}
{{^vendorExtensions.x-grpc-response}}
message {{operationId}}Response {
{{{vendorExtensions.x-grpc-response-type}}} data = 1;
}

{{/vendorExtensions.x-grpc-response}}
{{/operation}}
{{/operations}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{>partial_header}}
syntax = "proto3";

package {{#lambda.lowercase}}{{{packageName}}};{{/lambda.lowercase}}

import "google/protobuf/any.proto";

{{#imports}}
{{#import}}
import "{{{modelPackage}}}/{{{import}}}.proto";
{{/import}}
{{/imports}}

{{#models}}
{{#model}}
{{#isEnum}}{{>enum}}{{/isEnum}}{{^isEnum}}message {{classname}} {
{{#vars}}
{{#description}}
// {{{.}}}
{{/description}}
{{^isEnum}}
{{#vendorExtensions.x-protobuf-type}}{{{.}}} {{/vendorExtensions.x-protobuf-type}}{{{vendorExtensions.x-protobuf-data-type}}} {{{name}}} = {{vendorExtensions.x-protobuf-index}}{{#vendorExtensions.x-protobuf-packed}} [packed=true]{{/vendorExtensions.x-protobuf-packed}};
{{/isEnum}}
{{#isEnum}}
enum {{enumName}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = {{{protobuf-enum-index}}};
{{/enumVars}}
{{/allowableValues}}
}

{{enumName}} {{name}} = {{vendorExtensions.x-protobuf-index}};
{{/isEnum}}

{{/vars}}
}
{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{>partial_header}}
syntax = "proto3";

package {{{packageName}}};

{{#vendorExtensions.x-grpc-options}}
option {{{.}}};
{{/vendorExtensions.x-grpc-options}}

// Models
{{#models}}
{{#model}}
import "{{modelPackage}}/{{classFilename}}.proto";
{{/model}}
{{/models}}

// APIs
{{#apiInfo}}
{{#apis}}
import "{{apiPackage}}/{{classFilename}}.proto";
{{/apis}}
{{/apiInfo}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
README.md
models/besu_private_transaction_config_pb.proto
models/besu_transaction_config_pb.proto
models/besu_transaction_config_to_pb.proto
models/consistency_strategy_pb.proto
models/deploy_contract_solidity_bytecode_v1_request_pb.proto
models/deploy_contract_solidity_bytecode_v1_response_pb.proto
models/eth_contract_invocation_type_pb.proto
models/evm_block_pb.proto
models/evm_log_pb.proto
models/evm_transaction_pb.proto
models/get_balance_v1_request_pb.proto
models/get_balance_v1_response_pb.proto
models/get_besu_record_v1_request_pb.proto
models/get_besu_record_v1_response_pb.proto
models/get_block_v1_request_pb.proto
models/get_block_v1_response_pb.proto
models/get_past_logs_v1_request_pb.proto
models/get_past_logs_v1_response_pb.proto
models/get_transaction_v1_request_pb.proto
models/get_transaction_v1_response_pb.proto
models/invoke_contract_v1_request_pb.proto
models/invoke_contract_v1_response_pb.proto
models/receipt_type_pb.proto
models/run_transaction_request_pb.proto
models/run_transaction_response_pb.proto
models/sign_transaction_request_pb.proto
models/sign_transaction_response_pb.proto
models/solidity_contract_json_artifact_compiler_pb.proto
models/solidity_contract_json_artifact_gas_estimates_creation_pb.proto
models/solidity_contract_json_artifact_gas_estimates_pb.proto
models/solidity_contract_json_artifact_pb.proto
models/watch_blocks_v1_pb.proto
models/watch_blocks_v1_progress_pb.proto
models/watch_blocks_v1_request_pb.proto
models/web3_block_header_pb.proto
models/web3_block_header_timestamp_pb.proto
models/web3_signing_credential_cactus_keychain_ref_pb.proto
models/web3_signing_credential_none_pb.proto
models/web3_signing_credential_pb.proto
models/web3_signing_credential_private_key_hex_pb.proto
models/web3_signing_credential_type_pb.proto
models/web3_transaction_receipt_pb.proto
services/default_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.6.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# gPRC for org.hyperledger.cacti.plugin.ledger.connector.besu

Can perform basic tasks on a Besu ledger

## Overview
These files were generated by the [OpenAPI Generator](https://openapi-generator.tech) project.

- API version: v2.0.0-alpha.2
- Package version:
- Build package: org.openapitools.codegen.languages.ProtobufSchemaCodegen

## Usage

Below are some usage examples for Go and Ruby. For other languages, please refer to https://grpc.io/docs/quickstart/.

### Go
```
# assuming `protoc-gen-go` has been installed with `go get -u github.com/golang/protobuf/protoc-gen-go`
mkdir /var/tmp/go/org.hyperledger.cacti.plugin.ledger.connector.besu
protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.ledger.connector.besu services/*
protoc --go_out=/var/tmp/go/org.hyperledger.cacti.plugin.ledger.connector.besu models/*
```

### Ruby
```
# assuming `grpc_tools_ruby_protoc` has been installed via `gem install grpc-tools`
RUBY_OUTPUT_DIR="/var/tmp/ruby/org.hyperledger.cacti.plugin.ledger.connector.besu"
mkdir $RUBY_OUTPUT_DIR
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib services/*
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib models/*
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Hyperledger Cactus Plugin - Connector Besu
Can perform basic tasks on a Besu ledger
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.ledger.connector.besu;

import "google/protobuf/any.proto";


message BesuPrivateTransactionConfigPB {

string privateFrom = 360593360;

repeated google.protobuf.Any privateFor = 265462717;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Hyperledger Cactus Plugin - Connector Besu
Can perform basic tasks on a Besu ledger
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.ledger.connector.besu;

import "google/protobuf/any.proto";

import "models/besu_transaction_config_to_pb.proto";
import "models/web3_block_header_timestamp_pb.proto";

message BesuTransactionConfigPB {

string rawTransaction = 185047449;

Web3BlockHeaderTimestampPB from = 3151786;

BesuTransactionConfigToPB to = 3707;

Web3BlockHeaderTimestampPB value = 111972721;

Web3BlockHeaderTimestampPB gas = 102105;

Web3BlockHeaderTimestampPB gasPrice = 5271059;

float nonce = 105002991;

BesuTransactionConfigToPB data = 3076010;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Hyperledger Cactus Plugin - Connector Besu
Can perform basic tasks on a Besu ledger
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.ledger.connector.besu;

import "google/protobuf/any.proto";


message BesuTransactionConfigToPB {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Hyperledger Cactus Plugin - Connector Besu
Can perform basic tasks on a Besu ledger
The version of the OpenAPI document: v2.0.0-alpha.2
Generated by OpenAPI Generator: https://openapi-generator.tech
*/

syntax = "proto3";

package org.hyperledger.cacti.plugin.ledger.connector.besu;

import "google/protobuf/any.proto";

import "models/receipt_type_pb.proto";

message ConsistencyStrategyPB {

ReceiptTypePB receiptType = 423008661;

// The amount of milliseconds to wait for the receipt to arrive to the connector. Defaults to 0 which means to wait for an unlimited amount of time. Note that this wait may be interrupted still by other parts of the infrastructure such as load balancers cutting of HTTP requests after some time even if they are the type that is supposed to be kept alive. The question of re-entrance is a broader topic not in scope to discuss here, but it is important to mention it.
int32 timeoutMs = 51479271;

// The number of blocks to wait to be confirmed in addition to the block containing the transaction in question. Note that if the receipt type is set to only wait for node transaction pool ACK and this parameter is set to anything, but zero then the API will not accept the request due to conflicting parameters.
int32 blockConfirmations = 207555762;

}
Loading

0 comments on commit ab676d2

Please sign in to comment.