Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions kinode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ path = "src/main.rs"

[build-dependencies]
anyhow = "1.0.71"
kit = { git = "https://github.com/kinode-dao/kit", tag = "v0.6.2" }
rayon = "1.8.1"
kit = { git = "https://github.com/kinode-dao/kit", rev = "4a8999f" }
tokio = "1.28"
walkdir = "2.4"
zip = "0.6"
Expand Down
70 changes: 38 additions & 32 deletions kinode/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::{
collections::HashSet,
fs::{self, File},
Expand All @@ -16,38 +15,31 @@ fn get_features() -> String {
.to_lowercase()
.replace("_", "-");
features.push_str(&feature);
//println!("cargo:rustc-cfg=feature=\"{}\"", feature);
//println!("- {}", feature);
}
}
features
}

fn output_reruns(dir: &Path, rerun_files: &HashSet<String>) {
if rerun_files.contains(dir.to_str().unwrap()) {
// Output for all files in the directory if the directory itself is specified in rerun_files
if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.filter_map(|e| e.ok()) {
let path = entry.path();
println!("cargo:rerun-if-changed={}", path.display());
}
}
} else {
// Check files individually
if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.filter_map(|e| e.ok()) {
let path = entry.path();
if path.is_dir() {
// If the entry is a directory, recursively walk it
output_reruns(&path, rerun_files);
} else if let Some(filename) = path.file_name().and_then(|n| n.to_str()) {
// Check if the current file is in our list of interesting files
if rerun_files.contains(filename) {
// If so, print a `cargo:rerun-if-changed=PATH` line for it
println!("cargo:rerun-if-changed={}", path.display());
}
// Check files individually
if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.filter_map(|e| e.ok()) {
let path = entry.path();
if let Some(filename) = path.file_name().and_then(|n| n.to_str()) {
// Check if the current file is in our list of interesting files
if filename == "ui" {
continue;
}
if rerun_files.contains(filename) {
// If so, print a `cargo:rerun-if-changed=PATH` line for it
println!("cargo::rerun-if-changed={}", path.display());
continue;
}
}
if path.is_dir() {
// If the entry is a directory not in rerun_files, recursively walk it
output_reruns(&path, rerun_files);
}
}
}
}
Expand All @@ -59,13 +51,23 @@ fn build_and_zip_package(
) -> anyhow::Result<(String, String, Vec<u8>)> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
kit::build::execute(&entry_path, true, false, true, features, None, None, true)
.await
.map_err(|e| anyhow::anyhow!("{:?}", e))?;
kit::build::execute(
&entry_path,
true,
false,
true,
features,
None,
None,
None,
true,
)
.await
.map_err(|e| anyhow::anyhow!("{:?}", e))?;

let mut writer = Cursor::new(Vec::new());
let options = FileOptions::default()
.compression_method(zip::CompressionMethod::Stored)
.compression_method(zip::CompressionMethod::Deflated)
.unix_permissions(0o755);
{
let mut zip = zip::ZipWriter::new(&mut writer);
Expand Down Expand Up @@ -111,14 +113,14 @@ fn main() -> anyhow::Result<()> {
let rerun_files: HashSet<String> = HashSet::from([
"Cargo.lock".to_string(),
"Cargo.toml".to_string(),
"src/".to_string(),
"src".to_string(),
]);
output_reruns(&parent_dir, &rerun_files);

let features = get_features();

let results: Vec<anyhow::Result<(String, String, Vec<u8>)>> = entries
.par_iter()
.iter()
.filter_map(|entry_path| {
let parent_pkg_path = entry_path.join("pkg");
if !parent_pkg_path.exists() {
Expand Down Expand Up @@ -160,7 +162,11 @@ fn main() -> anyhow::Result<()> {
}

writeln!(bootstrapped_processes, "];")?;
let bootstrapped_processes_path = pwd.join("src/bootstrapped_processes.rs");
let target_dir = pwd.join("../target");
if !target_dir.exists() {
fs::create_dir_all(&target_dir)?;
}
let bootstrapped_processes_path = target_dir.join("bootstrapped_processes.rs");
fs::write(&bootstrapped_processes_path, bootstrapped_processes)?;

Ok(())
Expand Down
6 changes: 4 additions & 2 deletions kinode/packages/app_store/app_store/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ pub fn fetch_state(our: Address, provider: eth::Provider) -> State {
pub fn app_store_filter(state: &State) -> eth::Filter {
eth::Filter::new()
.address(eth::Address::from_str(&state.contract_address).unwrap())
.from_block(state.last_saved_block)
.events(EVENTS)
}

/// create a filter to fetch app store event logs from chain and subscribe to new events
pub fn fetch_and_subscribe_logs(state: &mut State) {
let filter = app_store_filter(state);
// get past logs, subscribe to new ones.
for log in fetch_logs(&state.provider, &filter) {
for log in fetch_logs(
&state.provider,
&filter.clone().from_block(state.last_saved_block),
) {
if let Err(e) = state.ingest_contract_event(log, false) {
println!("error ingesting log: {e:?}");
};
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/kino_updates/widget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ wit_bindgen::generate!({
world: "process-v0",
});

/// 20 minutes
const REFRESH_INTERVAL: u64 = 20 * 60 * 1000;
/// 2 hours
const REFRESH_INTERVAL: u64 = 120 * 60 * 1000;

#[derive(Serialize, Deserialize)]
struct KinodeBlogPost {
Expand Down
11 changes: 5 additions & 6 deletions kinode/packages/kns_indexer/kns_indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ sol! {
event RoutingUpdate(bytes32 indexed node, bytes32[] routers);
}

fn subscribe_to_logs(eth_provider: &eth::Provider, from_block: u64, filter: eth::Filter) {
fn subscribe_to_logs(eth_provider: &eth::Provider, filter: eth::Filter) {
loop {
match eth_provider.subscribe(1, filter.clone().from_block(from_block)) {
match eth_provider.subscribe(1, filter.clone()) {
Ok(()) => break,
Err(_) => {
println!("failed to subscribe to chain! trying again in 5s...");
Expand Down Expand Up @@ -126,7 +126,6 @@ fn init(our: Address) {
fn main(our: Address, mut state: State) -> anyhow::Result<()> {
let filter = eth::Filter::new()
.address(state.contract_address.parse::<eth::Address>().unwrap())
.from_block(state.block - 1)
.to_block(eth::BlockNumberOrTag::Latest)
.events(vec![
"NodeRegistered(bytes32,bytes)",
Expand All @@ -147,11 +146,11 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
state.chain_id
);

subscribe_to_logs(&eth_provider, state.block - 1, filter.clone());
subscribe_to_logs(&eth_provider, filter.clone());

// if block in state is < current_block, get logs from that part.
loop {
match eth_provider.get_logs(&filter) {
match eth_provider.get_logs(&filter.clone().from_block(state.block - 1)) {
Ok(logs) => {
for log in logs {
match handle_log(&our, &mut state, &log) {
Expand Down Expand Up @@ -277,7 +276,7 @@ fn handle_eth_message(
}
Err(_e) => {
println!("got eth subscription error");
subscribe_to_logs(&eth_provider, state.block - 1, filter.clone());
subscribe_to_logs(&eth_provider, filter.clone());
}
}

Expand Down
2 changes: 1 addition & 1 deletion kinode/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
};
use tokio::{fs, io::AsyncWriteExt, sync::Mutex};

include!("bootstrapped_processes.rs");
include!("../../target/bootstrapped_processes.rs");

pub async fn load_state(
our_name: String,
Expand Down