Skip to content

Commit

Permalink
Merge 2c56624 into 0c3e178
Browse files Browse the repository at this point in the history
  • Loading branch information
bullet-tooth committed Jan 13, 2020
2 parents 0c3e178 + 2c56624 commit 01b84f6
Show file tree
Hide file tree
Showing 64 changed files with 902 additions and 639 deletions.
4 changes: 4 additions & 0 deletions exonum-java-binding/CHANGELOG.md
Expand Up @@ -48,6 +48,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- The specification of `Configurable` operations and `Service#initialize`
to require throwing `ExecutionException` instead of
`IllegalArgumentException`.
- Transaction index in block type changed from `long` to `int`. (#1348)
- Extracted artifact version to the separate field from the artifact name.
Artifact name format is `groupId/artifactId` now.
PluginId format is `runtimeId:artifactName:artifactVersion` now. (#1349)

### Removed
- Classes supporting no longer used tree-like list proof representation.
Expand Down
Expand Up @@ -33,9 +33,8 @@ public final class CallInBlocks {
* @throws IndexOutOfBoundsException if position is negative or greater than
* {@value Integer#MAX_VALUE}
*/
public static CallInBlock transaction(/* todo: change to int once ECR-4083 is integrated */
long txPosition) {
checkElementIndex(Math.toIntExact(txPosition), Integer.MAX_VALUE, "txPosition");
public static CallInBlock transaction(int txPosition) {
checkElementIndex(txPosition, Integer.MAX_VALUE, "txPosition");
return CallInBlock.newBuilder()
.setTransaction(txPosition)
.build();
Expand Down
Expand Up @@ -27,7 +27,7 @@
@AutoValue
public abstract class TransactionLocation {

public static TransactionLocation valueOf(long height, long indexInBlock) {
public static TransactionLocation valueOf(long height, int indexInBlock) {
return new AutoValue_TransactionLocation(height, indexInBlock);
}

Expand All @@ -42,7 +42,7 @@ public static TransactionLocation valueOf(long height, long indexInBlock) {
* order of these indices.
*/
@SerializedName("position_in_block")
public abstract long getIndexInBlock();
public abstract int getIndexInBlock();

/**
* Provides a Gson type adapter for this class.
Expand Down
Expand Up @@ -26,16 +26,16 @@
class CallInBlocksTest {

@ParameterizedTest
@ValueSource(longs = {0, 1, Integer.MAX_VALUE - 1})
void transaction(long txPosition) {
@ValueSource(ints = {0, 1, Integer.MAX_VALUE - 1})
void transaction(int txPosition) {
CallInBlock transaction = CallInBlocks.transaction(txPosition);
assertThat(transaction.getTransaction()).isEqualTo(txPosition);
}

@ParameterizedTest
@ValueSource(longs = {/* Negative: */ Integer.MIN_VALUE, -2, -1,
@ValueSource(ints = {/* Negative: */ Integer.MIN_VALUE, -2, -1,
/* Too big: */ Integer.MAX_VALUE})
void transactionInvalidPositions(long txPosition) {
void transactionInvalidPositions(int txPosition) {
assertThrows(IndexOutOfBoundsException.class, () -> CallInBlocks.transaction(txPosition));
}
}
520 changes: 278 additions & 242 deletions exonum-java-binding/core/rust/Cargo.lock

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions exonum-java-binding/core/rust/Cargo.toml
Expand Up @@ -22,6 +22,7 @@ exonum-cli = "0.13.0-rc.2"
exonum-crypto = "0.13.0-rc.2"
exonum-derive = "0.13.0-rc.2"
exonum-proto = "0.13.0-rc.2"
exonum-supervisor = "0.13.0-rc.2"
exonum-testkit = "0.13.0-rc.2"
exonum-time = "0.13.0-rc.2"
failure = "0.1"
Expand Down Expand Up @@ -51,13 +52,13 @@ rpath = true

# FIXME: using git dependency until Exonum 1.0 is released
[patch.crates-io]
exonum = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-testkit = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-time = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-build = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-derive = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-cli = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-proto = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-supervisor = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-crypto = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum-merkledb = { git = "https://github.com/exonum/exonum", rev = "af28b719e6" }
exonum = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-testkit = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-time = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-build = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-derive = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-cli = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-proto = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-supervisor = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-crypto = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
exonum-merkledb = { git = "https://github.com/exonum/exonum", rev = "b81d64ef" }
6 changes: 4 additions & 2 deletions exonum-java-binding/core/rust/exonum-java/qa-service.yml
Expand Up @@ -18,12 +18,14 @@ plugins:
artifacts:
qa-service:
runtime: java
name: "com.exonum.binding:exonum-java-binding-qa-service:0.10.0-SNAPSHOT"
name: "com.exonum.binding/exonum-java-binding-qa-service"
version: "0.10.0-SNAPSHOT"
spec:
artifact_filename: "exonum-java-binding-qa-service-0.10.0-SNAPSHOT-artifact.jar"
time:
runtime: rust
name: "exonum-time:0.13.0-rc.2"
name: "exonum-time"
version: "0.13.0-rc.2"

instances:
qa-service:
Expand Down
47 changes: 18 additions & 29 deletions exonum-java-binding/core/rust/exonum-java/src/node.rs
Expand Up @@ -15,7 +15,7 @@
*/

use exonum_supervisor::Supervisor;
use exonum_time::{time_provider::SystemTimeProvider, TimeServiceFactory};
use exonum_time::TimeServiceFactory;
use java_bindings::{
create_java_vm, create_service_runtime,
exonum::{
Expand All @@ -24,12 +24,14 @@ use java_bindings::{
Blockchain, BlockchainBuilder, BlockchainMut,
},
exonum_merkledb::{Database, RocksDB},
node::{ApiSender, Node, NodeChannel},
node::{ApiSender, Node, NodeChannel, NodeConfig as CoreNodeConfig},
runtime::rust::{RustRuntime, ServiceFactory},
},
Command, Config, EjbCommand, EjbCommandResult, Executor, InternalConfig, JavaRuntimeProxy,
Command, Config, DefaultConfigManager, EjbCommand, EjbCommandResult, Executor, InternalConfig,
JavaRuntimeProxy,
};

use java_bindings::exonum::runtime::rust::RustRuntimeBuilder;
use std::sync::Arc;

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

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

let node_config_path = config
.run_config
.node_config_path
.to_str()
.expect("Cannot convert node_config_path to String")
.to_owned();
let config_manager = DefaultConfigManager::new(config.run_config.node_config_path);

Ok(Node::with_blockchain(
blockchain,
channel,
node_config,
Some(node_config_path),
node_config.into(),
Some(Box::new(config_manager)),
))
}

fn create_blockchain(
config: &Config,
channel: &NodeChannel,
) -> Result<BlockchainMut, failure::Error> {
let node_config = &config.run_config.node_config;
let node_config: CoreNodeConfig = config.run_config.node_config.clone().into();
let database = create_database(config)?;
let keypair = node_config.service_keypair();
let api_sender = ApiSender::new(channel.api_requests.0.clone());

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

let supervisor_service = supervisor_service();
let genesis_config = GenesisConfigBuilder::with_consensus_config(node_config.consensus.clone())
let genesis_config = GenesisConfigBuilder::with_consensus_config(node_config.consensus)
.with_artifact(Supervisor.artifact_id())
.with_instance(supervisor_service)
.build();

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

BlockchainBuilder::new(blockchain, genesis_config)
Ok(BlockchainBuilder::new(blockchain, genesis_config)
.with_runtime(rust_runtime)
.with_runtime(java_runtime)
.build()
.build())
}

fn create_rust_runtime(channel: &NodeChannel) -> RustRuntime {
let service_factories = standard_exonum_service_factories();
service_factories.into_iter().fold(
RustRuntime::new(channel.endpoints.0.clone()),
|runtime, factory| runtime.with_factory(factory),
)
RustRuntimeBuilder::new()
.with_factory(TimeServiceFactory::default())
.with_factory(Supervisor)
.build(channel.endpoints.0.clone())
}

fn create_java_runtime(config: &Config) -> JavaRuntimeProxy {
Expand All @@ -109,18 +105,11 @@ fn create_java_runtime(config: &Config) -> JavaRuntimeProxy {
fn create_database(config: &Config) -> Result<Arc<dyn Database>, failure::Error> {
let database = Arc::new(RocksDB::open(
&config.run_config.db_path,
&config.run_config.node_config.database,
&config.run_config.node_config.private_config.database,
)?) as Arc<dyn Database>;
Ok(database)
}

fn standard_exonum_service_factories() -> Vec<Box<dyn ServiceFactory>> {
vec![
Box::new(TimeServiceFactory::with_provider(SystemTimeProvider)),
Box::new(Supervisor),
]
}

fn supervisor_service() -> InstanceInitParams {
Supervisor::simple()
}
1 change: 1 addition & 0 deletions exonum-java-binding/core/rust/src/cmd/mod.rs
Expand Up @@ -30,6 +30,7 @@ mod run_dev;

pub use self::run::*;
pub use self::run_dev::*;
pub use exonum_cli::DefaultConfigManager;

/// Exonum Java Bindings Application.
///
Expand Down
10 changes: 6 additions & 4 deletions exonum-java-binding/core/rust/src/cmd/run_dev.rs
Expand Up @@ -16,11 +16,12 @@

use exonum_cli::command::{
finalize::Finalize,
generate_config::{GenerateConfig, PUB_CONFIG_FILE_NAME, SEC_CONFIG_FILE_NAME},
generate_config::{GenerateConfig, PRIVATE_CONFIG_FILE_NAME, PUBLIC_CONFIG_FILE_NAME},
generate_template::GenerateTemplate,
run::Run as StandardRun,
ExonumCommand,
};
use exonum_supervisor::mode::Mode;
use failure;
use structopt::StructOpt;

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

let generate_template = GenerateTemplate {
common_config: common_config_path.clone(),
validators_count,
supervisor_mode: Mode::Simple,
};
generate_template.execute()?;

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

let finalize = Finalize {
secret_config_path,
private_config_path,
output_config_path: node_config_path.clone(),
public_configs: vec![public_config_path],
public_api_address: Some(public_api_address),
Expand Down
1 change: 1 addition & 0 deletions exonum-java-binding/core/rust/src/lib.rs
Expand Up @@ -27,6 +27,7 @@ extern crate exonum_cli;
#[macro_use]
extern crate exonum_derive;
extern crate exonum_proto;
extern crate exonum_supervisor;
extern crate failure;
pub extern crate jni;
extern crate structopt;
Expand Down

0 comments on commit 01b84f6

Please sign in to comment.