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
367 changes: 291 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion kinode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 4 additions & 4 deletions kinode/packages/app_store/app_store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions kinode/packages/app_store/app_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
38 changes: 22 additions & 16 deletions kinode/packages/app_store/app_store/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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();

Expand All @@ -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"));
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion kinode/packages/app_store/download/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion kinode/packages/app_store/ft_worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion kinode/packages/app_store/install/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/app_store/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion kinode/packages/app_store/uninstall/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/chess/chess/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chess"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

[features]
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/chess/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/homepage/homepage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "homepage"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

[features]
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/homepage/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion kinode/packages/kns_indexer/get_block/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions kinode/packages/kns_indexer/kns_indexer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "kns_indexer"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

[features]
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"
Expand Down
46 changes: 30 additions & 16 deletions kinode/packages/kns_indexer/kns_indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand All @@ -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,
},
};

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -295,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) => {
Expand Down Expand Up @@ -345,7 +356,7 @@ fn handle_eth_message(
}

fn handle_log(our: &Address, state: &mut State, log: &eth::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(),
Expand All @@ -359,15 +370,15 @@ fn handle_log(our: &Address, state: &mut State, log: &eth::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,
Expand All @@ -380,15 +391,15 @@ fn handle_log(our: &Address, state: &mut State, log: &eth::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::<Vec<String>>();
Expand All @@ -413,7 +424,7 @@ fn handle_log(our: &Address, state: &mut State, log: &eth::Log) -> anyhow::Resul
}

// if new block is > 100 from last block, save state
let block = log.block_number.expect("expect").to::<u64>();
let block = log.block_number.expect("expect");
if block > state.block + 100 {
kinode_process_lib::print_to_terminal(
1,
Expand All @@ -430,9 +441,12 @@ fn handle_log(our: &Address, state: &mut State, log: &eth::Log) -> anyhow::Resul
}

fn get_name(log: &eth::Log) -> anyhow::Result<String> {
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<u8>) -> Result<String, FromUtf8Error> {
Expand Down
Loading