Skip to content

Commit efa01ec

Browse files
Ilya Bogdanovdmitry-timofeev
authored andcommitted
Update native to revision b81d64ef of Core [ECR-4097] (#1352)
- Multiple fixes for the latest Core API - ArtifactId passed in protobuf-serialized format - Removed check for ArtifactId.runtime_id == JAVA_RUNTIME_ID. It seems to be purely Core's responsibility - Multiple fixes for the latest `clippy`.
1 parent 56dc5e5 commit efa01ec

File tree

18 files changed

+410
-391
lines changed

18 files changed

+410
-391
lines changed
Submodule proto updated 1 file

exonum-java-binding/core/rust/Cargo.lock

Lines changed: 278 additions & 242 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exonum-java-binding/core/rust/Cargo.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ exonum-cli = "0.13.0-rc.2"
2222
exonum-crypto = "0.13.0-rc.2"
2323
exonum-derive = "0.13.0-rc.2"
2424
exonum-proto = "0.13.0-rc.2"
25+
exonum-supervisor = "0.13.0-rc.2"
2526
exonum-testkit = "0.13.0-rc.2"
2627
exonum-time = "0.13.0-rc.2"
2728
failure = "0.1"
@@ -51,13 +52,13 @@ rpath = true
5152

5253
# FIXME: using git dependency until Exonum 1.0 is released
5354
[patch.crates-io]
54-
exonum = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
55-
exonum-testkit = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
56-
exonum-time = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
57-
exonum-build = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
58-
exonum-derive = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
59-
exonum-cli = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
60-
exonum-proto = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
61-
exonum-supervisor = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
62-
exonum-crypto = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
63-
exonum-merkledb = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
55+
exonum = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
56+
exonum-testkit = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
57+
exonum-time = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
58+
exonum-build = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
59+
exonum-derive = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
60+
exonum-cli = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
61+
exonum-proto = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
62+
exonum-supervisor = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
63+
exonum-crypto = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
64+
exonum-merkledb = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }

exonum-java-binding/core/rust/exonum-java/src/node.rs

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
use exonum_supervisor::Supervisor;
18-
use exonum_time::{time_provider::SystemTimeProvider, TimeServiceFactory};
18+
use exonum_time::TimeServiceFactory;
1919
use java_bindings::{
2020
create_java_vm, create_service_runtime,
2121
exonum::{
@@ -24,12 +24,14 @@ use java_bindings::{
2424
Blockchain, BlockchainBuilder, BlockchainMut,
2525
},
2626
exonum_merkledb::{Database, RocksDB},
27-
node::{ApiSender, Node, NodeChannel},
27+
node::{ApiSender, Node, NodeChannel, NodeConfig as CoreNodeConfig},
2828
runtime::rust::{RustRuntime, ServiceFactory},
2929
},
30-
Command, Config, EjbCommand, EjbCommandResult, Executor, InternalConfig, JavaRuntimeProxy,
30+
Command, Config, DefaultConfigManager, EjbCommand, EjbCommandResult, Executor, InternalConfig,
31+
JavaRuntimeProxy,
3132
};
3233

34+
use java_bindings::exonum::runtime::rust::RustRuntimeBuilder;
3335
use std::sync::Arc;
3436

3537
pub fn run_node(command: Command) -> Result<(), failure::Error> {
@@ -43,57 +45,51 @@ pub fn run_node(command: Command) -> Result<(), failure::Error> {
4345

4446
fn create_node(config: Config) -> Result<Node, failure::Error> {
4547
let node_config = config.run_config.node_config.clone();
46-
let events_pool_capacity = &node_config.mempool.events_pool_capacity;
48+
let events_pool_capacity = &node_config.private_config.mempool.events_pool_capacity;
4749
let channel = NodeChannel::new(events_pool_capacity);
4850
let blockchain = create_blockchain(&config, &channel)?;
4951

50-
let node_config_path = config
51-
.run_config
52-
.node_config_path
53-
.to_str()
54-
.expect("Cannot convert node_config_path to String")
55-
.to_owned();
52+
let config_manager = DefaultConfigManager::new(config.run_config.node_config_path);
5653

5754
Ok(Node::with_blockchain(
5855
blockchain,
5956
channel,
60-
node_config,
61-
Some(node_config_path),
57+
node_config.into(),
58+
Some(Box::new(config_manager)),
6259
))
6360
}
6461

6562
fn create_blockchain(
6663
config: &Config,
6764
channel: &NodeChannel,
6865
) -> Result<BlockchainMut, failure::Error> {
69-
let node_config = &config.run_config.node_config;
66+
let node_config: CoreNodeConfig = config.run_config.node_config.clone().into();
7067
let database = create_database(config)?;
7168
let keypair = node_config.service_keypair();
7269
let api_sender = ApiSender::new(channel.api_requests.0.clone());
7370

7471
let blockchain = Blockchain::new(database, keypair, api_sender);
7572

7673
let supervisor_service = supervisor_service();
77-
let genesis_config = GenesisConfigBuilder::with_consensus_config(node_config.consensus.clone())
74+
let genesis_config = GenesisConfigBuilder::with_consensus_config(node_config.consensus)
7875
.with_artifact(Supervisor.artifact_id())
7976
.with_instance(supervisor_service)
8077
.build();
8178

8279
let rust_runtime = create_rust_runtime(channel);
8380
let java_runtime = create_java_runtime(&config);
8481

85-
BlockchainBuilder::new(blockchain, genesis_config)
82+
Ok(BlockchainBuilder::new(blockchain, genesis_config)
8683
.with_runtime(rust_runtime)
8784
.with_runtime(java_runtime)
88-
.build()
85+
.build())
8986
}
9087

9188
fn create_rust_runtime(channel: &NodeChannel) -> RustRuntime {
92-
let service_factories = standard_exonum_service_factories();
93-
service_factories.into_iter().fold(
94-
RustRuntime::new(channel.endpoints.0.clone()),
95-
|runtime, factory| runtime.with_factory(factory),
96-
)
89+
RustRuntimeBuilder::new()
90+
.with_factory(TimeServiceFactory::default())
91+
.with_factory(Supervisor)
92+
.build(channel.endpoints.0.clone())
9793
}
9894

9995
fn create_java_runtime(config: &Config) -> JavaRuntimeProxy {
@@ -109,18 +105,11 @@ fn create_java_runtime(config: &Config) -> JavaRuntimeProxy {
109105
fn create_database(config: &Config) -> Result<Arc<dyn Database>, failure::Error> {
110106
let database = Arc::new(RocksDB::open(
111107
&config.run_config.db_path,
112-
&config.run_config.node_config.database,
108+
&config.run_config.node_config.private_config.database,
113109
)?) as Arc<dyn Database>;
114110
Ok(database)
115111
}
116112

117-
fn standard_exonum_service_factories() -> Vec<Box<dyn ServiceFactory>> {
118-
vec![
119-
Box::new(TimeServiceFactory::with_provider(SystemTimeProvider)),
120-
Box::new(Supervisor),
121-
]
122-
}
123-
124113
fn supervisor_service() -> InstanceInitParams {
125114
Supervisor::simple()
126115
}

exonum-java-binding/core/rust/src/cmd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ mod run_dev;
3030

3131
pub use self::run::*;
3232
pub use self::run_dev::*;
33+
pub use exonum_cli::DefaultConfigManager;
3334

3435
/// Exonum Java Bindings Application.
3536
///

exonum-java-binding/core/rust/src/cmd/run_dev.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
use exonum_cli::command::{
1818
finalize::Finalize,
19-
generate_config::{GenerateConfig, PUB_CONFIG_FILE_NAME, SEC_CONFIG_FILE_NAME},
19+
generate_config::{GenerateConfig, PRIVATE_CONFIG_FILE_NAME, PUBLIC_CONFIG_FILE_NAME},
2020
generate_template::GenerateTemplate,
2121
run::Run as StandardRun,
2222
ExonumCommand,
2323
};
24+
use exonum_supervisor::mode::Mode;
2425
use failure;
2526
use structopt::StructOpt;
2627

@@ -71,12 +72,13 @@ impl RunDev {
7172
let public_allow_origin = "http://127.0.0.1:8080, http://localhost:8080".into();
7273
let private_allow_origin = "http://127.0.0.1:8081, http://localhost:8081".into();
7374
let common_config_path = concat_path(config_directory.clone(), "template.toml");
74-
let public_config_path = concat_path(config_directory.clone(), PUB_CONFIG_FILE_NAME);
75-
let secret_config_path = concat_path(config_directory.clone(), SEC_CONFIG_FILE_NAME);
75+
let public_config_path = concat_path(config_directory.clone(), PUBLIC_CONFIG_FILE_NAME);
76+
let private_config_path = concat_path(config_directory.clone(), PRIVATE_CONFIG_FILE_NAME);
7677

7778
let generate_template = GenerateTemplate {
7879
common_config: common_config_path.clone(),
7980
validators_count,
81+
supervisor_mode: Mode::Simple,
8082
};
8183
generate_template.execute()?;
8284

@@ -92,7 +94,7 @@ impl RunDev {
9294
generate_config.execute()?;
9395

9496
let finalize = Finalize {
95-
secret_config_path,
97+
private_config_path,
9698
output_config_path: node_config_path.clone(),
9799
public_configs: vec![public_config_path],
98100
public_api_address: Some(public_api_address),

exonum-java-binding/core/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern crate exonum_cli;
2727
#[macro_use]
2828
extern crate exonum_derive;
2929
extern crate exonum_proto;
30+
extern crate exonum_supervisor;
3031
extern crate failure;
3132
pub extern crate jni;
3233
extern crate structopt;

exonum-java-binding/core/rust/src/proxy/runtime.rs

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
use exonum::{
1818
blockchain::Blockchain,
1919
crypto::{Hash, PublicKey},
20-
exonum_merkledb::Snapshot,
21-
messages::BinaryValue,
20+
exonum_merkledb::{BinaryValue, Snapshot},
2221
runtime::{
23-
ArtifactId, CallInfo, Caller, ExecutionContext, ExecutionError, ExecutionFail, InstanceId,
24-
InstanceSpec, InstanceStatus, Mailbox, Runtime, RuntimeIdentifier, SnapshotExt,
25-
WellKnownRuntime,
22+
ArtifactId, CallInfo, Caller, ExecutionContext, ExecutionError, InstanceId, InstanceSpec,
23+
InstanceStatus, Mailbox, Runtime, RuntimeIdentifier, SnapshotExt, WellKnownRuntime,
2624
},
2725
};
2826
use futures::{Future, IntoFuture};
@@ -66,17 +64,6 @@ impl JavaRuntimeProxy {
6664
}
6765
}
6866

69-
fn parse_artifact(&self, artifact: &ArtifactId) -> Result<JavaArtifactId, ExecutionError> {
70-
if artifact.runtime_id != JAVA_RUNTIME_ID {
71-
Err(Error::IllegalArgument.with_description(format!(
72-
"Invalid runtime ID ({}), {} expected",
73-
artifact.runtime_id, JAVA_RUNTIME_ID
74-
)))
75-
} else {
76-
Ok(JavaArtifactId(artifact.name.to_string()))
77-
}
78-
}
79-
8067
/// If the current node is a validator, returns its ID, otherwise returns `-1`.
8168
fn validator_id(snapshot: &dyn Snapshot, pub_key: &PublicKey) -> i32 {
8269
snapshot
@@ -106,16 +93,13 @@ impl Runtime for JavaRuntimeProxy {
10693

10794
fn deploy_artifact(
10895
&mut self,
109-
artifact: ArtifactId,
96+
artifact_id: ArtifactId,
11097
deploy_spec: Vec<u8>,
11198
) -> Box<dyn Future<Item = (), Error = ExecutionError>> {
112-
let id = match self.parse_artifact(&artifact) {
113-
Ok(id) => id.to_string(),
114-
Err(err) => return Box::new(Err(err).into_future()),
115-
};
99+
let serialized_artifact_id: Vec<u8> = artifact_id.to_bytes();
116100

117101
let result = jni_call_default(&self.exec, |env| {
118-
let artifact_id = JObject::from(env.new_string(id)?);
102+
let artifact_id = JObject::from(env.byte_array_from_slice(&serialized_artifact_id)?);
119103
let spec = JObject::from(env.byte_array_from_slice(&deploy_spec)?);
120104

121105
env.call_method_unchecked(
@@ -130,16 +114,11 @@ impl Runtime for JavaRuntimeProxy {
130114
Box::new(result.map(|_| ()).into_future())
131115
}
132116

133-
fn is_artifact_deployed(&self, id: &ArtifactId) -> bool {
134-
let artifact = match self.parse_artifact(id) {
135-
Ok(id) => id.to_string(),
136-
Err(_) => {
137-
return false;
138-
}
139-
};
117+
fn is_artifact_deployed(&self, artifact_id: &ArtifactId) -> bool {
118+
let serialized_artifact_id: Vec<u8> = artifact_id.to_bytes();
140119

141120
unwrap_jni(self.exec.with_attached(|env| {
142-
let artifact_id = JObject::from(env.new_string(artifact)?);
121+
let artifact_id = JObject::from(env.byte_array_from_slice(&serialized_artifact_id)?);
143122

144123
panic_on_exception(
145124
env,
@@ -187,21 +166,24 @@ impl Runtime for JavaRuntimeProxy {
187166
_snapshot: &dyn Snapshot,
188167
instance_spec: &InstanceSpec,
189168
status: InstanceStatus,
190-
) -> Result<(), ExecutionError> {
169+
) {
191170
let serialized_instance_spec: Vec<u8> = instance_spec.to_bytes();
192-
jni_call_default(&self.exec, |env| {
171+
unwrap_jni(self.exec.with_attached(|env| {
193172
let instance_spec =
194173
JObject::from(env.byte_array_from_slice(&serialized_instance_spec)?);
195174
let instance_status = status as i32;
196175

197-
env.call_method_unchecked(
198-
self.runtime_adapter.as_obj(),
199-
runtime_adapter::update_service_status_id(),
200-
JavaType::Primitive(Primitive::Void),
201-
&[JValue::from(instance_spec), JValue::from(instance_status)],
202-
)
203-
.and_then(JValue::v)
204-
})
176+
panic_on_exception(
177+
env,
178+
env.call_method_unchecked(
179+
self.runtime_adapter.as_obj(),
180+
runtime_adapter::update_service_status_id(),
181+
JavaType::Primitive(Primitive::Void),
182+
&[JValue::from(instance_spec), JValue::from(instance_status)],
183+
),
184+
);
185+
Ok(())
186+
}));
205187
}
206188

207189
fn execute(
@@ -336,13 +318,3 @@ impl fmt::Debug for JavaRuntimeProxy {
336318
impl WellKnownRuntime for JavaRuntimeProxy {
337319
const ID: u32 = JAVA_RUNTIME_ID;
338320
}
339-
340-
/// Artifact identification properties within `JavaRuntimeProxy`
341-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
342-
pub struct JavaArtifactId(String);
343-
344-
impl fmt::Display for JavaArtifactId {
345-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
346-
write!(f, "{}", self.0)
347-
}
348-
}

exonum-java-binding/core/rust/src/storage/key_set_index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use exonum_merkledb::{
16-
access::FromAccess, key_set_index::KeySetIndexIter, Fork, IndexAddress, KeySetIndex, Snapshot,
16+
access::FromAccess, indexes::key_set::Iter, Fork, IndexAddress, KeySetIndex, Snapshot,
1717
};
1818
use jni::{
1919
objects::{JClass, JObject, JString},
@@ -217,7 +217,7 @@ pub extern "system" fn Java_com_exonum_binding_core_storage_indices_KeySetIndexP
217217
iter_handle: Handle,
218218
) -> jbyteArray {
219219
let res = panic::catch_unwind(|| {
220-
let iter = handle::cast_handle::<KeySetIndexIter<Key>>(iter_handle);
220+
let iter = handle::cast_handle::<Iter<Key>>(iter_handle);
221221
match iter.next() {
222222
Some(val) => env.byte_array_from_slice(&val),
223223
None => Ok(ptr::null_mut()),
@@ -233,5 +233,5 @@ pub extern "system" fn Java_com_exonum_binding_core_storage_indices_KeySetIndexP
233233
_: JObject,
234234
iter_handle: Handle,
235235
) {
236-
handle::drop_handle::<KeySetIndexIter<Key>>(&env, iter_handle);
236+
handle::drop_handle::<Iter<Key>>(&env, iter_handle);
237237
}

exonum-java-binding/core/rust/src/storage/list_index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use exonum_merkledb::{
16-
access::FromAccess, list_index::ListIndexIter, Fork, IndexAddress, ListIndex, Snapshot,
16+
access::FromAccess, indexes::list::Iter, Fork, IndexAddress, ListIndex, Snapshot,
1717
};
1818
use jni::{
1919
objects::{JClass, JObject, JString},
@@ -312,7 +312,7 @@ pub extern "system" fn Java_com_exonum_binding_core_storage_indices_ListIndexPro
312312
iter_handle: Handle,
313313
) -> jbyteArray {
314314
let res = panic::catch_unwind(|| {
315-
let iter = handle::cast_handle::<ListIndexIter<Value>>(iter_handle);
315+
let iter = handle::cast_handle::<Iter<Value>>(iter_handle);
316316
match iter.next() {
317317
Some(val) => env.byte_array_from_slice(&val),
318318
None => Ok(ptr::null_mut()),
@@ -328,5 +328,5 @@ pub extern "system" fn Java_com_exonum_binding_core_storage_indices_ListIndexPro
328328
_: JObject,
329329
iter_handle: Handle,
330330
) {
331-
handle::drop_handle::<ListIndexIter<Value>>(&env, iter_handle);
331+
handle::drop_handle::<Iter<Value>>(&env, iter_handle);
332332
}

0 commit comments

Comments
 (0)