attempt v10.0.0 merge 2

This commit is contained in:
bitful-pannul 2024-12-17 15:19:14 +02:00
commit e586d5a453
28 changed files with 243 additions and 91 deletions

5
Cargo.lock generated
View File

@ -4008,6 +4008,7 @@ dependencies = [
"anyhow",
"hex",
"kinode_process_lib 0.10.0",
"process_macros",
"rmp-serde",
"serde",
"serde_json",
@ -4985,7 +4986,8 @@ dependencies = [
[[package]]
name = "process_macros"
version = "0.1.0"
source = "git+https://github.com/kinode-dao/process_macros?rev=626e501#626e501d351e3365480ec6f770d474ed4ae339bf"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecfcd7b51a1b9249fb47359a9f8d57a9e9dbc71857c5cfd08f98764f7106a3d"
dependencies = [
"quote",
"syn 2.0.90",
@ -6069,6 +6071,7 @@ name = "state"
version = "0.1.0"
dependencies = [
"kinode_process_lib 0.10.0",
"process_macros",
"serde",
"serde_json",
"wit-bindgen 0.36.0",

View File

@ -2101,7 +2101,8 @@ dependencies = [
[[package]]
name = "process_macros"
version = "0.1.0"
source = "git+https://github.com/kinode-dao/process_macros?rev=626e501#626e501d351e3365480ec6f770d474ed4ae339bf"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecfcd7b51a1b9249fb47359a9f8d57a9e9dbc71857c5cfd08f98764f7106a3d"
dependencies = [
"quote",
"syn 2.0.90",

View File

@ -22,25 +22,41 @@ interface main {
/// Local requests that can be made to the App Store
variant local-request {
/// Request to add a new package to app-store. Includes zip and an optional onchain-metadata.
/// This is used by kit start
/// Request to add a new package to app-store.
///
/// Used by kit start-package.
///
/// lazy-load-blob: required; the zipped package to be added.
new-package(new-package-request),
/// Request to install a package
/// Request to install a package.
///
/// lazy-load-blob: none.
install(install-package-request),
/// Request to uninstall a package
/// Request to uninstall a package.
///
/// lazy-load-blob: none.
uninstall(package-id),
/// Request to list all available APIs
///
/// lazy-load-blob: none.
apis,
/// Request to get a specific API
///
/// lazy-load-blob: none.
get-api(package-id),
}
/// Local responses from the App Store
variant local-response {
/// lazy-load-blob: none.
new-package-response(new-package-response),
/// lazy-load-blob: none.
install-response(install-response),
/// lazy-load-blob: none.
uninstall-response(uninstall-response),
/// lazy-load-blob: none.
apis-response(apis-response),
/// lazy-load-blob: on success; the WIT API that was requested.
get-api-response(get-api-response),
}
@ -99,24 +115,40 @@ interface chain {
/// Requests that can be made to the chain component
variant chain-requests {
/// Get information about a specific app
///
/// lazy-load-blob: none.
get-app(package-id),
/// Get information about all apps
///
/// lazy-load-blob: none.
get-apps,
/// Get information about apps published by the current node
///
/// lazy-load-blob: none.
get-our-apps,
/// Start auto-updating an app
///
/// lazy-load-blob: none.
start-auto-update(package-id),
/// Stop auto-updating an app
///
/// lazy-load-blob: none.
stop-auto-update(package-id),
}
/// Responses from the chain component
variant chain-responses {
/// lazy-load-blob: none.
get-app(option<onchain-app>),
/// lazy-load-blob: none.
get-apps(list<onchain-app>),
/// lazy-load-blob: none.
get-our-apps(list<onchain-app>),
/// lazy-load-blob: none.
auto-update-started,
/// lazy-load-blob: none.
auto-update-stopped,
/// lazy-load-blob: none.
err(chain-error),
}
@ -171,37 +203,66 @@ interface downloads {
/// Requests that can be made to the downloads component
variant download-requests {
/// Request a remote download
///
/// lazy-load-blob: none.
remote-download(remote-download-request),
/// Request a chunk of a file
///
/// lazy-load-blob: none.
chunk(chunk-request),
/// Update download progress
///
/// lazy-load-blob: none.
progress(progress-update),
/// Update file size information
///
/// lazy-load-blob: none.
size(size-update),
/// Request a local download
///
/// lazy-load-blob: none.
local-download(local-download-request),
/// Request an auto-update
///
/// lazy-load-blob: none.
auto-update(auto-update-request),
/// Notify that a download is complete
///
/// lazy-load-blob: none.
download-complete(download-complete-request),
/// Auto-update-download complete
///
/// lazy-load-blob: none.
auto-download-complete(auto-download-complete-request),
/// Get files for a package
///
/// lazy-load-blob: none.
get-files(option<package-id>),
/// Remove a file
///
/// lazy-load-blob: none.
remove-file(remove-file-request),
/// Add a download
///
/// lazy-load-blob: none.
add-download(add-download-request),
/// Start mirroring a package
///
/// lazy-load-blob: none.
start-mirroring(package-id),
/// Stop mirroring a package
///
/// lazy-load-blob: none.
stop-mirroring(package-id),
}
/// Responses from the downloads component
variant download-responses {
/// lazy-load-blob: none.
success,
/// lazy-load-blob: none.
err(download-error),
/// lazy-load-blob: none.
get-files(list<entry>),
}

View File

@ -12,7 +12,7 @@ alloy-sol-types = "0.7.6"
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -12,7 +12,7 @@ alloy-sol-types = "0.7.6"
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -611,21 +611,6 @@ fn handle_eth_log(
if !startup {
state.last_saved_block = block_number;
state.db.set_last_saved_block(block_number)?;
// if auto_update is enabled, send a message to downloads to kick off the update.
if let Some(listing) = state.listings.get(&package_id) {
if listing.auto_update {
print_to_terminal(0, &format!("kicking off auto-update for: {}", package_id));
Request::to(("our", "downloads", "app-store", "sys"))
.body(&DownloadRequests::AutoUpdate(AutoUpdateRequest {
package_id: crate::kinode::process::main::PackageId::from_process_lib(
package_id,
),
metadata: metadata.unwrap().into(),
}))
.send()
.unwrap();
}
}
}
Ok(())

View File

@ -9,7 +9,7 @@ simulation-mode = []
[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.36.0"

View File

@ -9,7 +9,7 @@ simulation-mode = []
[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -10,7 +10,7 @@ simulation-mode = []
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -9,7 +9,7 @@ simulation-mode = []
[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.36.0"

View File

@ -9,7 +9,7 @@ simulation-mode = []
[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.36.0"

View File

@ -3,15 +3,22 @@ interface chess {
/// to a byte vector and send them over IPC.
variant request {
/// lazy-load-blob: none.
new-game(new-game-request),
/// lazy-load-blob: none.
move(move-request),
/// lazy-load-blob: none.
resign(string),
}
variant response {
/// lazy-load-blob: none.
new-game-accepted,
/// lazy-load-blob: none.
new-game-rejected,
/// lazy-load-blob: none.
move-accepted,
/// lazy-load-blob: none.
move-rejected,
}

View File

@ -1958,7 +1958,8 @@ dependencies = [
[[package]]
name = "process_macros"
version = "0.1.0"
source = "git+https://github.com/kinode-dao/process_macros?rev=626e501#626e501d351e3365480ec6f770d474ed4ae339bf"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecfcd7b51a1b9249fb47359a9f8d57a9e9dbc71857c5cfd08f98764f7106a3d"
dependencies = [
"quote",
"syn 2.0.90",

View File

@ -7,26 +7,45 @@ interface contacts {
}
variant request {
/// lazy-load-blob: none.
get-names, // requires read-names-only
/// lazy-load-blob: none.
get-all-contacts, // requires read
/// lazy-load-blob: none.
get-contact(string), // requires read
/// lazy-load-blob: none.
add-contact(string), // requires add
// tuple<node, field, value>
/// tuple<node, field, value>
///
/// lazy-load-blob: none.
add-field(tuple<string, string, string>), // requires add
/// lazy-load-blob: none.
remove-contact(string), // requires remove
// tuple<node, field>
/// tuple<node, field>
///
/// lazy-load-blob: none.
remove-field(tuple<string, string>), // requires remove
}
variant response {
/// lazy-load-blob: none.
get-names(list<string>),
get-all-contacts, // JSON all-contacts dict in blob
get-contact, // JSON contact dict in blob
/// lazy-load-blob: required; JSON all-contacts dict in blob.
get-all-contacts,
/// lazy-load-blob: required; JSON contact dict in blob.
get-contact,
/// lazy-load-blob: none.
add-contact,
/// lazy-load-blob: none.
add-field,
/// lazy-load-blob: none.
remove-contact,
/// lazy-load-blob: none.
remove-field,
err(string), // any failed request will receive this response
/// any failed request will receive this response
///
/// lazy-load-blob: none.
err(string),
}
}

View File

@ -8,7 +8,7 @@ simulation-mode = []
[dependencies]
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.36.0"

View File

@ -7,7 +7,7 @@ publish = false
[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.36.0"

View File

@ -10,16 +10,24 @@ interface homepage {
/// the package and process name will come from request source.
/// the path will automatically have the process_id prepended.
/// the icon is a base64 encoded image.
///
/// lazy-load-blob: none.
add(add-request),
/// remove ourself from homepage (message source will be item removed)
///
/// lazy-load-blob: none.
remove,
/// remove another app from homepage
/// using this requires RemoveOther capability
/// app store uses this to remove apps on uninstall
///
/// lazy-load-blob: none.
remove-other(string),
/// set the stylesheet for the homepage
/// using this requires SetStylesheet capability
/// settings:settings:sys uses this to set the stylesheet
///
/// lazy-load-blob: none.
set-stylesheet(string),
}

View File

@ -1536,6 +1536,7 @@ dependencies = [
"anyhow",
"hex",
"kinode_process_lib",
"process_macros",
"rmp-serde",
"serde",
"serde_json",
@ -1958,6 +1959,16 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "process_macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecfcd7b51a1b9249fb47359a9f8d57a9e9dbc71857c5cfd08f98764f7106a3d"
dependencies = [
"quote",
"syn 2.0.90",
]
[[package]]
name = "proptest"
version = "1.5.0"
@ -2452,6 +2463,7 @@ name = "state"
version = "0.1.0"
dependencies = [
"kinode_process_lib",
"process_macros",
"serde",
"serde_json",
"wit-bindgen",

View File

@ -6,7 +6,7 @@ interface kns-indexer {
/// human readable name, you would send a NodeInfo request.
/// The block parameter specifies the recency of the data: the indexer will
/// not respond until it has processed events up to the specified block.
variant indexer-requests {
variant indexer-request {
/// return the human readable name for a namehash
/// returns an Option<String>
namehash-to-name(namehash-to-name-request),
@ -19,6 +19,12 @@ interface kns-indexer {
get-state(get-state-request),
}
variant indexer-response {
name(option<string>),
node-info(option<wit-kns-update>),
get-state(wit-state),
}
record namehash-to-name-request {
hash: string,
block: u64,
@ -32,6 +38,22 @@ interface kns-indexer {
record get-state-request {
block: u64,
}
record wit-kns-update {
name: string,
public-key: string,
ips: list<string>,
ports: list<tuple<string, u16>>, // map, but wit doesn't support maps
routers: list<string>,
}
record wit-state {
chain-id: u64,
contract-address: list<u8>, // 20-byte ETH address
names: list<tuple<string, string>>, // map, but wit doesn't support maps
nodes: list<tuple<string, wit-kns-update>>, // map, but wit doesn't support maps
last-block: u64,
}
}
world kns-indexer-sys-v0 {

View File

@ -12,6 +12,7 @@ alloy-primitives = "0.7.0"
alloy-sol-types = "0.7.0"
hex = "0.4.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = "0.1"
rmp-serde = "1.1.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -1,5 +1,6 @@
use crate::kinode::process::kns_indexer::{
GetStateRequest, IndexerRequests, NamehashToNameRequest, NodeInfoRequest,
GetStateRequest, IndexerRequest, IndexerResponse, NamehashToNameRequest, NodeInfoRequest,
WitKnsUpdate, WitState,
};
use alloy_primitives::keccak256;
use alloy_sol_types::SolEvent;
@ -19,7 +20,7 @@ wit_bindgen::generate!({
path: "target/wit",
world: "kns-indexer-sys-v0",
generate_unused_types: true,
additional_derives: [serde::Deserialize, serde::Serialize],
additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto],
});
#[cfg(not(feature = "simulation-mode"))]
@ -241,12 +242,53 @@ impl State {
}
}
// note: not defined in wit api right now like IndexerRequests.
#[derive(Clone, Debug, Serialize, Deserialize)]
enum IndexerResponses {
Name(Option<String>),
NodeInfo(Option<net::KnsUpdate>),
GetState(State),
// impl From<State> for WitState {
// fn from(s: State) -> Self {
// let contract_address: [u8; 20] = s.contract_address.into();
// WitState {
// chain_id: s.chain_id.clone(),
// contract_address: contract_address.to_vec(),
// names: s
// .names
// .iter()
// .map(|(k, v)| (k.clone(), v.clone()))
// .collect::<Vec<_>>(),
// nodes: s
// .nodes
// .iter()
// .map(|(k, v)| (k.clone(), v.clone().into()))
// .collect::<Vec<_>>(),
// last_block: s.last_block.clone(),
// }
// }
// }
impl From<net::KnsUpdate> for WitKnsUpdate {
fn from(k: net::KnsUpdate) -> Self {
WitKnsUpdate {
name: k.name.clone(),
public_key: k.public_key.clone(),
ips: k.ips.clone(),
ports: k
.ports
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect::<Vec<_>>(),
routers: k.routers.clone(),
}
}
}
impl From<WitKnsUpdate> for net::KnsUpdate {
fn from(k: WitKnsUpdate) -> Self {
net::KnsUpdate {
name: k.name.clone(),
public_key: k.public_key.clone(),
ips: k.ips.clone(),
ports: BTreeMap::from_iter(k.ports),
routers: k.routers.clone(),
}
}
}
#[derive(Debug, thiserror::Error)]
@ -320,7 +362,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
// pending_requests temporarily on timeout.
// very naughty.
// let mut pending_requests: BTreeMap<u64, Vec<IndexerRequests>> = BTreeMap::new();
// let mut pending_requests: BTreeMap<u64, Vec<IndexerRequest>> = BTreeMap::new();
let mut pending_notes: BTreeMap<u64, Vec<(kimap::contract::Note, u8)>> = BTreeMap::new();
// if block in state is < current_block, get logs from that part.
@ -376,26 +418,26 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
let request = serde_json::from_slice(&body)?;
match request {
IndexerRequests::NamehashToName(NamehashToNameRequest { ref hash, .. }) => {
IndexerRequest::NamehashToName(NamehashToNameRequest { ref hash, .. }) => {
// TODO: make sure we've seen the whole block, while actually
// sending a response to the proper place.
Response::new()
.body(serde_json::to_vec(&IndexerResponses::Name(
state.get_name(hash),
))?)
.body(IndexerResponse::Name(state.get_name(hash)))
.send()?;
}
IndexerRequests::NodeInfo(NodeInfoRequest { ref name, .. }) => {
IndexerRequest::NodeInfo(NodeInfoRequest { ref name, .. }) => {
Response::new()
.body(serde_json::to_vec(&IndexerResponses::NodeInfo(
state.get_node(name),
))?)
.body(&IndexerResponse::NodeInfo(
state
.get_node(name)
.map(|update| WitKnsUpdate::from(update)),
))
.send()?;
}
// note no longer relevant.
// TODO: redo with iterator once available.
IndexerRequests::GetState(GetStateRequest { .. }) => {
IndexerRequest::GetState(GetStateRequest { .. }) => {
Response::new().body(serde_json::to_vec(&state)?).send()?;
}
}

View File

@ -1,5 +1,5 @@
{
"get_block.wasm": {
"get-block.wasm": {
"root": false,
"public": false,
"request_networking": false,

View File

@ -8,6 +8,7 @@ simulation-mode = []
[dependencies]
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.36.0"

View File

@ -1,58 +1,44 @@
use kinode_process_lib::{eth, net, script, Address, Message, Request};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::kinode::process::kns_indexer::{GetStateRequest, IndexerRequest, IndexerResponse};
use kinode_process_lib::{eth, script, Address, Message, Request};
wit_bindgen::generate!({
path: "target/wit",
world: "process-v1",
world: "kns-indexer-sys-v0",
generate_unused_types: true,
additional_derives: [serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto],
});
/// From main kns-indexer process
#[derive(Clone, Debug, Serialize, Deserialize)]
struct State {
chain_id: u64,
// what contract this state pertains to
contract_address: eth::Address,
// namehash to human readable name
names: HashMap<String, String>,
// human readable name to most recent on-chain routing information as json
// TODO: optional params knsUpdate? also include tba.
nodes: HashMap<String, net::KnsUpdate>,
// last block we have an update from
last_block: u64,
}
script!(init);
fn init(_our: Address, _args: String) -> String {
// we don't take any args
let Ok(Message::Response { body, .. }) =
Request::to(("our", "kns-indexer", "kns-indexer", "sys"))
.body(
serde_json::json!({
"GetState": {
"block": 0
}
})
.to_string()
.as_bytes()
.to_vec(),
)
.body(IndexerRequest::GetState(GetStateRequest { block: 0 }))
.send_and_await_response(10)
.unwrap()
else {
return "failed to get state from kns-indexer".to_string();
};
let Ok(state) = serde_json::from_slice::<State>(&body) else {
let Ok(IndexerResponse::GetState(state)) = body.try_into() else {
return "failed to deserialize state".to_string();
};
// can change later, but for now, just print every known node name
let mut names = state.names.values().map(AsRef::as_ref).collect::<Vec<_>>();
let mut names = state
.names
.iter()
.map(|(_k, v)| v.clone())
.collect::<Vec<_>>();
names.sort();
let contract_address: [u8; 20] = state
.contract_address
.try_into()
.expect("invalid contract addess: doesn't have 20 bytes");
let contract_address: eth::Address = contract_address.into();
format!(
"\nrunning on chain id {}\nCA: {}\n{} known nodes as of block {}\n {}",
state.chain_id,
state.contract_address,
contract_address,
names.len(),
state.last_block,
names.join("\n ")

View File

@ -1935,7 +1935,8 @@ dependencies = [
[[package]]
name = "process_macros"
version = "0.1.0"
source = "git+https://github.com/kinode-dao/process_macros?rev=626e501#626e501d351e3365480ec6f770d474ed4ae339bf"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecfcd7b51a1b9249fb47359a9f8d57a9e9dbc71857c5cfd08f98764f7106a3d"
dependencies = [
"quote",
"syn 2.0.90",

View File

@ -1,9 +1,11 @@
interface tester {
variant request {
/// lazy-load-blob: none.
run(run-request),
}
variant response {
/// lazy-load-blob: none.
run(result<_, fail-response>)
}

View File

@ -10,7 +10,7 @@ simulation-mode = []
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "9c441fe" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
process_macros = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"

Binary file not shown.