Skip to content

Commit

Permalink
<fix>(jni): update jni version to 3.7.1, update fisco-bcos-cpp-sdk to…
Browse files Browse the repository at this point in the history
… 3.12.1. (#235)
  • Loading branch information
kyonRay authored Dec 13, 2024
1 parent b2215b3 commit 871d2d1
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 14 deletions.
33 changes: 24 additions & 9 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-12 ]
os: [ macos-13 ]
# env:
# VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
steps:
Expand Down Expand Up @@ -134,32 +134,47 @@ jobs:
build_with_centos:
name: build_with_centos
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
container:
- centos-7.9
container:
image: docker.io/centos:7
volumes:
- /usr/local/share/vcpkg:/usr/local/share/vcpkg
# env:
- /node20217:/node20217:rw,rshared
- ${{ matrix.container == 'centos-7.9' && '/node20217:/__e/node20:ro,rshared' || ' ' }}
# env:
# VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
steps:
- uses: actions/checkout@v3
- name: install nodejs20glibc2.17
if: ${{ matrix.container == 'centos-7.9' }}
run: |
curl -LO https://unofficial-builds.nodejs.org/download/release/v20.9.0/node-v20.9.0-linux-x64-glibc-217.tar.xz
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
- uses: actions/checkout@v4
with:
fetch-depth: 5
- name: install rust language
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-06-17
toolchain: nightly-2022-07-28
override: true
- uses: actions/cache@v3
id: cache
id: deps_cache
with:
path: |
deps/
/usr/local/share/vcpkg/buildtrees
/usr/local/share/vcpkg/packages
key: vcpkg-centos-v1-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
/home/runner/.ccache
/Users/runner/.ccache/
key: centos-notest-all-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/cpp_full_node_workflow.yml') }}
restore-keys: |
vcpkg-centos-v1-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }}
vcpkg-centos-v1-notest-${{ runner.temp }}-${{ github.base_ref }}-
vcpkg-centos-v1-notest-${{ runner.temp }}-
centos-notest-all-${{ matrix.os }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/cpp_full_node_workflow.yml') }}
centos-notest-all-${{ matrix.os }}-${{ github.base_ref }}-
centos-notest-all-${{ matrix.os }}-
- name: install CentOS dependencies
run: |
rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl-rh/2/3.el7.centos/noarch/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
Expand Down
1 change: 1 addition & 0 deletions bcos-c-sdk/bcos_sdk_c_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "bcos_sdk_c_error.h"
#include <bcos-utilities/Common.h>
#include <bcos-utilities/Error.h>
#include <bcos-utilities/BoostLog.h>

using namespace bcos;

Expand Down
2 changes: 1 addition & 1 deletion bindings/java/jni/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {

archivesBaseName = 'bcos-sdk-jni'
group = 'org.fisco-bcos'
version = '3.7.0'
version = '3.7.1'

// Additional attribute definition
ext {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package org.fisco.bcos.sdk.jni.perf;

import org.fisco.bcos.sdk.jni.utilities.keypair.KeyPairJniObj;
import org.fisco.bcos.sdk.jni.utilities.tx.TransactionBuilderJniObj;
import org.fisco.bcos.sdk.jni.utilities.tx.TxPair;

public class OldCreateSignedTx {

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------

// HelloWorld Source Code:

// HelloWorld Source Code:
/**
* pragma solidity>=0.4.24 <0.6.11;
*
* <p>contract HelloWorld { string name;
*
* <p>constructor() public { name = "Hello, World!"; }
*
* <p>function get() public view returns (string memory) { return name; }
*
* <p>function set(string memory n) public { name = n; } }
*/
private static final String hwBIN =
"608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c146100f6575b600080fd5b6100f46004803603602081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460018302840111640100000000831117156100a257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610179565b005b6100fe610193565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013e578082015181840152602081019050610123565b50505050905090810190601f16801561016b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b806000908051906020019061018f929190610235565b5050565b606060008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561022b5780601f106102005761010080835404028352916020019161022b565b820191906000526020600020905b81548152906001019060200180831161020e57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea2646970667358221220b5943f43c48cc93c6d71cdcf27aee5072566c88755ce9186e32ce83b24e8dc6c64736f6c634300060a0033";

private static final String hwSmBIN =
"608060405234801561001057600080fd5b506040518060400160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b610310806101166000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063299f7f9d1461003b5780633590b49f146100be575b600080fd5b610043610179565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610083578082015181840152602081019050610068565b50505050905090810190601f1680156100b05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610177600480360360208110156100d457600080fd5b81019080803590602001906401000000008111156100f157600080fd5b82018360208201111561010357600080fd5b8035906020019184600183028401116401000000008311171561012557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061021b565b005b606060008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102115780601f106101e657610100808354040283529160200191610211565b820191906000526020600020905b8154815290600101906020018083116101f457829003601f168201915b5050505050905090565b8060009080519060200190610231929190610235565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027657805160ff19168380011785556102a4565b828001600101855582156102a4579182015b828111156102a3578251825591602001919060010190610288565b5b5090506102b191906102b5565b5090565b6102d791905b808211156102d35760008160009055506001016102bb565b5090565b9056fea26469706673582212209871cb2bcf390d53645807cbaedfe052d739ef9cff9d84787f74c4f379e1854664736f6c634300060a0033";

/*
{
"6d4ce63c": "get()",
"4ed3885e": "set(string)"
}
{
"299f7f9d": "get()",
"3590b49f": "set(string)"
}
*/

static class KeypairWrapper {
private long keypair;

public KeypairWrapper(long keypair) {
this.keypair = keypair;
}

public long getKeypair() {
return keypair;
}

@Override
protected void finalize() throws Throwable {
KeyPairJniObj.destroyJniKeyPair(keypair);
super.finalize();
}
}

public static String getBinary(boolean isSM) {
return isSM ? hwSmBIN : hwBIN;
}

public static void Usage() {
System.out.println("Desc: create signed transaction[HelloWorld set] perf test");
System.out.println(
"Usage: java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.jni.perf.OldCreateSignedTx smCrypto durationMS(MS)");
System.out.println("Example:");
System.out.println(
" java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.jni.perf.OldCreateSignedTx true 10000\n");
System.out.println(
" java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.jni.perf.OldCreateSignedTx false 10000\n");
System.exit(0);
}

public static void main(String[] args) throws Throwable {
// if (args.length < 2) {
// Usage();
// }

boolean smCrypto = false;
long durationMS = 1000000;

System.out.printf(
"[Create Signed Tx Perf Test] ===>>>> smCrypto: %d, durationMS: %d\n",
smCrypto ? 1 : 0, durationMS);

long blockLimit = 111111;
String groupID = "group0";
String chainID = "chain0";
String data = getBinary(smCrypto);

long startPoint = System.currentTimeMillis();
long lastReportPoint = startPoint;

long nTotalC = 0;
long nLastSecC = 0;
while (true) {
long keyPair = KeyPairJniObj.createJniKeyPair(smCrypto ? 1 : 0);
KeypairWrapper keypairWrapper = new KeypairWrapper(keyPair);
long keypair = keypairWrapper.getKeypair();
keypairWrapper.finalize();
TxPair signedTransaction =
TransactionBuilderJniObj.createSignedTransaction(
keypair, groupID, chainID, "", data, "", blockLimit, 0, "");
String txHash = signedTransaction.getSignedTx();

nTotalC++;
nLastSecC++;

long now = System.currentTimeMillis();
long elapsedMS = now - startPoint;
if (elapsedMS >= durationMS) {
System.out.printf(
" [Create Signed Tx Perf Test] total txs: %d, total elapsed(ms): %d \n",
nTotalC, elapsedMS);
break;
}

long lastElapsedMS = now - lastReportPoint;
if (lastElapsedMS >= 1000) {
System.out.printf(
" [Create Signed Tx Perf Test] last txs: %d, last elapsed(ms): %d\n",
nLastSecC, lastElapsedMS);

nLastSecC = 0;
lastReportPoint = now;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static native TxPair createSignedTransaction(
throws JniException;

public static native TxPair createSignedTransaction(
long txBuilderService, JniKeyPair keyPair, String to, String data, String abi, int attribute)
long txBuilderService,
JniKeyPair keyPair,
String to,
String data,
String abi,
int attribute)
throws JniException;
}
6 changes: 5 additions & 1 deletion sample/rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ file(GLOB SRC_LIST "*.c")
file(GLOB HEADERS "*.h")

add_executable(rpc rpc.c)
target_link_libraries(rpc PUBLIC ${BCOS_C_SDK_STATIC_TARGET})
target_link_libraries(rpc PUBLIC ${BCOS_C_SDK_STATIC_TARGET})

add_executable(repeat_connect repeat_connect.c)
target_link_libraries(repeat_connect PUBLIC ${BCOS_C_SDK_STATIC_TARGET})

117 changes: 117 additions & 0 deletions sample/rpc/repeat_connect.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <bcos-c-sdk/bcos_sdk_c.h>
#include <bcos-c-sdk/bcos_sdk_c_common.h>
#include <bcos-c-sdk/bcos_sdk_c_error.h>
#include <bcos-c-sdk/bcos_sdk_c_rpc.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void usage(void)
{
printf("Desc: rpc methods call test\n");
printf("Usage: rpc <host> <port> <ssl type> <group_id>\n");
printf("Example:\n");
printf(" ./rpc 127.0.0.1 20200 ssl group0\n");
printf(" ./rpc 127.0.0.1 20200 sm_ssl group0\n");
exit(0);
}


// callback for rpc interfaces
void on_recv_resp_callback(struct bcos_sdk_c_struct_response* resp)
{
if (resp->error != 0)
{
printf("\t something is wrong, error: %d, errorMessage: %s\n", resp->error, resp->desc);
// exit(-1);
}
else
{
printf(" \t recv rpc resp from server ===>>>> resp: %s\n", (char*)resp->data);
}
}

void* thread_function(void* arg)
{
while (1)
{
void* sdk = bcos_sdk_create((struct bcos_sdk_c_config*)arg);

bcos_sdk_start(sdk);

bcos_rpc_get_block_number(sdk, (char*)"group0", NULL, on_recv_resp_callback, sdk);
sleep(1);

bcos_sdk_stop(sdk);
bcos_sdk_destroy(sdk);
}
}

int main(int argc, char** argv)
{
if (argc < 5)
{
usage();
}

// option params
const char* host = argv[1];
int port = atoi(argv[2]);
const char* type = argv[3];
const char* group = argv[4];

printf(" [RPC] params ===>>>> \n");
printf(" \t # host: %s\n", host);
printf(" \t # port: %d\n", port);
printf(" \t # type: %s\n", type);
printf(" \t # group: %s\n", group);

int is_sm_ssl = 1;
char* pos = strstr(type, "sm_ssl");
if (pos == NULL)
{
is_sm_ssl = 0;
}


struct bcos_sdk_c_config* config = bcos_sdk_create_config(is_sm_ssl, (char*)host, port);

// check success or not
int error = bcos_sdk_get_last_error();
if (error != 0)
{
printf(" bcos_sdk_create_by_config_file failed, error: %d, errorMessage: %s\n", error,
bcos_sdk_get_last_error_msg());
exit(-1);
}
// bcos_sdk_c_config_destroy(config);


pthread_t threads[100];

int rc;
long t;
for (t = 0; t < 100; t++)
{
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, thread_function, (void*)config);
if (rc)
{
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}

for (t = 0; t < 100; t++)
{
pthread_join(threads[t], NULL);
}


return EXIT_SUCCESS;
}
4 changes: 2 additions & 2 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"registries": [
{
"kind": "git",
"repository": "https://gh-proxy.com/https://github.com/FISCO-BCOS/registry",
"baseline": "ede020c4c2538ca9cc6bd31f22ded572768184c5",
"repository": "https://github.com/FISCO-BCOS/registry",
"baseline": "cca5531387b451a89aec525174addac4cb8f1371",
"packages": [
"openssl",
"hsm-crypto",
Expand Down

0 comments on commit 871d2d1

Please sign in to comment.