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
72 changes: 70 additions & 2 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions kinode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ simulation-mode = []

[dependencies]
aes-gcm = "0.10.3"
alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4", features = ["ws"]}
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-providers = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "6f8ebb4" }
alloy-primitives = "0.6.2"
alloy-sol-macro = "0.6.2"
alloy-sol-types = "0.6.2"
Expand Down Expand Up @@ -76,6 +79,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_urlencoded = "0.7"
sha2 = "0.10"
sha3 = "0.10.8"
snow = { version = "0.9.5", features = ["ring-resolver"] }
static_dir = "0.2.0"
thiserror = "1.0"
Expand Down
19 changes: 11 additions & 8 deletions kinode/packages/app_store/app_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,20 @@ use ft_worker_lib::{

const ICON: &str = include_str!("icon");

#[cfg(not(feature = "simulation-mode"))]
const CHAIN_ID: u64 = 10; // optimism
#[cfg(feature = "simulation-mode")]
const CHAIN_ID: u64 = 31337; // local

#[cfg(not(feature = "simulation-mode"))]
const CONTRACT_ADDRESS: &str = "0x52185B6a6017E6f079B994452F234f7C2533787B"; // optimism
#[cfg(feature = "simulation-mode")]
const CONTRACT_ADDRESS: &str = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"; // local

#[cfg(not(feature = "simulation-mode"))]
const CONTRACT_FIRST_BLOCK: u64 = 118_590_088;
#[cfg(feature = "simulation-mode")]
const CONTRACT_FIRST_BLOCK: u64 = 1;

const EVENTS: [&str; 3] = [
"AppRegistered(uint256,string,bytes,string,bytes32)",
Expand Down Expand Up @@ -71,7 +82,6 @@ pub enum Resp {
}

fn fetch_logs(eth_provider: &eth::Provider, filter: &eth::Filter) -> Vec<eth::Log> {
#[cfg(not(feature = "simulation-mode"))]
loop {
match eth_provider.get_logs(filter) {
Ok(res) => return res,
Expand All @@ -82,13 +92,10 @@ fn fetch_logs(eth_provider: &eth::Provider, filter: &eth::Filter) -> Vec<eth::Lo
}
}
}
#[cfg(feature = "simulation-mode")] // TODO use local testnet, provider_chainId: 31337
vec![]
}

#[allow(unused_variables)]
fn subscribe_to_logs(eth_provider: &eth::Provider, filter: eth::Filter) {
#[cfg(not(feature = "simulation-mode"))]
loop {
match eth_provider.subscribe(1, filter.clone()) {
Ok(()) => break,
Expand All @@ -99,7 +106,6 @@ fn subscribe_to_logs(eth_provider: &eth::Provider, filter: eth::Filter) {
}
}
}
#[cfg(not(feature = "simulation-mode"))]
println!("subscribed to logs successfully");
}

Expand Down Expand Up @@ -221,10 +227,7 @@ fn init(our: Address) {
state = State::new(CONTRACT_ADDRESS.to_string()).unwrap();
}

#[cfg(not(feature = "simulation-mode"))]
println!("indexing on contract address {}", state.contract_address);
#[cfg(feature = "simulation-mode")]
println!("simulation mode: not indexing packages");

// create new provider for sepolia with request-timeout of 60s
// can change, log requests can take quite a long time.
Expand Down
3 changes: 3 additions & 0 deletions kinode/packages/kino_updates/widget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "widget"
version = "0.1.0"
edition = "2021"

[features]
simulation-mode = []

[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
Expand Down
49 changes: 30 additions & 19 deletions kinode/packages/kns_indexer/kns_indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@ wit_bindgen::generate!({
world: "process",
});

// perhaps a constant in process_lib?
const KNS_OPTIMISM_ADDRESS: &'static str = "0xca5b5811c0c40aab3295f932b1b5112eb7bb4bd6";
const KNS_FIRST_BLOCK: u64 = 114_923_786;
#[cfg(not(feature = "simulation-mode"))]
const KNS_ADDRESS: &'static str = "0xca5b5811c0c40aab3295f932b1b5112eb7bb4bd6"; // optimism
#[cfg(feature = "simulation-mode")]
const KNS_ADDRESS: &'static str = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; // local

#[cfg(not(feature = "simulation-mode"))]
const CHAIN_ID: u64 = 10; // optimism
#[cfg(feature = "simulation-mode")]
const CHAIN_ID: u64 = 31337; // local

#[cfg(not(feature = "simulation-mode"))]
const KNS_FIRST_BLOCK: u64 = 114_923_786; // optimism
#[cfg(feature = "simulation-mode")]
const KNS_FIRST_BLOCK: u64 = 1; // local

#[derive(Clone, Debug, Serialize, Deserialize)]
struct State {
Expand Down Expand Up @@ -100,7 +111,6 @@ sol! {
}

fn subscribe_to_logs(eth_provider: &eth::Provider, from_block: u64, filter: eth::Filter) {
#[cfg(not(feature = "simulation-mode"))]
loop {
match eth_provider.subscribe(1, filter.clone().from_block(from_block)) {
Ok(()) => break,
Expand All @@ -111,28 +121,22 @@ fn subscribe_to_logs(eth_provider: &eth::Provider, from_block: u64, filter: eth:
}
}
}
#[cfg(not(feature = "simulation-mode"))]
println!("subscribed to logs successfully");
}

call_init!(init);
fn init(our: Address) {
let (chain_id, contract_address) = (10, KNS_OPTIMISM_ADDRESS.to_string());

#[cfg(not(feature = "simulation-mode"))]
println!("indexing on contract address {}", contract_address);
#[cfg(feature = "simulation-mode")]
println!("simulation mode: not indexing KNS");
println!("indexing on contract address {}", KNS_ADDRESS);

// if we have state, load it in
let state: State = match get_typed_state(|bytes| Ok(bincode::deserialize::<State>(bytes)?)) {
Some(s) => {
// if chain id or contract address changed from a previous run, reset state
if s.chain_id != chain_id || s.contract_address != contract_address {
if s.chain_id != CHAIN_ID || s.contract_address != KNS_ADDRESS {
println!("resetting state because runtime contract address or chain ID changed");
State {
chain_id,
contract_address,
chain_id: CHAIN_ID,
contract_address: KNS_ADDRESS.to_string(),
names: HashMap::new(),
nodes: HashMap::new(),
block: KNS_FIRST_BLOCK,
Expand All @@ -143,8 +147,8 @@ fn init(our: Address) {
}
}
None => State {
chain_id,
contract_address: contract_address.clone(),
chain_id: CHAIN_ID,
contract_address: KNS_ADDRESS.to_string(),
names: HashMap::new(),
nodes: HashMap::new(),
block: KNS_FIRST_BLOCK,
Expand Down Expand Up @@ -184,8 +188,12 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
// if they do time out, we try them again
let eth_provider = eth::Provider::new(state.chain_id, 60);

println!(
"subscribing, state.block: {}, chain_id: {}",
state.block, state.chain_id
);

// if block in state is < current_block, get logs from that part.
#[cfg(not(feature = "simulation-mode"))]
if state.block < eth_provider.get_block_number().unwrap_or(u64::MAX) {
loop {
match eth_provider.get_logs(&filter) {
Expand All @@ -200,8 +208,11 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
}
break;
}
Err(_) => {
println!("failed to fetch logs! trying again in 5s...");
Err(e) => {
println!(
"got eth error while fetching logs: {:?}, trying again in 5s...",
e
);
std::thread::sleep(std::time::Duration::from_secs(5));
continue;
}
Expand Down
7 changes: 0 additions & 7 deletions kinode/src/eth/default_providers_mainnet.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
[
{
"chain_id": 31337,
"trusted": true,
"provider": {
"RpcUrl": "wss://localhost:8545"
}
},
{
"chain_id": 1,
"trusted": false,
Expand Down
Loading