Sitelet https://github.com/exonum/exonum-java-binding/pull/1065
Skip to content

Add initial ServiceRuntime for Dynamic Services [ECR-3404] - #1065

Merged
dmitry-timofeev merged 30 commits into
exonum:dynamic-servicesfrom
dmitry-timofeev:service-runtime-for-ds-ECR-3404
Aug 20, 2019
Merged

dmitry-timofeev merged 30 commits into
exonum:dynamic-servicesfrom
dmitry-timofeev:service-runtime-for-ds-ECR-3404

Conversation

@dmitry-timofeev

Copy link
Copy Markdown
Contributor

Overview

Adds initial implementation of ServiceRuntime operations for dynamic services.

The code in dependent on core modules has not been migrated as the ServiceRuntime interface is not finalized yet, neither are the user-facing interfaces (like Service, Transaction, etc.).


See: https://jira.bf.local/browse/ECR-3404

Definition of Done

  • There are no TODOs left in the code
  • Change is covered by automated tests
  • The coding guidelines are followed
  • Public API has Javadoc
  • Method preconditions are checked and documented in the Javadoc of the method
  • Changelog is updated if needed (in case of notable or breaking changes)
  • The continuous integration build passes

@dmitry-timofeev dmitry-timofeev added the work-in-progress 👷‍♂️ Do not expect reviewers to provide any feedback on WIP PRs — please ask for it explicitly! label Aug 13, 2019
@dmitry-timofeev
dmitry-timofeev force-pushed the service-runtime-for-ds-ECR-3404 branch 2 times, most recently from 7c135d4 to 0ba481a Compare August 13, 2019 13:44
@dmitry-timofeev dmitry-timofeev removed the work-in-progress 👷‍♂️ Do not expect reviewers to provide any feedback on WIP PRs — please ask for it explicitly! label Aug 13, 2019
@dmitry-timofeev
dmitry-timofeev requested review from MakarovS, bullet-tooth, skletsun and vitvakatu and removed request for bullet-tooth August 13, 2019 15:27
@dmitry-timofeev

Copy link
Copy Markdown
Contributor Author

How to review:

  • Java: everything, but start with:
    • ServiceRuntime
    • ServiceRuntimeIntegrationTest
    • ServiceFactory & its implementation and test
    • Service
    • ServiceWrapper
    • everything else
  • Rust:
    • (for native interface) ServiceRuntimeAdapter and ServiceRuntime
    • jni_cache

@dmitry-timofeev

Copy link
Copy Markdown
Contributor Author

+1,612 −1,605 — nothing was added, actually 🙃

public abstract String getName();

/**
* Returns the numeric id of the service instance. Exonum assigns it to the service

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exonum assigns it to the service on instantiation.

As I remember, a user must provide id for its service which is unique within the network. Does it change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it has been changed in dynamic services. As administrators can create several instances from the same artifact, the service id cannot be hardcoded in the service definition, but must be assigned on instantiation, so that the transaction messages can be routed to the correct instance. The id assignment is done by the core; the name is provided by the administrators (and is considered the primary identifier of the service instance).

this.frameworkInjector = checkNotNull(frameworkInjector);
this.serviceLoader = checkNotNull(serviceLoader);
this.servicesFactory = checkNotNull(servicesFactory);
services = new TreeMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move instantiations to the field ^

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning behind your suggestion? I can think of bringing the definition closer to the field declaration 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly

@MakarovS MakarovS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

static mut CLASS_GET_NAME: Option<JMethodID> = None;
static mut THROWABLE_GET_MESSAGE: Option<JMethodID> = None;

// todo: Remove transaction and service adapter items when native JavaServiceRuntime is implemented

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to the task?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one 'Implement JavaServiceRuntime' in the native, but it isn't in Jira till some questions on it are clarified: https://wiki.bf.local/display/EJB/Java+Dynamic+Services+P1+Design#JavaDynamicServicesP1Design-%D0%97%D0%B0%D0%B4%D0%B0%D1%87%D0%B8

@@ -0,0 +1,43 @@
package com.exonum.binding.core.runtime;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

}

private static ServiceId extractServiceId(String pluginId) throws ServiceLoadingException {
private static ServiceArtifactId extractServiceId(String pluginId)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extractServiceArtifactId?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest keeping it as is for brevity — it must be clear from the context.

@@ -0,0 +1,23 @@
package com.exonum.binding.core.runtime;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

@@ -0,0 +1,35 @@
package com.exonum.binding.core.runtime;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

@@ -0,0 +1,77 @@
package com.exonum.binding.core.runtime;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

@@ -0,0 +1,25 @@
package com.exonum.binding.core.runtime;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

/**
* Converts an Exonum raw transaction to an executable transaction of <em>this</em> service.
* Returns a list of hashes representing the state of this service, as of the given snapshot
* of the blockchain state. Usually, it includes the root hashes of all Merkelized collections

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root hashes or object/index hashes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks!

* @param arguments the {@linkplain TransactionMessage#getPayload() serialized transaction
* arguments}
* @return an executable transaction of the service
* @throws IllegalArgumentException if the raw transaction is malformed or not known

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we rephrase this exception description?

@@ -0,0 +1,93 @@
package com.exonum.binding.core.runtime;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

@vitvakatu

Copy link
Copy Markdown
Contributor

Looks good to me, but where is beforeCommit method? Can't find any task for it and it is mentioned in documentation of ServiceRuntime.

@dmitry-timofeev

Copy link
Copy Markdown
Contributor Author

- Perform the expected/actual id verification
* Remove:
  - getId — this one might be reconsidered
  - getName

* Update configure to take configuration parameters and return void

* Make getStateHashes implementation required (as no state hashes
usually means "you don't need the blockchain or do it wrong").

Obviously, it neither compiles nor works.
#createService does not connect it to the Server yet — that is delayed
till some questions are resolved.
It has a potential issue with memory usage which we shall consider
together with the updates in Fork required for isolation of database
modifications from different services in prospective beforeCommit
Also, pass them to native in Protobuf. No 3D arrays any longer.
ViewFactory is moved to the runtime package, as its main usages are
there.

Code mounting the API is still to be taken from UserServiceAdapter
when the appropriate operation is added to the ServiceRuntime.

Usages of UserServiceAdapter in the Testkit are left as is.
Move ServiceRuntime to integration tests as it uses the native library.

Don't initialize the method ids of no longer existing classes
when the native library is loaded.

Setup some invocations.
Add Jira references where appropriate
@dmitry-timofeev
dmitry-timofeev force-pushed the service-runtime-for-ds-ECR-3404 branch from aadf8a7 to 4f54926 Compare August 20, 2019 11:53
@dmitry-timofeev
dmitry-timofeev changed the base branch from merkledb to dynamic-services August 20, 2019 11:53
@dmitry-timofeev
dmitry-timofeev changed the base branch from dynamic-services to master August 20, 2019 11:58
@dmitry-timofeev
dmitry-timofeev changed the base branch from master to dynamic-services August 20, 2019 11:58
@dmitry-timofeev
dmitry-timofeev merged commit d95151d into exonum:dynamic-services Aug 20, 2019
@dmitry-timofeev
dmitry-timofeev deleted the service-runtime-for-ds-ECR-3404 branch August 20, 2019 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants