-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add core API server in Rust #91
Conversation
6756040
to
c899cd3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work
Have a few misc comments - a few neatenings here or there, and slight questions about our need to us dyn
, but basically this is almost ready to merge I think
@@ -96,6 +96,9 @@ protected void configure() { | |||
binder.addBinding(HandlerRoute.get("/system/version")).to(VersionHandler.class); | |||
binder.addBinding(HandlerRoute.get("/system/peers")).to(PeersHandler.class); | |||
binder.addBinding(HandlerRoute.get("/system/addressbook")).to(AddressBookHandler.class); | |||
binder | |||
.addBinding(HandlerRoute.get("/system/network-sync-status")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from Core API? Seems sensible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, moved
@@ -73,37 +66,6 @@ public void setSyncStatus(SyncStatus syncStatus) { | |||
} | |||
|
|||
|
|||
public NetworkSyncStatusResponse peers(List<Peer> peers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess peers is returned through some other call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already in /system/peers
@@ -141,8 +140,6 @@ public PrometheusService( | |||
InMemorySystemInfo inMemorySystemInfo, | |||
@Self BFTNode self, | |||
Addressing addressing) { | |||
boolean enableTransactions = properties.get("api.transactions.enable", false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DevOps currently have this on the dashboard - I imagine we'll still have something like this in the new Core API?
Do we need to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's something to discuss. Does it still make sense to put this API behind a flag in babylon?
assertThat(bech32.getNodeHrp()).isEqualTo(addressing.forNodes().getHrp()); | ||
assertThat(bech32.getValidatorHrp()).isEqualTo(addressing.forValidators().getHrp()); | ||
assertThat(bech32.getResourceHrpSuffix()).isEqualTo(addressing.forResources().getHrp()); | ||
private static int mkNetworkConfigurationRequest(int port) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does mk
mean? Is it short for make
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, not a particularly char-saving abbreviation :D but quite commonly used across Linux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be up for making it make
to avoid any potential confusion? :D
// Act & Assert #1: start the server and verify it's up | ||
server.start(); | ||
final var statusCode = mkNetworkConfigurationRequest(port); | ||
assertEquals(200, statusCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the assert fails, will our server be shut down properly, or do we leak unmanaged memory, and possibly threads?
Do you think it might be worth creating some easy-to-use with try-with-resources Core Api runner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'm not a big fan of using auto-closeable for long living objects. Seems a bit off to me. I've added a regular try-finally block, if that's okay?
|
||
jni = "0.19.0" | ||
|
||
# Deps for generated models and the Hyper server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many dependencies and transient dependencies :( - are there any options on the generator to remove some of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately there aren't any config options for the generator; I've removed mime
and percent-encoding
deps which weren't used (all others are)
@@ -0,0 +1,16 @@ | |||
/// A workaround for including the symbols defined in state_manager / core_api_server | |||
/// in the output library file. See: https://github.com/rust-lang/rfcs/issues/2771 | |||
/// I truly have no idea why this works, but it does. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣 love it
request_payload: jbyteArray, | ||
) -> StateManagerResult<bool> { | ||
let state_manager = JNIStateManager::get_state_manager(env, sm_instance); | ||
let state_manager = JNIStateManager::get_state_manager(env, j_state_manager); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note - Ohh looks like I somehow missed changing these to use the new-fangled method for native functions 🤷
let jni_state_manager = JNIStateManager { state_manager }; | ||
let jni_state_manager = JNIStateManager { | ||
state_manager, | ||
// tokio_runtime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be removed now :D
&self, | ||
_context: &C, | ||
) -> Result<StatusNetworkConfigurationPostResponse, ApiError> { | ||
let network = &self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up - this will need changing after my network merge
pub struct JNIStateManager { | ||
pub state_manager: ActualStateManager, | ||
pub state_manager: Arc<Mutex<dyn StateManager + 'static + Send + Sync>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we stick to the jni rw lock for now? Feels too early to start implementing multithreaded locks around state manager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main reason is that the server gets it's own copy of the StateManager arc and needs to be able to lock on it outside of the jni context.
} | ||
} | ||
|
||
pub struct StateManagerImpl<M: Mempool, S> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StateManagerImpl vs StateManager trait feels like a broken use of dyn
and traits. Let's go over this sometime tomorrow.
998934b
to
007a72d
Compare
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I'd be happy to get this merged. I think Josh's objections have been dealt with, but if not, we can fix in a follow up PR? :)
@@ -98,7 +99,8 @@ public enum Network { | |||
LOCALSIMULATOR(242 /* 0xF1 */, "simulator", "sim", GenesisSource.fromConfiguration); | |||
|
|||
// For the Radix Shell to provide a default | |||
public static final String DefaultHexGenesisTransaction = "01"; | |||
public static final String DefaultHexGenesisTransaction = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused - why does this say Transaction
if it's generating a public key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the genesis from an integer (num of validators), to a list of validators pub keys a while back
.type(NetworkNotSupportedError.class.getSimpleName())); | ||
} | ||
/** | ||
* Stores a pointer to the rust state manager across JNI calls. In the JNI model, this is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment still needs updating - it says "rust state manager" but the pointer says "Core API"
] | ||
|
||
[[package]] | ||
name = "android_system_properties" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:'( yay open source. I just don't know how we somehow end up pulling in an android_system_properties
library via transitive dependencies...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chrono (provides DateTime) -> iana-time-zone -> android_system_properties 🤷♂️
api_version: API_VERSION.to_string(), | ||
}, | ||
network_identifier: NetworkIdentifier { | ||
network: format!("{:?}", network), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want network.logical_name
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 will do in the follow up PR (#95)
.to_string(), | ||
validator_hrp: "TODO".to_string(), | ||
node_hrp: "TODO".to_string(), | ||
resource_hrp_suffix: hrp_set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all a bit outdated hmm. We should probably change this to account
, resource
, system
, component
. Or maybe just return the network_hrp_suffix
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 will do in the follow up PR (#95)
Initial work towards core API server in Rust.