From 131438b1cbc2b4f755af8c9152e02579901d5551 Mon Sep 17 00:00:00 2001 From: bitful-pannul Date: Fri, 9 Feb 2024 15:01:01 -0300 Subject: [PATCH] kns_indexer: make passthrough rpc proof --- modules/kns_indexer/kns_indexer/src/lib.rs | 13 +++++++++++++ modules/kns_indexer/pkg/manifest.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/kns_indexer/kns_indexer/src/lib.rs b/modules/kns_indexer/kns_indexer/src/lib.rs index ad14d706..4d045c28 100644 --- a/modules/kns_indexer/kns_indexer/src/lib.rs +++ b/modules/kns_indexer/kns_indexer/src/lib.rs @@ -170,6 +170,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> { ); // if contract address changed from a previous run, reset state if state.contract_address != contract_address { + println!("resetting state for some reason."); state = State { contract_address: contract_address.clone(), names: HashMap::new(), @@ -177,6 +178,15 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> { block: 1, }; } + + // shove all state into net::net + Request::new() + .target((&our.node, "net", "distro", "sys")) + .try_body(NetActions::KnsBatchUpdate( + state.nodes.values().cloned().collect::>(), + ))? + .send()?; + let filter = Filter::new() .address(contract_address.unwrap().parse::().unwrap()) .to_block(BlockNumberOrTag::Latest) @@ -188,6 +198,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> { "WsUpdate(bytes32,uint16)", "RoutingUpdate(bytes32,bytes32[])", ]); + // std::thread::sleep(std::time::Duration::from_secs(10)); // if block in state is < current_block, get logs from that part. if state.block < get_block_number()? { let logs = get_logs(filter.clone())?; @@ -203,6 +214,8 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> { ))? .send()?; + set_state(&bincode::serialize(&state)?); + let params = Params::Logs(Box::new(filter)); let kind = SubscriptionKind::Logs; diff --git a/modules/kns_indexer/pkg/manifest.json b/modules/kns_indexer/pkg/manifest.json index d29393b9..531fc002 100644 --- a/modules/kns_indexer/pkg/manifest.json +++ b/modules/kns_indexer/pkg/manifest.json @@ -3,7 +3,7 @@ "process_name": "kns_indexer", "process_wasm_path": "/kns_indexer.wasm", "on_exit": "Restart", - "request_networking": false, + "request_networking": true, "request_capabilities": [ "eth:distro:sys", "http_server:distro:sys",