From b79c9535df3d7735daa611b59868198cba394c87 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 8 May 2024 12:59:05 -0600 Subject: [PATCH] app store fixes --- Cargo.lock | 38 ++++++++++++++++++- .../packages/app_store/app_store/src/lib.rs | 21 ++++++++-- .../packages/app_store/app_store/src/types.rs | 11 +++--- kinode/src/eth/default_providers_mainnet.json | 14 ------- kinode/src/eth/mod.rs | 5 ++- 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b31ee96..030e1b98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3084,7 +3084,7 @@ dependencies = [ "hmac", "http 1.1.0", "jwt", - "kit", + "kit 0.3.1 (git+https://github.com/kinode-dao/kit?rev=25b474a)", "lazy_static", "lib", "log", @@ -3215,6 +3215,40 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "kit" +version = "0.3.1" +source = "git+https://github.com/kinode-dao/kit?rev=25b474a#25b474abec180f6ae63b3f2c13f459a180b5be73" +dependencies = [ + "anyhow", + "base64 0.21.7", + "clap", + "color-eyre", + "dirs 5.0.1", + "fs-err", + "futures-util", + "git2", + "hex", + "kinode_process_lib 0.6.0", + "nix", + "regex", + "reqwest 0.11.27", + "rmp-serde", + "semver 1.0.22", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-tungstenite 0.20.1", + "toml", + "tracing", + "tracing-appender", + "tracing-error", + "tracing-subscriber", + "walkdir", + "zip 0.6.6", +] + [[package]] name = "kit" version = "0.3.1" @@ -3289,7 +3323,7 @@ version = "0.7.2" dependencies = [ "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)", "anyhow", - "kit", + "kit 0.3.1 (git+https://github.com/kinode-dao/kit?rev=659f59e)", "lazy_static", "rand 0.8.5", "reqwest 0.12.4", diff --git a/kinode/packages/app_store/app_store/src/lib.rs b/kinode/packages/app_store/app_store/src/lib.rs index a8b71908..717c7332 100644 --- a/kinode/packages/app_store/app_store/src/lib.rs +++ b/kinode/packages/app_store/app_store/src/lib.rs @@ -218,9 +218,20 @@ fn init(our: Address) { .send() .unwrap(); - // load in our saved state or initalize a new one if none exists - let mut state = get_typed_state(|bytes| Ok(bincode::deserialize(bytes)?)) - .unwrap_or(State::new(CONTRACT_ADDRESS.to_string()).unwrap()); + let mut state: State = match get_typed_state(|bytes| Ok(bincode::deserialize::(bytes)?)) + { + Some(state) => { + println!("loaded saved state"); + state + } + _ => { + println!("failed to load state, initializing"); + State::new(CONTRACT_ADDRESS.to_string()).unwrap() + } + }; + // // load in our saved state or initalize a new one if none exists + // let mut state = get_typed_state(|bytes| Ok(bincode::deserialize(bytes)?)) + // .unwrap_or(State::new(CONTRACT_ADDRESS.to_string()).unwrap()); if state.contract_address != CONTRACT_ADDRESS { println!("warning: contract address mismatch--overwriting saved state"); @@ -532,12 +543,14 @@ pub fn rebuild_index( .from_block(state.last_saved_block - 1) .events(EVENTS); + subscribe_to_logs(ð_provider, filter.clone()); + for log in fetch_logs(ð_provider, &filter) { if let Err(e) = state.ingest_listings_contract_event(our, log) { println!("error ingesting log: {e:?}"); }; } - subscribe_to_logs(ð_provider, filter); + LocalResponse::RebuiltIndex } diff --git a/kinode/packages/app_store/app_store/src/types.rs b/kinode/packages/app_store/app_store/src/types.rs index 5f561779..21d1bb7c 100644 --- a/kinode/packages/app_store/app_store/src/types.rs +++ b/kinode/packages/app_store/app_store/src/types.rs @@ -73,6 +73,9 @@ pub struct PackageState { pub installed: bool, pub verified: bool, pub caps_approved: bool, + /// the hash of the manifest file, which is used to determine whether package + /// capabilities have changed. if they have changed, auto-install must fail + /// and the user must approve the new capabilities. pub manifest_hash: Option, /// are we serving this package to others? pub mirroring: bool, @@ -360,7 +363,7 @@ impl State { Ok(()) } - /// only saves state if last_saved_block is more than 1000 blocks behind + /// saves state pub fn ingest_listings_contract_event( &mut self, our: &Address, @@ -518,10 +521,8 @@ impl State { } _ => {} } - if block_number > self.last_saved_block + 1000 { - self.last_saved_block = block_number; - crate::set_state(&bincode::serialize(self)?); - } + self.last_saved_block = block_number; + crate::set_state(&bincode::serialize(self)?); Ok(()) } } diff --git a/kinode/src/eth/default_providers_mainnet.json b/kinode/src/eth/default_providers_mainnet.json index 9eeae49e..dc964f61 100644 --- a/kinode/src/eth/default_providers_mainnet.json +++ b/kinode/src/eth/default_providers_mainnet.json @@ -1,18 +1,4 @@ [ - { - "chain_id": 1, - "trusted": false, - "provider": { - "RpcUrl": "wss://ethereum.publicnode.com" - } - }, - { - "chain_id": 10, - "trusted": false, - "provider": { - "RpcUrl": "wss://optimism-rpc.publicnode.com" - } - }, { "chain_id": 1, "trusted": false, diff --git a/kinode/src/eth/mod.rs b/kinode/src/eth/mod.rs index 73db0c47..7925388e 100644 --- a/kinode/src/eth/mod.rs +++ b/kinode/src/eth/mod.rs @@ -391,7 +391,10 @@ async fn handle_message( } verbose_print( &state.print_tx, - "eth: got sub_keepalive but no matching sub found", + &format!( + "eth: got sub_keepalive from {} but no matching sub found", + km.source + ), ) .await; // send a response with an EthSubError