From a0e78c1978855a3578b051e92e3dd925ef1ddb26 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 24 Apr 2024 00:03:49 +0900 Subject: [PATCH 1/7] fixes: clean up provider and add more debug prints --- kinode/src/eth/mod.rs | 194 +++++++++++++++++++++------------ kinode/src/eth/subscription.rs | 4 +- kinode/src/main.rs | 1 + lib/src/eth.rs | 2 +- 4 files changed, 129 insertions(+), 72 deletions(-) diff --git a/kinode/src/eth/mod.rs b/kinode/src/eth/mod.rs index 46963286..fedfadb5 100644 --- a/kinode/src/eth/mod.rs +++ b/kinode/src/eth/mod.rs @@ -18,9 +18,13 @@ mod subscription; #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] enum IncomingReq { + /// requests for an RPC action that can come from processes on this node or others EthAction(EthAction), + /// requests that must come from this node to modify provider settings / fetch them EthConfigAction(EthConfigAction), + /// subscription updates coming in from a remote provider EthSubResult(EthSubResult), + /// a remote node who uses our provider keeping their subscription alive SubKeepalive(u64), } @@ -46,7 +50,9 @@ struct NodeProvider { /// semi-temporary flag to mark if this provider is currently usable /// future updates will make this more dynamic pub usable: bool, - pub name: String, + /// the KNS update that describes this node provider + /// kept so we can re-serialize to SavedConfigs + pub kns_update: KnsUpdate, } impl ActiveProviders { @@ -59,7 +65,7 @@ impl ActiveProviders { self.nodes.push(NodeProvider { trusted: new.trusted, usable: use_as_provider, - name: kns_update.name, + kns_update, }); } NodeOrRpcUrl::RpcUrl(url) => { @@ -74,7 +80,7 @@ impl ActiveProviders { fn remove_provider(&mut self, remove: &str) { self.urls.retain(|x| x.url != remove); - self.nodes.retain(|x| x.name != remove); + self.nodes.retain(|x| x.kns_update.name != remove); } } @@ -157,7 +163,9 @@ pub async fn provider( caps_oracle: CapMessageSender, print_tx: PrintSender, ) -> Result<()> { - // load access settings if they've been saved + // load access settings if they've been persisted to disk + // this merely describes whether our provider is available to other nodes + // and if so, which nodes are allowed to access it (public/whitelist/blacklist) let access_settings: AccessSettings = match tokio::fs::read_to_string(format!("{}/.eth_access_settings", home_directory_path)) .await @@ -183,6 +191,9 @@ pub async fn provider( ) .await; + // initialize module state + // fill out providers based on saved configs (possibly persisted, given to us) + // this can be a mix of node providers and rpc providers let mut state = ModuleState { our: Arc::new(our), home_directory_path, @@ -208,14 +219,13 @@ pub async fn provider( verbose_print(&state.print_tx, "eth: provider initialized").await; + // main loop: handle incoming network errors and incoming kernel messages loop { tokio::select! { Some(wrapped_error) = net_error_recv.recv() => { handle_network_error( wrapped_error, - &state.active_subscriptions, - &state.response_channels, - &state.print_tx + &state, ).await; } Some(km) = recv_in_client.recv() => { @@ -241,40 +251,54 @@ pub async fn provider( } } -async fn handle_network_error( - wrapped_error: WrappedSendError, - active_subscriptions: &ActiveSubscriptions, - response_channels: &ResponseChannels, - print_tx: &PrintSender, -) { - verbose_print(&print_tx, "eth: got network error").await; - // if we hold active subscriptions for the remote node that this error refers to, - // close them here -- they will need to resubscribe - // TODO is this necessary? - if let Some((_who, sub_map)) = active_subscriptions.remove(&wrapped_error.error.target) { - for (_sub_id, sub) in sub_map.iter() { - if let ActiveSub::Local(handle) = sub { - verbose_print( - &print_tx, - "eth: closing local sub in response to network error", - ) - .await; - handle.abort(); - } +/// network errors only come from remote provider nodes we tried to access, +/// or from remote nodes that are using us as a provider. +/// +/// if we tried to access them, we will have a response channel to send the error to. +/// if they are using us as a provider, close the subscription associated with the target. +async fn handle_network_error(wrapped_error: WrappedSendError, state: &ModuleState) { + verbose_print( + &state.print_tx, + &format!( + "eth: got network error from {}", + &wrapped_error.error.target + ), + ) + .await; + + // close all subscriptions held by the process that we (possibly) tried to send an update to + if let Some((_who, sub_map)) = state + .active_subscriptions + .remove(&wrapped_error.error.target) + { + for (sub_id, sub) in sub_map.iter() { + verbose_print( + &state.print_tx, + &format!( + "eth: closed subscription {} in response to network error", + sub_id + ), + ) + .await; + sub.close(*sub_id, state).await; } } - // we got an error from a remote node provider -- - // forward it to response channel if it exists - if let Some(chan) = response_channels.get(&wrapped_error.id) { - // can't close channel here, as response may be an error - // and fulfill_request may wish to try other providers. - verbose_print(&print_tx, "eth: sent network error to response channel").await; + + // forward error to response channel if it exists + if let Some(chan) = state.response_channels.get(&wrapped_error.id) { + // don't close channel here, as channel holder will wish to try other providers. + verbose_print( + &state.print_tx, + "eth: forwarded network error to response channel", + ) + .await; let _ = chan.send(Err(wrapped_error)).await; } } -/// handle incoming requests, namely [`EthAction`] and [`EthConfigAction`]. -/// also handle responses that are passthroughs from remote provider nodes. +/// handle incoming requests and responses. +/// requests must be one of types in [`IncomingReq`]. +/// responses are passthroughs from remote provider nodes. async fn handle_message( state: &mut ModuleState, km: KernelMessage, @@ -335,6 +359,8 @@ async fn handle_message( { if provider_node == &km.source.node { if let Ok(()) = sender.send(eth_sub_result).await { + // successfully sent a subscription update from a + // remote provider to one of our processes return Ok(()); } } @@ -367,6 +393,26 @@ async fn handle_message( return Ok(()); } } + verbose_print( + &state.print_tx, + "eth: got sub_keepalive but no matching sub found", + ) + .await; + // send a response with an EthSubError + kernel_message( + &state.our.clone(), + km.id, + km.source.clone(), + None, + false, + None, + EthSubResult::Err(EthSubError { + id: sub_id, + error: "Subscription not found".to_string(), + }), + &state.send_to_loop, + ) + .await; } } } @@ -382,7 +428,10 @@ async fn handle_eth_action( ) -> Result<(), EthError> { // check our access settings if the request is from a remote node if km.source.node != *state.our { - if state.access_settings.deny.contains(&km.source.node) { + if state.access_settings.deny.contains(&km.source.node) + || (!state.access_settings.public + && !state.access_settings.allow.contains(&km.source.node)) + { verbose_print( &state.print_tx, "eth: got eth_action from unauthorized remote source", @@ -390,21 +439,19 @@ async fn handle_eth_action( .await; return Err(EthError::PermissionDenied); } - if !state.access_settings.public { - if !state.access_settings.allow.contains(&km.source.node) { - verbose_print( - &state.print_tx, - "eth: got eth_action from unauthorized remote source", - ) - .await; - return Err(EthError::PermissionDenied); - } - } } verbose_print( &state.print_tx, - &format!("eth: handling eth_action {eth_action:?}"), + &format!( + "eth: handling {} from {}", + match ð_action { + EthAction::SubscribeLogs { .. } => "subscribe", + EthAction::UnsubscribeLogs(_) => "unsubscribe", + EthAction::Request { .. } => "request", + }, + km.source + ), ) .await; @@ -517,7 +564,11 @@ async fn fulfill_request( Some(pubsub) => pubsub, None => { if let Ok(()) = activate_url_provider(url_provider).await { - verbose_print(print_tx, "eth: activated a url provider").await; + verbose_print( + print_tx, + &format!("eth: activated url provider {}", url_provider.url), + ) + .await; url_provider.pubsub.as_ref().unwrap() } else { continue; @@ -563,14 +614,14 @@ async fn forward_to_node_provider( send_to_loop: &MessageSender, receiver: &mut ProcessMessageReceiver, ) -> EthResponse { - if !node_provider.usable || node_provider.name == our { + if !node_provider.usable || node_provider.kns_update.name == our { return EthResponse::Err(EthError::PermissionDenied); } kernel_message( our, km_id, Address { - node: node_provider.name.clone(), + node: node_provider.kns_update.name.clone(), process: ETH_PROCESS_ID.clone(), }, rsvp, @@ -627,6 +678,7 @@ async fn handle_eth_config_action( ) .await; + let mut save_settings = false; let mut save_providers = false; // modify our providers and access settings based on config action @@ -650,21 +702,27 @@ async fn handle_eth_config_action( } EthConfigAction::SetPublic => { state.access_settings.public = true; + save_settings = true; } EthConfigAction::SetPrivate => { state.access_settings.public = false; + save_settings = true; } EthConfigAction::AllowNode(node) => { state.access_settings.allow.insert(node); + save_settings = true; } EthConfigAction::UnallowNode(node) => { state.access_settings.allow.remove(&node); + save_settings = true; } EthConfigAction::DenyNode(node) => { state.access_settings.deny.insert(node); + save_settings = true; } EthConfigAction::UndenyNode(node) => { state.access_settings.deny.remove(&node); + save_settings = true; } EthConfigAction::SetProviders(new_providers) => { let new_map = DashMap::new(); @@ -713,20 +771,26 @@ async fn handle_eth_config_action( }; } } - // save providers and access settings to disk - let _ = tokio::fs::write( - format!("{}/.eth_access_settings", state.home_directory_path), - serde_json::to_string(&state.access_settings).unwrap(), - ) - .await; - verbose_print(&state.print_tx, "eth: saved new access settings").await; + // save providers and/or access settings, depending on necessity, to disk + if save_settings { + if let Ok(()) = tokio::fs::write( + format!("{}/.eth_access_settings", state.home_directory_path), + serde_json::to_string(&state.access_settings).unwrap(), + ) + .await + { + verbose_print(&state.print_tx, "eth: saved new access settings").await; + }; + } if save_providers { - let _ = tokio::fs::write( + if let Ok(()) = tokio::fs::write( format!("{}/.eth_providers", state.home_directory_path), serde_json::to_string(&providers_to_saved_configs(&state.providers)).unwrap(), ) - .await; - verbose_print(&state.print_tx, "eth: saved new provider settings").await; + .await + { + verbose_print(&state.print_tx, "eth: saved new provider settings").await; + }; } EthConfigResponse::Ok } @@ -767,15 +831,7 @@ fn providers_to_saved_configs(providers: &Providers) -> SavedConfigs { .chain(entry.nodes.iter().map(|node_provider| ProviderConfig { chain_id: *entry.key(), provider: NodeOrRpcUrl::Node { - kns_update: KnsUpdate { - name: node_provider.name.clone(), - owner: "".to_string(), - node: "".to_string(), - public_key: "".to_string(), - ip: "".to_string(), - port: 0, - routers: vec![], - }, + kns_update: node_provider.kns_update.clone(), use_as_provider: node_provider.usable, }, trusted: node_provider.trusted, diff --git a/kinode/src/eth/subscription.rs b/kinode/src/eth/subscription.rs index 86adf51e..234d4094 100644 --- a/kinode/src/eth/subscription.rs +++ b/kinode/src/eth/subscription.rs @@ -50,7 +50,7 @@ pub async fn create_new_subscription( Ok(rx) => { subs.insert( sub_id, - // this is a local sub, as in, we connect to the rpc endpt + // this is a local sub, as in, we connect to the rpc endpoint ActiveSub::Local(tokio::spawn(async move { // await the subscription error and kill it if so if let Err(e) = maintain_local_subscription( @@ -232,7 +232,7 @@ async fn build_subscription( ) .await; response_channels.remove(&km_id); - return Ok(Err((node_provider.name.clone(), remote_sub_id))); + return Ok(Err((node_provider.kns_update.name.clone(), remote_sub_id))); } EthResponse::Response { .. } => { // the response to a SubscribeLogs request must be an 'ok' diff --git a/kinode/src/main.rs b/kinode/src/main.rs index 3c8ad411..99cdbd12 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -1,3 +1,4 @@ +#![feature(async_closure)] #![feature(btree_extract_if)] use anyhow::Result; diff --git a/lib/src/eth.rs b/lib/src/eth.rs index e8026b5e..2c071e5b 100644 --- a/lib/src/eth.rs +++ b/lib/src/eth.rs @@ -155,7 +155,7 @@ pub struct ProviderConfig { pub enum NodeOrRpcUrl { Node { kns_update: crate::core::KnsUpdate, - use_as_provider: bool, // for routers inside saved config + use_as_provider: bool, // false for just-routers inside saved config }, RpcUrl(String), } From cca3133b61614503bc85f40998214e75263ae1d2 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 24 Apr 2024 03:40:57 +0900 Subject: [PATCH 2/7] fix: kns_indexer, update all packages to process_lib 0.7.0, change default providers --- Cargo.lock | 367 ++++++++++++++---- Cargo.toml | 2 +- kinode/Cargo.toml | 2 +- .../packages/app_store/app_store/Cargo.toml | 8 +- .../packages/app_store/app_store/src/lib.rs | 1 + .../packages/app_store/app_store/src/types.rs | 38 +- kinode/packages/app_store/download/Cargo.toml | 2 +- .../packages/app_store/ft_worker/Cargo.toml | 2 +- kinode/packages/app_store/install/Cargo.toml | 2 +- kinode/packages/app_store/metadata.json | 4 +- .../packages/app_store/uninstall/Cargo.toml | 2 +- kinode/packages/chess/chess/Cargo.toml | 4 +- kinode/packages/chess/metadata.json | 4 +- kinode/packages/homepage/homepage/Cargo.toml | 4 +- kinode/packages/homepage/metadata.json | 4 +- .../packages/kns_indexer/get_block/Cargo.toml | 2 +- .../kns_indexer/kns_indexer/Cargo.toml | 8 +- .../kns_indexer/kns_indexer/src/lib.rs | 39 +- kinode/packages/kns_indexer/metadata.json | 6 +- kinode/packages/kns_indexer/state/Cargo.toml | 2 +- kinode/packages/terminal/alias/Cargo.toml | 2 +- kinode/packages/terminal/cat/Cargo.toml | 2 +- kinode/packages/terminal/echo/Cargo.toml | 2 +- kinode/packages/terminal/hi/Cargo.toml | 2 +- kinode/packages/terminal/m/Cargo.toml | 2 +- kinode/packages/terminal/metadata.json | 4 +- .../terminal/namehash_to_name/Cargo.toml | 2 +- .../terminal/net_diagnostics/Cargo.toml | 2 +- kinode/packages/terminal/peer/Cargo.toml | 2 +- kinode/packages/terminal/peers/Cargo.toml | 2 +- kinode/packages/terminal/terminal/Cargo.toml | 4 +- kinode/packages/terminal/top/Cargo.toml | 2 +- kinode/packages/tester/metadata.json | 4 +- kinode/packages/tester/test_runner/Cargo.toml | 2 +- kinode/packages/tester/tester/Cargo.toml | 4 +- kinode/src/eth/default_providers_mainnet.json | 94 +---- kinode/src/eth/mod.rs | 40 +- lib/Cargo.toml | 2 +- 38 files changed, 435 insertions(+), 242 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74bd89d8..d5621431 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,7 +78,7 @@ name = "alias" version = "0.1.0" dependencies = [ "anyhow", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -90,36 +90,85 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "alloy-consensus" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=cad7935#cad7935d69f433e45d190902e58b1c996b35adfa" +dependencies = [ + "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cad7935)", + "alloy-primitives 0.7.0", + "alloy-rlp", + "alloy-serde", + "c-kzg", + "serde", + "sha2", +] + [[package]] name = "alloy-eips" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.6.4", "alloy-rlp", "serde", "thiserror", ] +[[package]] +name = "alloy-eips" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=cad7935#cad7935d69f433e45d190902e58b1c996b35adfa" +dependencies = [ + "alloy-primitives 0.7.0", + "alloy-rlp", + "alloy-serde", + "c-kzg", + "once_cell", + "serde", +] + +[[package]] +name = "alloy-genesis" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=cad7935#cad7935d69f433e45d190902e58b1c996b35adfa" +dependencies = [ + "alloy-primitives 0.7.0", + "alloy-serde", + "serde", +] + [[package]] name = "alloy-json-rpc" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.6.4", "serde", "serde_json", "thiserror", ] +[[package]] +name = "alloy-json-rpc" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=cad7935#cad7935d69f433e45d190902e58b1c996b35adfa" +dependencies = [ + "alloy-primitives 0.7.0", + "serde", + "serde_json", + "thiserror", + "tracing", +] + [[package]] name = "alloy-network" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-eips", - "alloy-json-rpc", - "alloy-primitives", + "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-primitives 0.6.4", "alloy-rlp", "serde", ] @@ -146,17 +195,39 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "alloy-primitives" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99bbad0a6b588ef4aec1b5ddbbfdacd9ef04e00b979617765b03174318ee1f3a" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if", + "const-hex", + "derive_more", + "hex-literal", + "itoa", + "k256", + "keccak-asm", + "proptest", + "rand 0.8.5", + "ruint", + "serde", + "tiny-keccak", +] + [[package]] name = "alloy-providers" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ "alloy-network", - "alloy-primitives", + "alloy-primitives 0.6.4", "alloy-rpc-client", "alloy-rpc-trace-types", - "alloy-rpc-types", - "alloy-transport", + "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-transport 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "alloy-transport-http", "async-trait", "auto_impl", @@ -170,9 +241,9 @@ name = "alloy-pubsub" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-json-rpc", - "alloy-primitives", - "alloy-transport", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-primitives 0.6.4", + "alloy-transport 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "bimap", "futures", "serde", @@ -209,10 +280,10 @@ name = "alloy-rpc-client" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-json-rpc", - "alloy-primitives", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-primitives 0.6.4", "alloy-pubsub", - "alloy-transport", + "alloy-transport 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "alloy-transport-http", "alloy-transport-ws", "futures", @@ -230,8 +301,8 @@ name = "alloy-rpc-trace-types" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-primitives", - "alloy-rpc-types", + "alloy-primitives 0.6.4", + "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "serde", "serde_json", ] @@ -241,7 +312,7 @@ name = "alloy-rpc-types" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.6.4", "alloy-rlp", "itertools 0.12.1", "serde", @@ -249,13 +320,41 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-rpc-types" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=cad7935#cad7935d69f433e45d190902e58b1c996b35adfa" +dependencies = [ + "alloy-consensus", + "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cad7935)", + "alloy-genesis", + "alloy-primitives 0.7.0", + "alloy-rlp", + "alloy-serde", + "alloy-sol-types 0.7.0", + "itertools 0.12.1", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "alloy-serde" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=cad7935#cad7935d69f433e45d190902e58b1c996b35adfa" +dependencies = [ + "alloy-primitives 0.7.0", + "serde", + "serde_json", +] + [[package]] name = "alloy-signer" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ "alloy-network", - "alloy-primitives", + "alloy-primitives 0.6.4", "async-trait", "auto_impl", "elliptic-curve", @@ -278,18 +377,63 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.60", - "syn-solidity", + "syn-solidity 0.6.4", "tiny-keccak", ] +[[package]] +name = "alloy-sol-macro" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "452d929748ac948a10481fff4123affead32c553cf362841c5103dd508bdfc16" +dependencies = [ + "alloy-sol-macro-input", + "const-hex", + "heck 0.4.1", + "indexmap", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.60", + "syn-solidity 0.7.0", + "tiny-keccak", +] + +[[package]] +name = "alloy-sol-macro-input" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df64e094f6d2099339f9e82b5b38440b159757b6920878f28316243f8166c8d1" +dependencies = [ + "const-hex", + "dunce", + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.60", + "syn-solidity 0.7.0", +] + [[package]] name = "alloy-sol-types" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad09ec5853fa700d12d778ad224dcdec636af424d29fad84fb9a2f16a5b0ef09" dependencies = [ - "alloy-primitives", - "alloy-sol-macro", + "alloy-primitives 0.6.4", + "alloy-sol-macro 0.6.4", + "const-hex", + "serde", +] + +[[package]] +name = "alloy-sol-types" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43bc2d6dfc2a19fd56644494479510f98b1ee929e04cf0d4aa45e98baa3e545b" +dependencies = [ + "alloy-primitives 0.7.0", + "alloy-sol-macro 0.7.0", "const-hex", "serde", ] @@ -299,7 +443,7 @@ name = "alloy-transport" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-json-rpc", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "base64 0.21.7", "futures-util", "serde", @@ -311,13 +455,31 @@ dependencies = [ "wasm-bindgen-futures", ] +[[package]] +name = "alloy-transport" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=cad7935#cad7935d69f433e45d190902e58b1c996b35adfa" +dependencies = [ + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cad7935)", + "base64 0.22.0", + "futures-util", + "futures-utils-wasm", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower", + "url", + "wasm-bindgen-futures", +] + [[package]] name = "alloy-transport-http" version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ - "alloy-json-rpc", - "alloy-transport", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-transport 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "reqwest 0.11.27", "serde_json", "tower", @@ -330,7 +492,7 @@ version = "0.1.0" source = "git+https://github.com/alloy-rs/alloy?rev=6f8ebb4#6f8ebb45afca1a201a11d421ec46db0f7a1d8d08" dependencies = [ "alloy-pubsub", - "alloy-transport", + "alloy-transport 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "futures", "http 0.2.12", "serde_json", @@ -417,13 +579,13 @@ checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "app_store" -version = "0.3.0" +version = "0.3.1" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.7.0", + "alloy-sol-types 0.7.0", "anyhow", "bincode", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rand 0.8.5", "serde", "serde_json", @@ -778,6 +940,18 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "blst" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c94087b935a822949d3291a9989ad2b2051ea141eda0fd4e478a75f6aa3e604b" +dependencies = [ + "cc", + "glob", + "threadpool", + "zeroize", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -826,6 +1000,20 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "c-kzg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3130f3d8717cc02e668a896af24984d5d5d4e8bf12e278e982e0f1bd88a0f9af" +dependencies = [ + "blst", + "cc", + "glob", + "hex", + "libc", + "serde", +] + [[package]] name = "cap-fs-ext" version = "3.0.0" @@ -908,7 +1096,7 @@ name = "cat" version = "0.1.0" dependencies = [ "anyhow", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -966,12 +1154,12 @@ dependencies = [ [[package]] name = "chess" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "base64 0.22.0", "bincode", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "pleco", "serde", "serde_json", @@ -1683,7 +1871,7 @@ name = "download" version = "0.1.0" dependencies = [ "anyhow", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -1714,7 +1902,7 @@ name = "echo" version = "0.1.0" dependencies = [ "anyhow", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -1934,7 +2122,7 @@ version = "0.2.0" dependencies = [ "anyhow", "bincode", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rand 0.8.5", "serde", "serde_json", @@ -2042,6 +2230,12 @@ dependencies = [ "slab", ] +[[package]] +name = "futures-utils-wasm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42012b0f064e01aa58b545fe3727f90f7dd4020f4a3ea735b50344965f5a57e9" + [[package]] name = "fxhash" version = "0.2.1" @@ -2088,7 +2282,7 @@ dependencies = [ name = "get_block" version = "0.1.0" dependencies = [ - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -2288,7 +2482,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "hi" version = "0.1.0" dependencies = [ - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -2314,11 +2508,11 @@ dependencies = [ [[package]] name = "homepage" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "bincode", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -2629,7 +2823,7 @@ name = "install" version = "0.1.0" dependencies = [ "anyhow", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -2788,17 +2982,17 @@ dependencies = [ [[package]] name = "kinode" -version = "0.7.0" +version = "0.7.1" dependencies = [ "aes-gcm", - "alloy-primitives", + "alloy-primitives 0.6.4", "alloy-providers", "alloy-pubsub", "alloy-rpc-client", - "alloy-rpc-types", + "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "alloy-signer", - "alloy-sol-macro", - "alloy-sol-types", + "alloy-sol-macro 0.6.4", + "alloy-sol-types 0.6.4", "alloy-transport-ws", "anyhow", "async-trait", @@ -2861,7 +3055,7 @@ dependencies = [ [[package]] name = "kinode_lib" -version = "0.7.0" +version = "0.7.1" dependencies = [ "lib", ] @@ -2871,10 +3065,10 @@ name = "kinode_process_lib" version = "0.6.0" source = "git+https://github.com/kinode-dao/process_lib?rev=84b3d84#84b3d84c7c31185f15691a288f1b45dbffb18fe2" dependencies = [ - "alloy-json-rpc", - "alloy-primitives", - "alloy-rpc-types", - "alloy-transport", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-primitives 0.6.4", + "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", + "alloy-transport 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "anyhow", "bincode", "http 1.1.0", @@ -2889,13 +3083,13 @@ dependencies = [ [[package]] name = "kinode_process_lib" -version = "0.6.1" -source = "git+https://github.com/kinode-dao/process_lib?tag=v0.6.1#37a20b0249dc2c86ae6c2c69cfb199fb177f1520" +version = "0.7.0" +source = "git+https://github.com/kinode-dao/process_lib?tag=v0.7.0#b7c0abee62df683e6c78069c87072a1d52602408" dependencies = [ - "alloy-json-rpc", - "alloy-primitives", - "alloy-rpc-types", - "alloy-transport", + "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cad7935)", + "alloy-primitives 0.7.0", + "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cad7935)", + "alloy-transport 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cad7935)", "anyhow", "bincode", "http 1.1.0", @@ -2945,14 +3139,14 @@ dependencies = [ [[package]] name = "kns_indexer" -version = "0.2.0" +version = "0.2.1" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.7.0", + "alloy-sol-types 0.7.0", "anyhow", "bincode", "hex", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rmp-serde", "serde", "serde_json", @@ -2979,9 +3173,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "lib" -version = "0.7.0" +version = "0.7.1" dependencies = [ - "alloy-rpc-types", + "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "anyhow", "kit", "lazy_static", @@ -3153,7 +3347,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "regex", "serde", "serde_json", @@ -3285,7 +3479,7 @@ dependencies = [ name = "namehash_to_name" version = "0.1.0" dependencies = [ - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rmp-serde", "serde", "wit-bindgen", @@ -3313,7 +3507,7 @@ dependencies = [ name = "net_diagnostics" version = "0.1.0" dependencies = [ - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rmp-serde", "serde", "wit-bindgen", @@ -3606,7 +3800,7 @@ dependencies = [ name = "peer" version = "0.1.0" dependencies = [ - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rmp-serde", "serde", "wit-bindgen", @@ -3616,7 +3810,7 @@ dependencies = [ name = "peers" version = "0.1.0" dependencies = [ - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rmp-serde", "serde", "wit-bindgen", @@ -4829,7 +5023,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" name = "state" version = "0.1.0" dependencies = [ - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -4910,6 +5104,18 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "syn-solidity" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4497156948bd342b52038035a6fa514a89626e37af9d2c52a5e8d8ebcc7ee479" +dependencies = [ + "paste", + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "sync_wrapper" version = "0.1.2" @@ -4979,11 +5185,11 @@ dependencies = [ [[package]] name = "terminal" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "bincode", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "rand 0.8.5", "regex", "serde", @@ -4997,7 +5203,7 @@ version = "0.1.0" dependencies = [ "anyhow", "bincode", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "thiserror", @@ -5006,12 +5212,12 @@ dependencies = [ [[package]] name = "tester" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "bincode", "indexmap", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "thiserror", @@ -5048,6 +5254,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + [[package]] name = "time" version = "0.3.36" @@ -5243,7 +5458,7 @@ name = "top" version = "0.1.0" dependencies = [ "anyhow", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", @@ -5565,7 +5780,7 @@ name = "uninstall" version = "0.1.0" dependencies = [ "anyhow", - "kinode_process_lib 0.6.1", + "kinode_process_lib 0.7.0", "serde", "serde_json", "wit-bindgen", diff --git a/Cargo.toml b/Cargo.toml index b25f0577..6cc9242d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kinode_lib" authors = ["KinodeDAO"] -version = "0.7.0" +version = "0.7.1" edition = "2021" description = "A general-purpose sovereign cloud computing platform" homepage = "https://kinode.org" diff --git a/kinode/Cargo.toml b/kinode/Cargo.toml index 34ef95a2..0776fa6b 100644 --- a/kinode/Cargo.toml +++ b/kinode/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kinode" authors = ["KinodeDAO"] -version = "0.7.0" +version = "0.7.1" edition = "2021" description = "A general-purpose sovereign cloud computing platform" homepage = "https://kinode.org" diff --git a/kinode/packages/app_store/app_store/Cargo.toml b/kinode/packages/app_store/app_store/Cargo.toml index cb4a23c7..60ef9300 100644 --- a/kinode/packages/app_store/app_store/Cargo.toml +++ b/kinode/packages/app_store/app_store/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "app_store" -version = "0.3.0" +version = "0.3.1" edition = "2021" [features] simulation-mode = [] [dependencies] -alloy-primitives = "0.6.2" -alloy-sol-types = "0.6.2" +alloy-primitives = "0.7.0" +alloy-sol-types = "0.7.0" anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/kinode/packages/app_store/app_store/src/lib.rs b/kinode/packages/app_store/app_store/src/lib.rs index a5ee2da1..d0f4a92a 100644 --- a/kinode/packages/app_store/app_store/src/lib.rs +++ b/kinode/packages/app_store/app_store/src/lib.rs @@ -41,6 +41,7 @@ const ICON: &str = include_str!("icon"); const CHAIN_ID: u64 = 10; // optimism const CONTRACT_ADDRESS: &str = "0x52185B6a6017E6f079B994452F234f7C2533787B"; // optimism +const CONTRACT_FIRST_BLOCK: u64 = 118_590_088; const EVENTS: [&str; 3] = [ "AppRegistered(uint256,string,bytes,string,bytes32)", diff --git a/kinode/packages/app_store/app_store/src/types.rs b/kinode/packages/app_store/app_store/src/types.rs index afef5d01..427e0eaf 100644 --- a/kinode/packages/app_store/app_store/src/types.rs +++ b/kinode/packages/app_store/app_store/src/types.rs @@ -111,7 +111,7 @@ impl State { crate::print_to_terminal(1, "producing new state"); let mut state = State { contract_address, - last_saved_block: 1, + last_saved_block: crate::CONTRACT_FIRST_BLOCK, package_hashes: HashMap::new(), listed_packages: HashMap::new(), downloaded_packages: HashMap::new(), @@ -371,14 +371,16 @@ impl State { .ok_or(anyhow::anyhow!("got log with no block number"))? .try_into()?; - // let package_hash: alloy_primitives::U256 = log.topics[1].into(); - // let package_hash = package_hash.to_string(); - - match log.topics[0] { + match log.topics()[0] { AppRegistered::SIGNATURE_HASH => { - let package_hash = log.topics[1]; - let (package_name, publisher_dnswire, metadata_url, metadata_hash) = - AppRegistered::abi_decode_data(&log.data, true)?; + let package_hash = log.topics()[1]; + + let app = AppRegistered::decode_log_data(log.data(), false)?; + let package_name = app.packageName; + let publisher_dnswire = app.publisherName; + let metadata_url = app.metadataUrl; + let metadata_hash = app.metadataHash; + let package_hash = package_hash.to_string(); let metadata_hash = metadata_hash.to_string(); @@ -390,13 +392,14 @@ impl State { ), ); - if generate_package_hash(&package_name, publisher_dnswire.as_slice()) + if generate_package_hash(&package_name, publisher_dnswire.to_vec().as_slice()) != package_hash { return Err(anyhow::anyhow!("got log with mismatched package hash")); } - let Ok(publisher_name) = dnswire_decode(publisher_dnswire.as_slice()) else { + let Ok(publisher_name) = dnswire_decode(publisher_dnswire.to_vec().as_slice()) + else { return Err(anyhow::anyhow!("got log with invalid publisher name")); }; @@ -430,9 +433,12 @@ impl State { self.insert_listing(package_hash, listing); } AppMetadataUpdated::SIGNATURE_HASH => { - let package_hash = log.topics[1].to_string(); - let (metadata_url, metadata_hash) = - AppMetadataUpdated::abi_decode_data(&log.data, false)?; + let package_hash = log.topics()[1].to_string(); + + let upd = AppMetadataUpdated::decode_log_data(log.data(), false)?; + let metadata_url = upd.metadataUrl; + let metadata_hash = upd.metadataHash; + let metadata_hash = metadata_hash.to_string(); let current_listing = self @@ -484,9 +490,9 @@ impl State { } } Transfer::SIGNATURE_HASH => { - let from = alloy_primitives::Address::from_word(log.topics[1]); - let to = alloy_primitives::Address::from_word(log.topics[2]); - let package_hash = log.topics[3].to_string(); + let from = alloy_primitives::Address::from_word(log.topics()[1]); + let to = alloy_primitives::Address::from_word(log.topics()[2]); + let package_hash = log.topics()[3].to_string(); if from == alloy_primitives::Address::ZERO { match self.get_listing_with_hash_mut(&package_hash) { diff --git a/kinode/packages/app_store/download/Cargo.toml b/kinode/packages/app_store/download/Cargo.toml index cf10e764..ec78a53a 100644 --- a/kinode/packages/app_store/download/Cargo.toml +++ b/kinode/packages/app_store/download/Cargo.toml @@ -8,7 +8,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/app_store/ft_worker/Cargo.toml b/kinode/packages/app_store/ft_worker/Cargo.toml index 89031b71..23a0c8d1 100644 --- a/kinode/packages/app_store/ft_worker/Cargo.toml +++ b/kinode/packages/app_store/ft_worker/Cargo.toml @@ -9,7 +9,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/kinode/packages/app_store/install/Cargo.toml b/kinode/packages/app_store/install/Cargo.toml index dadf327f..8c24d74c 100644 --- a/kinode/packages/app_store/install/Cargo.toml +++ b/kinode/packages/app_store/install/Cargo.toml @@ -8,7 +8,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/app_store/metadata.json b/kinode/packages/app_store/metadata.json index 43106e13..68693944 100644 --- a/kinode/packages/app_store/metadata.json +++ b/kinode/packages/app_store/metadata.json @@ -4,11 +4,11 @@ "image": "", "properties": { "package_name": "app_store", - "current_version": "0.3.0", + "current_version": "0.3.1", "publisher": "sys", "mirrors": [], "code_hashes": { - "0.3.0": "" + "0.3.1": "" } }, "external_url": "https://kinode.org", diff --git a/kinode/packages/app_store/uninstall/Cargo.toml b/kinode/packages/app_store/uninstall/Cargo.toml index b3a28efd..8bfe76eb 100644 --- a/kinode/packages/app_store/uninstall/Cargo.toml +++ b/kinode/packages/app_store/uninstall/Cargo.toml @@ -8,7 +8,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/chess/chess/Cargo.toml b/kinode/packages/chess/chess/Cargo.toml index 4d397306..a39ebd18 100644 --- a/kinode/packages/chess/chess/Cargo.toml +++ b/kinode/packages/chess/chess/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chess" -version = "0.2.0" +version = "0.2.1" edition = "2021" [features] @@ -10,7 +10,7 @@ simulation-mode = [] anyhow = "1.0" base64 = "0.22.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } pleco = "0.5" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/kinode/packages/chess/metadata.json b/kinode/packages/chess/metadata.json index b40ba7bc..a8d4af7b 100644 --- a/kinode/packages/chess/metadata.json +++ b/kinode/packages/chess/metadata.json @@ -4,11 +4,11 @@ "image": "", "properties": { "package_name": "chess", - "current_version": "0.2.0", + "current_version": "0.2.1", "publisher": "sys", "mirrors": [], "code_hashes": { - "0.2.0": "" + "0.2.1": "" } }, "external_url": "https://kinode.org", diff --git a/kinode/packages/homepage/homepage/Cargo.toml b/kinode/packages/homepage/homepage/Cargo.toml index acadadb0..c908f109 100644 --- a/kinode/packages/homepage/homepage/Cargo.toml +++ b/kinode/packages/homepage/homepage/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "homepage" -version = "0.1.0" +version = "0.1.1" edition = "2021" [features] @@ -9,7 +9,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/homepage/metadata.json b/kinode/packages/homepage/metadata.json index de80df72..146bae33 100644 --- a/kinode/packages/homepage/metadata.json +++ b/kinode/packages/homepage/metadata.json @@ -4,11 +4,11 @@ "image": "", "properties": { "package_name": "homepage", - "current_version": "0.1.0", + "current_version": "0.1.1", "publisher": "sys", "mirrors": [], "code_hashes": { - "0.1.0": "" + "0.1.1": "" } }, "external_url": "https://kinode.org", diff --git a/kinode/packages/kns_indexer/get_block/Cargo.toml b/kinode/packages/kns_indexer/get_block/Cargo.toml index be4a5250..66a53175 100644 --- a/kinode/packages/kns_indexer/get_block/Cargo.toml +++ b/kinode/packages/kns_indexer/get_block/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" simulation-mode = [] [dependencies] -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/kns_indexer/kns_indexer/Cargo.toml b/kinode/packages/kns_indexer/kns_indexer/Cargo.toml index a90116e7..0ecdc055 100644 --- a/kinode/packages/kns_indexer/kns_indexer/Cargo.toml +++ b/kinode/packages/kns_indexer/kns_indexer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kns_indexer" -version = "0.2.0" +version = "0.2.1" edition = "2021" [features] @@ -8,11 +8,11 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -alloy-primitives = "0.6.2" -alloy-sol-types = "0.6.2" +alloy-primitives = "0.7.0" +alloy-sol-types = "0.7.0" bincode = "1.3.3" hex = "0.4.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rmp-serde = "1.1.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs index 71d6dcd8..5e90a163 100644 --- a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs +++ b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs @@ -17,6 +17,7 @@ wit_bindgen::generate!({ // perhaps a constant in process_lib? const KNS_OPTIMISM_ADDRESS: &'static str = "0xca5b5811c0c40aab3295f932b1b5112eb7bb4bd6"; +const KNS_FIRST_BLOCK: u64 = 114_923_786; #[derive(Clone, Debug, Serialize, Deserialize)] struct State { @@ -132,7 +133,7 @@ fn init(our: Address) { contract_address, names: HashMap::new(), nodes: HashMap::new(), - block: 1, + block: KNS_FIRST_BLOCK, } } else { println!("loading in {} persisted PKI entries", s.nodes.len()); @@ -144,7 +145,7 @@ fn init(our: Address) { contract_address: contract_address.clone(), names: HashMap::new(), nodes: HashMap::new(), - block: 1, + block: KNS_FIRST_BLOCK, }, }; @@ -188,7 +189,12 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> { match eth_provider.get_logs(&filter) { Ok(logs) => { for log in logs { - handle_log(&our, &mut state, &log)?; + match handle_log(&our, &mut state, &log) { + Ok(_) => {} + Err(e) => { + println!("log-handling error! {e:?}"); + } + } } break; } @@ -345,7 +351,7 @@ fn handle_eth_message( } fn handle_log(our: &Address, state: &mut State, log: ð::Log) -> anyhow::Result<()> { - let node_id = log.topics[1]; + let node_id = log.topics()[1]; let name = match state.names.entry(node_id.to_string()) { Entry::Occupied(o) => o.into_mut(), @@ -359,15 +365,15 @@ fn handle_log(our: &Address, state: &mut State, log: ð::Log) -> anyhow::Resul let mut send = true; - match log.topics[0] { + match log.topics()[0] { KeyUpdate::SIGNATURE_HASH => { - node.public_key = KeyUpdate::abi_decode_data(&log.data, true) + node.public_key = KeyUpdate::decode_log_data(log.data(), true) .unwrap() - .0 + .key .to_string(); } IpUpdate::SIGNATURE_HASH => { - let ip = IpUpdate::abi_decode_data(&log.data, true).unwrap().0; + let ip = IpUpdate::decode_log_data(log.data(), true).unwrap().ip; node.ip = format!( "{}.{}.{}.{}", (ip >> 24) & 0xFF, @@ -380,15 +386,15 @@ fn handle_log(our: &Address, state: &mut State, log: ð::Log) -> anyhow::Resul node.routers = vec![]; } WsUpdate::SIGNATURE_HASH => { - node.port = WsUpdate::abi_decode_data(&log.data, true).unwrap().0; + node.port = WsUpdate::decode_log_data(log.data(), true).unwrap().port; // when we get port data, we should delete any router data, // since the assignment of port indicates an direct node node.routers = vec![]; } RoutingUpdate::SIGNATURE_HASH => { - node.routers = RoutingUpdate::abi_decode_data(&log.data, true) + node.routers = RoutingUpdate::decode_log_data(log.data(), true) .unwrap() - .0 + .routers .iter() .map(|r| r.to_string()) .collect::>(); @@ -413,7 +419,7 @@ fn handle_log(our: &Address, state: &mut State, log: ð::Log) -> anyhow::Resul } // if new block is > 100 from last block, save state - let block = log.block_number.expect("expect").to::(); + let block = log.block_number.expect("expect"); if block > state.block + 100 { kinode_process_lib::print_to_terminal( 1, @@ -430,9 +436,12 @@ fn handle_log(our: &Address, state: &mut State, log: ð::Log) -> anyhow::Resul } fn get_name(log: ð::Log) -> anyhow::Result { - let decoded = - NodeRegistered::abi_decode_data(&log.data, true).map_err(|e| anyhow::anyhow!(e))?; - dnswire_decode(decoded.0.clone()).map_err(|e| anyhow::anyhow!(e)) + let decoded = NodeRegistered::decode_log_data(log.data(), false).map_err(|_e| { + anyhow::anyhow!( + "got event other than NodeRegistered without knowing about existing node name" + ) + })?; + dnswire_decode(decoded.name.to_vec()).map_err(|e| anyhow::anyhow!(e)) } fn dnswire_decode(wire_format_bytes: Vec) -> Result { diff --git a/kinode/packages/kns_indexer/metadata.json b/kinode/packages/kns_indexer/metadata.json index bc28db53..9dd45ab0 100644 --- a/kinode/packages/kns_indexer/metadata.json +++ b/kinode/packages/kns_indexer/metadata.json @@ -1,14 +1,14 @@ { "name": "KNS Indexer", - "description": "Kinode OS pki indexer", + "description": "Kinode OS PKI indexer", "image": "", "properties": { "package_name": "kns_indexer", - "current_version": "0.1.0", + "current_version": "0.2.1", "publisher": "sys", "mirrors": [], "code_hashes": { - "0.1.0": "" + "0.2.1": "" } }, "external_url": "https://kinode.org", diff --git a/kinode/packages/kns_indexer/state/Cargo.toml b/kinode/packages/kns_indexer/state/Cargo.toml index 7f1889db..77cc580c 100644 --- a/kinode/packages/kns_indexer/state/Cargo.toml +++ b/kinode/packages/kns_indexer/state/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" simulation-mode = [] [dependencies] -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/alias/Cargo.toml b/kinode/packages/terminal/alias/Cargo.toml index ecbf584e..6d9f3c5f 100644 --- a/kinode/packages/terminal/alias/Cargo.toml +++ b/kinode/packages/terminal/alias/Cargo.toml @@ -8,7 +8,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/cat/Cargo.toml b/kinode/packages/terminal/cat/Cargo.toml index d6ba3fd4..c297f22f 100644 --- a/kinode/packages/terminal/cat/Cargo.toml +++ b/kinode/packages/terminal/cat/Cargo.toml @@ -8,7 +8,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/echo/Cargo.toml b/kinode/packages/terminal/echo/Cargo.toml index 9c7d9162..8cb489f5 100644 --- a/kinode/packages/terminal/echo/Cargo.toml +++ b/kinode/packages/terminal/echo/Cargo.toml @@ -8,7 +8,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/hi/Cargo.toml b/kinode/packages/terminal/hi/Cargo.toml index f02f3bbc..d0350a48 100644 --- a/kinode/packages/terminal/hi/Cargo.toml +++ b/kinode/packages/terminal/hi/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" simulation-mode = [] [dependencies] -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/m/Cargo.toml b/kinode/packages/terminal/m/Cargo.toml index 69858ea8..3f7e5197 100644 --- a/kinode/packages/terminal/m/Cargo.toml +++ b/kinode/packages/terminal/m/Cargo.toml @@ -9,7 +9,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" clap = "4.4.18" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } regex = "1.10.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/kinode/packages/terminal/metadata.json b/kinode/packages/terminal/metadata.json index 20fd8012..fe8b16a9 100644 --- a/kinode/packages/terminal/metadata.json +++ b/kinode/packages/terminal/metadata.json @@ -4,11 +4,11 @@ "image": "", "properties": { "package_name": "terminal", - "current_version": "0.1.0", + "current_version": "0.1.1", "publisher": "sys", "mirrors": [], "code_hashes": { - "0.1.0": "" + "0.1.1": "" } }, "external_url": "https://kinode.org", diff --git a/kinode/packages/terminal/namehash_to_name/Cargo.toml b/kinode/packages/terminal/namehash_to_name/Cargo.toml index 18c11100..275f19b8 100644 --- a/kinode/packages/terminal/namehash_to_name/Cargo.toml +++ b/kinode/packages/terminal/namehash_to_name/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" simulation-mode = [] [dependencies] -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rmp-serde = "1.1.2" serde = { version = "1.0", features = ["derive"] } wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/net_diagnostics/Cargo.toml b/kinode/packages/terminal/net_diagnostics/Cargo.toml index 89df80e1..1940413c 100644 --- a/kinode/packages/terminal/net_diagnostics/Cargo.toml +++ b/kinode/packages/terminal/net_diagnostics/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" simulation-mode = [] [dependencies] -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rmp-serde = "1.1.2" serde = { version = "1.0", features = ["derive"] } wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/peer/Cargo.toml b/kinode/packages/terminal/peer/Cargo.toml index 790385d6..e69e94d8 100644 --- a/kinode/packages/terminal/peer/Cargo.toml +++ b/kinode/packages/terminal/peer/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" simulation-mode = [] [dependencies] -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rmp-serde = "1.1.2" serde = { version = "1.0", features = ["derive"] } wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/peers/Cargo.toml b/kinode/packages/terminal/peers/Cargo.toml index 6d5ba208..1273755e 100644 --- a/kinode/packages/terminal/peers/Cargo.toml +++ b/kinode/packages/terminal/peers/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" simulation-mode = [] [dependencies] -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rmp-serde = "1.1.2" serde = { version = "1.0", features = ["derive"] } wit-bindgen = "0.24.0" diff --git a/kinode/packages/terminal/terminal/Cargo.toml b/kinode/packages/terminal/terminal/Cargo.toml index acdc452b..d9c36cab 100644 --- a/kinode/packages/terminal/terminal/Cargo.toml +++ b/kinode/packages/terminal/terminal/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terminal" -version = "0.1.0" +version = "0.1.1" edition = "2021" [features] @@ -9,7 +9,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } rand = "0.8" regex = "1.10.3" serde = { version = "1.0", features = ["derive"] } diff --git a/kinode/packages/terminal/top/Cargo.toml b/kinode/packages/terminal/top/Cargo.toml index 9ab2f690..69f6d36b 100644 --- a/kinode/packages/terminal/top/Cargo.toml +++ b/kinode/packages/terminal/top/Cargo.toml @@ -8,7 +8,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = "0.24.0" diff --git a/kinode/packages/tester/metadata.json b/kinode/packages/tester/metadata.json index 9bc832b3..3dd05325 100644 --- a/kinode/packages/tester/metadata.json +++ b/kinode/packages/tester/metadata.json @@ -4,11 +4,11 @@ "image": "", "properties": { "package_name": "tester", - "current_version": "0.1.0", + "current_version": "0.1.1", "publisher": "sys", "mirrors": [], "code_hashes": { - "0.1.0": "" + "0.1.1": "" } }, "external_url": "https://kinode.org", diff --git a/kinode/packages/tester/test_runner/Cargo.toml b/kinode/packages/tester/test_runner/Cargo.toml index 583181f6..c0752883 100644 --- a/kinode/packages/tester/test_runner/Cargo.toml +++ b/kinode/packages/tester/test_runner/Cargo.toml @@ -9,7 +9,7 @@ simulation-mode = [] [dependencies] anyhow = "1.0" bincode = "1.3.3" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" diff --git a/kinode/packages/tester/tester/Cargo.toml b/kinode/packages/tester/tester/Cargo.toml index 80cb37b9..65e17c48 100644 --- a/kinode/packages/tester/tester/Cargo.toml +++ b/kinode/packages/tester/tester/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tester" -version = "0.1.0" +version = "0.1.1" edition = "2021" [features] @@ -10,7 +10,7 @@ simulation-mode = [] anyhow = "1.0" bincode = "1.3.3" indexmap = "2.1" -kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.1" } +kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.7.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" diff --git a/kinode/src/eth/default_providers_mainnet.json b/kinode/src/eth/default_providers_mainnet.json index 736e8ce5..2473518c 100644 --- a/kinode/src/eth/default_providers_mainnet.json +++ b/kinode/src/eth/default_providers_mainnet.json @@ -1,11 +1,4 @@ [ - { - "chain_id": 1, - "trusted": false, - "provider": { - "RpcUrl": "wss://ethereum.publicnode.com" - } - }, { "chain_id": 31337, "trusted": true, @@ -13,6 +6,13 @@ "RpcUrl": "wss://localhost:8545" } }, + { + "chain_id": 1, + "trusted": false, + "provider": { + "RpcUrl": "wss://ethereum.publicnode.com" + } + }, { "chain_id": 10, "trusted": false, @@ -21,18 +21,18 @@ } }, { - "chain_id": 10, + "chain_id": 1, "trusted": false, "provider": { "Node": { "use_as_provider": true, "kns_update": { - "name": "default-router-1.os", + "name": "providerfren.os", "owner": "", - "node": "0xb35eb347deb896bc3fb6132a07fca1601f83462385ed11e835c24c33ba4ef73d", - "public_key": "0xe1f7a266eafe46c79494d4dcce4222d81e5767511b295f1ed26c37221aecb80b", + "node": "", + "public_key": "", "ip": "147.135.114.167", - "port": 9000, + "port": 9999, "routers": [] } } @@ -45,30 +45,12 @@ "Node": { "use_as_provider": true, "kns_update": { - "name": "default-router-2.os", + "name": "providerfren.os", "owner": "", - "node": "0xd827ae579fafa604af79fbed977e8abe048497f10885c6473dfd343a3b7b4458", - "public_key": "0xcc2752e30ba865ab6baa1b819b0291b71f1136245234274b274df5950c3abcc4", + "node": "", + "public_key": "", "ip": "147.135.114.167", - "port": 9001, - "routers": [] - } - } - } - }, - { - "chain_id": 10, - "trusted": false, - "provider": { - "Node": { - "use_as_provider": true, - "kns_update": { - "name": "default-router-3.os", - "owner": "", - "node": "0x96e36331c8f0882f2c0c46c13b15d812def04fe8606d503bc0e2be39db26486a", - "public_key": "0xe992841b17212206a3929b4cc065ad2854875d48fc7177e260005b9eb8d4f123", - "ip": "147.135.114.167", - "port": 9005, + "port": 9999, "routers": [] } } @@ -81,48 +63,12 @@ "Node": { "use_as_provider": true, "kns_update": { - "name": "default-router-3.os", + "name": "providerfren.os", "owner": "", - "node": "0x96e36331c8f0882f2c0c46c13b15d812def04fe8606d503bc0e2be39db26486a", - "public_key": "0xe992841b17212206a3929b4cc065ad2854875d48fc7177e260005b9eb8d4f123", + "node": "", + "public_key": "", "ip": "147.135.114.167", - "port": 9005, - "routers": [] - } - } - } - }, - { - "chain_id": 11155111, - "trusted": false, - "provider": { - "Node": { - "use_as_provider": true, - "kns_update": { - "name": "default-router-2.os", - "owner": "", - "node": "0xd827ae579fafa604af79fbed977e8abe048497f10885c6473dfd343a3b7b4458", - "public_key": "0xcc2752e30ba865ab6baa1b819b0291b71f1136245234274b274df5950c3abcc4", - "ip": "147.135.114.167", - "port": 9001, - "routers": [] - } - } - } - }, - { - "chain_id": 11155111, - "trusted": false, - "provider": { - "Node": { - "use_as_provider": true, - "kns_update": { - "name": "default-router-1.os", - "owner": "", - "node": "0xb35eb347deb896bc3fb6132a07fca1601f83462385ed11e835c24c33ba4ef73d", - "public_key": "0xe1f7a266eafe46c79494d4dcce4222d81e5767511b295f1ed26c37221aecb80b", - "ip": "147.135.114.167", - "port": 9000, + "port": 9999, "routers": [] } } diff --git a/kinode/src/eth/mod.rs b/kinode/src/eth/mod.rs index fedfadb5..fd16b610 100644 --- a/kinode/src/eth/mod.rs +++ b/kinode/src/eth/mod.rs @@ -177,11 +177,6 @@ pub async fn provider( allow: HashSet::new(), deny: HashSet::new(), }; - let _ = tokio::fs::write( - format!("{}/.eth_access_settings", home_directory_path), - serde_json::to_string(&access_settings).unwrap(), - ) - .await; access_settings } }; @@ -556,10 +551,13 @@ async fn fulfill_request( let Some(mut aps) = providers.get_mut(&chain_id) else { return EthResponse::Err(EthError::NoRpcForChain); }; + // first, try any url providers we have for this chain, // then if we have none or they all fail, go to node provider. // finally, if no provider works, return an error. - for url_provider in &mut aps.urls { + + // bump the successful provider to the front of the list for future requests + for (index, url_provider) in aps.urls.iter_mut().enumerate() { let pubsub = match &url_provider.pubsub { Some(pubsub) => pubsub, None => { @@ -571,16 +569,34 @@ async fn fulfill_request( .await; url_provider.pubsub.as_ref().unwrap() } else { + verbose_print( + print_tx, + &format!("eth: could not activate url provider {}", url_provider.url), + ) + .await; continue; } } }; - let Ok(value) = pubsub.inner().prepare(method, params.clone()).await else { - // this provider failed and needs to be reset - url_provider.pubsub = None; - continue; - }; - return EthResponse::Response { value }; + match pubsub.inner().prepare(method, params.clone()).await { + Ok(value) => { + let successful_provider = aps.urls.remove(index); + aps.urls.insert(0, successful_provider); + return EthResponse::Response { value }; + } + Err(rpc_error) => { + verbose_print( + print_tx, + &format!( + "eth: got error from url provider {}: {}", + url_provider.url, rpc_error + ), + ) + .await; + // this provider failed and needs to be reset + url_provider.pubsub = None; + } + } } for node_provider in &mut aps.nodes { let response = forward_to_node_provider( diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 032d58e3..b294ef8f 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "lib" authors = ["KinodeDAO"] -version = "0.7.0" +version = "0.7.1" edition = "2021" description = "A general-purpose sovereign cloud computing platform" homepage = "https://kinode.org" From d1184b5bf8de5f3e70888fb4d1561d5e5127bd98 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 24 Apr 2024 20:51:10 +0900 Subject: [PATCH 3/7] add providerfren pubkey --- kinode/src/eth/default_providers_mainnet.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kinode/src/eth/default_providers_mainnet.json b/kinode/src/eth/default_providers_mainnet.json index 2473518c..9f8c00bf 100644 --- a/kinode/src/eth/default_providers_mainnet.json +++ b/kinode/src/eth/default_providers_mainnet.json @@ -30,7 +30,7 @@ "name": "providerfren.os", "owner": "", "node": "", - "public_key": "", + "public_key": "0x54f5a8a4c625d5925e63ed3f0203b63e007e3f822d7858bd98b1fd9704c99451", "ip": "147.135.114.167", "port": 9999, "routers": [] @@ -48,7 +48,7 @@ "name": "providerfren.os", "owner": "", "node": "", - "public_key": "", + "public_key": "0x54f5a8a4c625d5925e63ed3f0203b63e007e3f822d7858bd98b1fd9704c99451", "ip": "147.135.114.167", "port": 9999, "routers": [] @@ -66,7 +66,7 @@ "name": "providerfren.os", "owner": "", "node": "", - "public_key": "", + "public_key": "0x54f5a8a4c625d5925e63ed3f0203b63e007e3f822d7858bd98b1fd9704c99451", "ip": "147.135.114.167", "port": 9999, "routers": [] From d15ffa4a520c684244c4f7ef2ca7c2d80d2dcd44 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 24 Apr 2024 21:53:34 +0900 Subject: [PATCH 4/7] terminal: move script-spawn debug to verbosity 3 --- kinode/packages/terminal/terminal/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kinode/packages/terminal/terminal/src/lib.rs b/kinode/packages/terminal/terminal/src/lib.rs index 612b6d47..c793f749 100644 --- a/kinode/packages/terminal/terminal/src/lib.rs +++ b/kinode/packages/terminal/terminal/src/lib.rs @@ -295,7 +295,7 @@ fn handle_run(our: &Address, process: &ProcessId, args: String) -> anyhow::Resul } } print_to_terminal( - 2, + 3, &format!( "{}: Process {{\n wasm_bytes_handle: {},\n wit_version: {},\n on_exit: {:?},\n public: {}\n capabilities: {}\n}}", parsed_new_process_id.clone(), From 35e1692de7d9c0badd9b438cb910ec07252a4003 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 24 Apr 2024 23:43:47 +0900 Subject: [PATCH 5/7] fix: refactor eth provider subs --- kinode/src/eth/mod.rs | 30 +++++------- kinode/src/eth/subscription.rs | 83 +++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 44 deletions(-) diff --git a/kinode/src/eth/mod.rs b/kinode/src/eth/mod.rs index fd16b610..8a1046c9 100644 --- a/kinode/src/eth/mod.rs +++ b/kinode/src/eth/mod.rs @@ -456,19 +456,15 @@ async fn handle_eth_action( // before returning an error. match eth_action { EthAction::SubscribeLogs { sub_id, .. } => { - tokio::spawn(subscription::create_new_subscription( - state.our.to_string(), + subscription::create_new_subscription( + state, km.id, km.source.clone(), km.rsvp, - state.send_to_loop.clone(), sub_id, eth_action, - state.providers.clone(), - state.active_subscriptions.clone(), - state.response_channels.clone(), - state.print_tx.clone(), - )); + ) + .await; } EthAction::UnsubscribeLogs(sub_id) => { let mut sub_map = state @@ -553,7 +549,7 @@ async fn fulfill_request( }; // first, try any url providers we have for this chain, - // then if we have none or they all fail, go to node provider. + // then if we have none or they all fail, go to node providers. // finally, if no provider works, return an error. // bump the successful provider to the front of the list for future requests @@ -652,15 +648,13 @@ async fn forward_to_node_provider( else { return EthResponse::Err(EthError::RpcTimeout); }; - let Message::Response((resp, _context)) = response_km.message else { - // if we hit this, they spoofed a request with same id, ignore and possibly punish - return EthResponse::Err(EthError::RpcMalformedResponse); - }; - let Ok(eth_response) = serde_json::from_slice::(&resp.body) else { - // if we hit this, they sent a malformed response, ignore and possibly punish - return EthResponse::Err(EthError::RpcMalformedResponse); - }; - eth_response + if let Message::Response((resp, _context)) = response_km.message { + if let Ok(eth_response) = serde_json::from_slice::(&resp.body) { + return eth_response; + } + } + // if we hit this, they sent a malformed response, ignore and possibly punish + EthResponse::Err(EthError::RpcMalformedResponse) } async fn handle_eth_config_action( diff --git a/kinode/src/eth/subscription.rs b/kinode/src/eth/subscription.rs index 234d4094..3aa2667e 100644 --- a/kinode/src/eth/subscription.rs +++ b/kinode/src/eth/subscription.rs @@ -4,50 +4,49 @@ use alloy_rpc_types::pubsub::SubscriptionResult; /// cleans itself up when the subscription is closed or fails. pub async fn create_new_subscription( - our: String, + state: &ModuleState, km_id: u64, target: Address, rsvp: Option
, - send_to_loop: MessageSender, sub_id: u64, eth_action: EthAction, - providers: Providers, - active_subscriptions: ActiveSubscriptions, - response_channels: ResponseChannels, - print_tx: PrintSender, ) { - verbose_print(&print_tx, "eth: creating new subscription").await; + verbose_print(&state.print_tx, "eth: creating new subscription").await; match build_subscription( - &our, + &state.our, km_id, &target, - &send_to_loop, + &state.send_to_loop, ð_action, - &providers, - &response_channels, - &print_tx, + &state.providers, + &state.response_channels, + &state.print_tx, ) .await { Ok(maybe_raw_sub) => { // send a response to the target that the subscription was successful kernel_message( - &our, + &state.our, km_id, target.clone(), rsvp.clone(), false, None, EthResponse::Ok, - &send_to_loop, + &state.send_to_loop, ) .await; - let mut subs = active_subscriptions + let mut subs = state + .active_subscriptions .entry(target.clone()) .or_insert(HashMap::new()); - let active_subscriptions = active_subscriptions.clone(); + let active_subscriptions = state.active_subscriptions.clone(); match maybe_raw_sub { Ok(rx) => { + let our = state.our.clone(); + let send_to_loop = state.send_to_loop.clone(); + let print_tx = state.print_tx.clone(); subs.insert( sub_id, // this is a local sub, as in, we connect to the rpc endpoint @@ -92,7 +91,13 @@ pub async fn create_new_subscription( let keepalive_km_id = rand::random(); let (keepalive_err_sender, keepalive_err_receiver) = tokio::sync::mpsc::channel(1); - response_channels.insert(keepalive_km_id, keepalive_err_sender); + state + .response_channels + .insert(keepalive_km_id, keepalive_err_sender); + let our = state.our.clone(); + let send_to_loop = state.send_to_loop.clone(); + let print_tx = state.print_tx.clone(); + let response_channels = state.response_channels.clone(); subs.insert( remote_sub_id, ActiveSub::Remote { @@ -140,7 +145,7 @@ pub async fn create_new_subscription( } } Err(e) => { - error_message(&our, km_id, target.clone(), e, &send_to_loop).await; + error_message(&state.our, km_id, target.clone(), e, &state.send_to_loop).await; } } } @@ -171,32 +176,58 @@ async fn build_subscription( // first, try any url providers we have for this chain, // then if we have none or they all fail, go to node providers. // finally, if no provider works, return an error. - for url_provider in &mut aps.urls { + + // bump the successful provider to the front of the list for future requests + for (index, url_provider) in aps.urls.iter_mut().enumerate() { let pubsub = match &url_provider.pubsub { Some(pubsub) => pubsub, None => { if let Ok(()) = activate_url_provider(url_provider).await { - verbose_print(print_tx, "eth: activated a url provider").await; + verbose_print( + print_tx, + &format!("eth: activated url provider {}", url_provider.url), + ) + .await; url_provider.pubsub.as_ref().unwrap() } else { + verbose_print( + print_tx, + &format!("eth: could not activate url provider {}", url_provider.url), + ) + .await; continue; } } }; let kind = serde_json::to_value(&kind).unwrap(); let params = serde_json::to_value(¶ms).unwrap(); - if let Ok(id) = pubsub + match pubsub .inner() .prepare("eth_subscribe", [kind, params]) .await { - let rx = pubsub.inner().get_raw_subscription(id).await; - return Ok(Ok(rx)); + Ok(id) => { + let rx = pubsub.inner().get_raw_subscription(id).await; + let successful_provider = aps.urls.remove(index); + aps.urls.insert(0, successful_provider); + return Ok(Ok(rx)); + } + Err(rpc_error) => { + verbose_print( + print_tx, + &format!( + "eth: got error from url provider {}: {}", + url_provider.url, rpc_error + ), + ) + .await; + // this provider failed and needs to be reset + url_provider.pubsub = None; + } } - // this provider failed and needs to be reset - url_provider.pubsub = None; } - // now we need a response channel + // now we need a response channel which will be open for the duration + // of the subscription let (sender, mut response_receiver) = tokio::sync::mpsc::channel(1); response_channels.insert(km_id, sender); // we need to create our own unique sub id because in the remote provider node, From d3a36b378ef2decf22e1268c01d54da8b6c5f281 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Thu, 25 Apr 2024 00:27:14 +0900 Subject: [PATCH 6/7] print nits --- kinode/packages/kns_indexer/kns_indexer/src/lib.rs | 7 ++++++- kinode/src/eth/subscription.rs | 1 - kinode/src/http/server.rs | 10 ++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs index 5e90a163..33faa818 100644 --- a/kinode/packages/kns_indexer/kns_indexer/src/lib.rs +++ b/kinode/packages/kns_indexer/kns_indexer/src/lib.rs @@ -301,7 +301,12 @@ fn handle_eth_message( match eth_result { Ok(eth::EthSub { result, .. }) => { if let eth::SubscriptionResult::Log(log) = result { - handle_log(our, state, &log)?; + match handle_log(our, state, &log) { + Ok(_) => {} + Err(e) => { + println!("log-handling error! {e:?}"); + } + } } } Err(_e) => { diff --git a/kinode/src/eth/subscription.rs b/kinode/src/eth/subscription.rs index 3aa2667e..ddbf5fea 100644 --- a/kinode/src/eth/subscription.rs +++ b/kinode/src/eth/subscription.rs @@ -11,7 +11,6 @@ pub async fn create_new_subscription( sub_id: u64, eth_action: EthAction, ) { - verbose_print(&state.print_tx, "eth: creating new subscription").await; match build_subscription( &state.our, km_id, diff --git a/kinode/src/http/server.rs b/kinode/src/http/server.rs index a9774f0d..b7dbb435 100644 --- a/kinode/src/http/server.rs +++ b/kinode/src/http/server.rs @@ -1144,8 +1144,14 @@ async fn handle_app_message( .send(Printout { verbosity: 2, content: format!( - "binding path {path} for {}, authenticated={authenticated}, local={local_only}, cached={cache}", - km.source.process + "http: binding {path}, {}, {}, {}", + if authenticated { + "authenticated" + } else { + "unauthenticated" + }, + if local_only { "local only" } else { "open" }, + if cache { "cached" } else { "dynamic" }, ), }) .await; From cfedc1910292ec97c65aff8f885c03aa91a9d1ca Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Thu, 25 Apr 2024 02:42:11 +0900 Subject: [PATCH 7/7] fix: more sub refactor --- kinode/src/eth/mod.rs | 11 +- kinode/src/eth/subscription.rs | 249 ++++++++++++++++++--------------- 2 files changed, 147 insertions(+), 113 deletions(-) diff --git a/kinode/src/eth/mod.rs b/kinode/src/eth/mod.rs index 8a1046c9..c1fb20d1 100644 --- a/kinode/src/eth/mod.rs +++ b/kinode/src/eth/mod.rs @@ -46,6 +46,7 @@ struct UrlProvider { #[derive(Debug)] struct NodeProvider { + /// NOT CURRENTLY USED pub trusted: bool, /// semi-temporary flag to mark if this provider is currently usable /// future updates will make this more dynamic @@ -365,7 +366,7 @@ async fn handle_message( // so they can stop sending us updates verbose_print( &state.print_tx, - "eth: got eth_sub_result but no matching sub found", + "eth: got eth_sub_result but no matching sub found, unsubscribing", ) .await; kernel_message( @@ -595,6 +596,14 @@ async fn fulfill_request( } } for node_provider in &mut aps.nodes { + verbose_print( + print_tx, + &format!( + "eth: attempting to fulfill via {}", + node_provider.kns_update.name + ), + ) + .await; let response = forward_to_node_provider( our, km_id, diff --git a/kinode/src/eth/subscription.rs b/kinode/src/eth/subscription.rs index ddbf5fea..79b92d79 100644 --- a/kinode/src/eth/subscription.rs +++ b/kinode/src/eth/subscription.rs @@ -11,120 +11,75 @@ pub async fn create_new_subscription( sub_id: u64, eth_action: EthAction, ) { - match build_subscription( - &state.our, - km_id, - &target, - &state.send_to_loop, - ð_action, - &state.providers, - &state.response_channels, - &state.print_tx, - ) - .await - { - Ok(maybe_raw_sub) => { - // send a response to the target that the subscription was successful - kernel_message( - &state.our, + let our = state.our.clone(); + let send_to_loop = state.send_to_loop.clone(); + let active_subscriptions = state.active_subscriptions.clone(); + let providers = state.providers.clone(); + let response_channels = state.response_channels.clone(); + let print_tx = state.print_tx.clone(); + tokio::spawn(async move { + match tokio::time::timeout( + std::time::Duration::from_secs(30), + build_subscription( + &our, km_id, - target.clone(), - rsvp.clone(), - false, - None, - EthResponse::Ok, - &state.send_to_loop, - ) - .await; - let mut subs = state - .active_subscriptions - .entry(target.clone()) - .or_insert(HashMap::new()); - let active_subscriptions = state.active_subscriptions.clone(); - match maybe_raw_sub { - Ok(rx) => { - let our = state.our.clone(); - let send_to_loop = state.send_to_loop.clone(); - let print_tx = state.print_tx.clone(); - subs.insert( - sub_id, - // this is a local sub, as in, we connect to the rpc endpoint - ActiveSub::Local(tokio::spawn(async move { - // await the subscription error and kill it if so - if let Err(e) = maintain_local_subscription( - &our, - sub_id, - rx, - &target, - &rsvp, - &send_to_loop, - ) - .await - { - verbose_print( - &print_tx, - "eth: closed local subscription due to error", - ) - .await; - kernel_message( + &target, + &send_to_loop, + ð_action, + &providers, + &response_channels, + &print_tx, + ), + ) + .await + { + Ok(Ok(maybe_raw_sub)) => { + // send a response to the target that the subscription was successful + kernel_message( + &our, + km_id, + target.clone(), + rsvp.clone(), + false, + None, + EthResponse::Ok, + &send_to_loop, + ) + .await; + let mut subs = active_subscriptions + .entry(target.clone()) + .or_insert(HashMap::new()); + let active_subscriptions = active_subscriptions.clone(); + match maybe_raw_sub { + Ok(rx) => { + let our = our.clone(); + let send_to_loop = send_to_loop.clone(); + let print_tx = print_tx.clone(); + subs.insert( + sub_id, + // this is a local sub, as in, we connect to the rpc endpoint + ActiveSub::Local(tokio::spawn(async move { + // await the subscription error and kill it if so + if let Err(e) = maintain_local_subscription( &our, - rand::random(), - target.clone(), - rsvp, - true, - None, - EthSubResult::Err(e), - &send_to_loop, - ) - .await; - active_subscriptions.entry(target).and_modify(|sub_map| { - sub_map.remove(&km_id); - }); - } - })), - ); - } - Err((provider_node, remote_sub_id)) => { - // this is a remote sub, given by a relay node - let (sender, rx) = tokio::sync::mpsc::channel(10); - let keepalive_km_id = rand::random(); - let (keepalive_err_sender, keepalive_err_receiver) = - tokio::sync::mpsc::channel(1); - state - .response_channels - .insert(keepalive_km_id, keepalive_err_sender); - let our = state.our.clone(); - let send_to_loop = state.send_to_loop.clone(); - let print_tx = state.print_tx.clone(); - let response_channels = state.response_channels.clone(); - subs.insert( - remote_sub_id, - ActiveSub::Remote { - provider_node: provider_node.clone(), - handle: tokio::spawn(async move { - if let Err(e) = maintain_remote_subscription( - &our, - &provider_node, - remote_sub_id, sub_id, - keepalive_km_id, rx, - keepalive_err_receiver, &target, + &rsvp, &send_to_loop, ) .await { verbose_print( &print_tx, - "eth: closed subscription with provider node due to error", + "eth: closed local subscription due to error", ) .await; kernel_message( &our, rand::random(), target.clone(), - None, + rsvp, true, None, EthSubResult::Err(e), @@ -132,21 +87,84 @@ pub async fn create_new_subscription( ) .await; active_subscriptions.entry(target).and_modify(|sub_map| { - sub_map.remove(&sub_id); + sub_map.remove(&km_id); }); - response_channels.remove(&keepalive_km_id); } - }), - sender, - }, - ); + })), + ); + } + Err((provider_node, remote_sub_id)) => { + // this is a remote sub, given by a relay node + let (sender, rx) = tokio::sync::mpsc::channel(10); + let keepalive_km_id = rand::random(); + let (keepalive_err_sender, keepalive_err_receiver) = + tokio::sync::mpsc::channel(1); + response_channels.insert(keepalive_km_id, keepalive_err_sender); + let our = our.clone(); + let send_to_loop = send_to_loop.clone(); + let print_tx = print_tx.clone(); + let response_channels = response_channels.clone(); + subs.insert( + remote_sub_id, + ActiveSub::Remote { + provider_node: provider_node.clone(), + handle: tokio::spawn(async move { + if let Err(e) = maintain_remote_subscription( + &our, + &provider_node, + remote_sub_id, + sub_id, + keepalive_km_id, + rx, + keepalive_err_receiver, + &target, + &send_to_loop, + ) + .await + { + verbose_print( + &print_tx, + "eth: closed subscription with provider node due to error", + ) + .await; + kernel_message( + &our, + rand::random(), + target.clone(), + None, + true, + None, + EthSubResult::Err(e), + &send_to_loop, + ) + .await; + active_subscriptions.entry(target).and_modify(|sub_map| { + sub_map.remove(&sub_id); + }); + response_channels.remove(&keepalive_km_id); + } + }), + sender, + }, + ); + } } } + Ok(Err(e)) => { + error_message(&our, km_id, target.clone(), e, &send_to_loop).await; + } + Err(_) => { + error_message( + &our, + km_id, + target.clone(), + EthError::RpcTimeout, + &send_to_loop, + ) + .await; + } } - Err(e) => { - error_message(&state.our, km_id, target.clone(), e, &state.send_to_loop).await; - } - } + }); } /// terrible abuse of result in return type, yes, sorry @@ -183,14 +201,14 @@ async fn build_subscription( None => { if let Ok(()) = activate_url_provider(url_provider).await { verbose_print( - print_tx, + &print_tx, &format!("eth: activated url provider {}", url_provider.url), ) .await; url_provider.pubsub.as_ref().unwrap() } else { verbose_print( - print_tx, + &print_tx, &format!("eth: could not activate url provider {}", url_provider.url), ) .await; @@ -213,7 +231,7 @@ async fn build_subscription( } Err(rpc_error) => { verbose_print( - print_tx, + &print_tx, &format!( "eth: got error from url provider {}: {}", url_provider.url, rpc_error @@ -225,14 +243,21 @@ async fn build_subscription( } } } - // now we need a response channel which will be open for the duration - // of the subscription + let (sender, mut response_receiver) = tokio::sync::mpsc::channel(1); response_channels.insert(km_id, sender); // we need to create our own unique sub id because in the remote provider node, // all subs will be identified under our process address. let remote_sub_id = rand::random(); for node_provider in &mut aps.nodes { + verbose_print( + &print_tx, + &format!( + "eth: attempting to fulfill via {}", + node_provider.kns_update.name + ), + ) + .await; match forward_to_node_provider( &our, km_id,