From 8c878eaeb21a227379b7aa84a2bcfe5cf7b5cb66 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Sun, 30 Jun 2024 13:17:49 +0700 Subject: [PATCH] work on getconfigparams --- Cargo.lock | 22 ++++++++-------- src/liteserver.rs | 64 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adcdb0c..4e86459 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,9 +344,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.100" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c891175c3fb232128f48de6590095e59198bbeb8620c310be349bfc3afd12c7b" +checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" dependencies = [ "jobserver", "libc", @@ -1366,9 +1366,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" dependencies = [ "serde", ] @@ -1569,9 +1569,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", @@ -2259,9 +2259,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" dependencies = [ "itoa", "ryu", @@ -2576,9 +2576,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" dependencies = [ "tinyvec_macros", ] @@ -2829,7 +2829,7 @@ dependencies = [ [[package]] name = "ton_liteapi" version = "0.1.0" -source = "git+https://github.com/tonstack/lite-client?branch=async#8289d25280eb8bbdf855f054ff9126e16b4f3015" +source = "git+https://github.com/tonstack/lite-client?branch=async#c3d8bb69b33ef62d02158537b1c9c9cda10b2652" dependencies = [ "adnl", "derivative", diff --git a/src/liteserver.rs b/src/liteserver.rs index 8c9f4aa..7124bf0 100644 --- a/src/liteserver.rs +++ b/src/liteserver.rs @@ -3,7 +3,7 @@ use std::{sync::Arc, task::Poll, time::Duration}; use anyhow::{anyhow, Result}; use broxus_util::now; use futures_util::future::BoxFuture; -use ton_block::{AccountIdPrefixFull, Block, Deserializable, GetRepresentationHash, HashmapAugType, InRefValue, MerkleProof, MsgAddrStd, Serializable, ShardIdent, ShardStateUnsplit, Transaction, TraverseNextStep}; +use ton_block::{AccountIdPrefixFull, Block, ConfigParams, Deserializable, GetRepresentationHash, HashmapAugType, InRefValue, MerkleProof, MsgAddrStd, Serializable, ShardIdent, ShardStateUnsplit, Transaction, TraverseNextStep}; use ton_indexer::{utils::ShardStateStuff, Engine, GlobalConfig}; use ton_liteapi::{ layers::{UnwrapMessagesLayer, WrapErrorLayer}, @@ -17,7 +17,7 @@ use ton_liteapi::{ }, types::LiteError, }; -use ton_types::{serialize_toc, BagOfCells, Cell, UInt256, UsageTree}; +use ton_types::{serialize_toc, BagOfCells, Cell, SliceData, UInt256, UsageTree}; use tower::{make::Shared, Service, ServiceBuilder}; use x25519_dalek::StaticSecret; @@ -72,6 +72,8 @@ impl LiteServer { with_state_update: bool, with_value_flow: bool, with_extra: bool, + with_shard_hashes: bool, + config_params: Vec ) -> Result { let usage_tree = UsageTree::with_root(block_root.clone()); let block = Block::construct_from_cell(usage_tree.root_cell())?; @@ -383,15 +385,51 @@ impl LiteServer { }) } - fn make_state_proof(state_root: Cell, with_accounts: bool, with_prev_blocks: bool) -> Result { + fn update_config_params(params: &mut Vec, with_validator_set: bool, with_special_smc: bool, with_workchain_info: bool, with_capabilities: bool) -> Result<()> { + if with_validator_set { + params.push(34); + } + if with_special_smc { + params.push(31); + } + if with_workchain_info { + params.push(12); + } + if with_capabilities { + params.push(8); + } + Ok(()) + } + + fn touch_config(config: &ConfigParams, with_params: &[i32]) -> Result<()> { + fn preload_param(config: &ConfigParams, param: i32) -> Result<()> { + let key = SliceData::load_builder(param.write_to_new_cell()?)?; + let slice = config.config_params.get(key)?.ok_or(anyhow!("no such param {param}"))?; + let cell = slice.reference_opt(0).ok_or(anyhow!("no such reference in param {param}"))?; + cell.preload_with_depth_hint::<32>()?; + Ok(()) + } + for i in with_params { + preload_param(config, *i)?; + } + Ok(()) + } + + fn make_state_proof(state_root: Cell, params: &[i32], with_accounts: bool, with_prev_blocks: bool, with_shard_hashes: bool) -> Result { let usage_tree = UsageTree::with_root(state_root.clone()); let state = ShardStateUnsplit::construct_from_cell(usage_tree.root_cell())?; if with_accounts { state.read_accounts()?; } let custom = state.read_custom()?.ok_or(anyhow!("no custom data in state"))?; - let mut counter = 0; - let _ = custom.prev_blocks.iterate_ext(true, None, |_, _| { counter += 1; Ok(counter < 16) })?; + if with_prev_blocks { + let mut counter = 0; + let _ = custom.prev_blocks.iterate_ext(true, None, |_, _| { counter += 1; Ok(counter < 16) })?; + } + if with_shard_hashes { + let _ = custom.shards.root().ok_or(anyhow!("no shards in state"))?.preload_with_depth_hint::<32>()?; + } + Self::touch_config(config, with_params) Ok(MerkleProof::create_by_usage_tree(&state_root, usage_tree)?) } @@ -399,6 +437,7 @@ impl LiteServer { if req.id.workchain != -1 { return Err(anyhow!("requested block is not in masterchain")) } + Self::update_config_params(&mut req.param_list, req.with_validator_set.is_some(), req.with_special_smc.is_some(), req.with_workchain_info.is_some(), req.with_capabilities.is_some())?; let block_root = self.load_block_by_tonlabs_id(&req.id.as_tonlabs()?).await?.ok_or(anyhow!("no such block in db"))?; let block = Block::construct_from_cell(block_root.clone())?; if req.extract_from_key_block.is_some() { @@ -420,6 +459,10 @@ impl LiteServer { with_accounts_root: req.with_accounts_root, with_prev_blocks: req.with_prev_blocks, extract_from_key_block: req.extract_from_key_block, + with_validator_set: req.with_validator_set, + with_special_smc: req.with_special_smc, + with_workchain_info: req.with_workchain_info, + with_capabilities: req.with_capabilities, }) } else { let state_root = self.load_state(&req.id).await?.root_cell().clone(); @@ -430,7 +473,12 @@ impl LiteServer { mode: (), id: req.id, state_proof: Self::make_block_proof(block_root, true, false, false)?.write_to_bytes()?, - config_proof: Self::make_state_proof(state_root, req.with_accounts_root.is_some(), req.with_prev_blocks.is_some())?.write_to_bytes()?, + config_proof: Self::make_state_proof( + state_root, + req.with_accounts_root.is_some(), + req.with_prev_blocks.is_some(), + req.with_shard_hashes.is_some() + )?.write_to_bytes()?, with_state_root: req.with_state_root, with_libraries: req.with_libraries, with_state_extra_root: req.with_state_extra_root, @@ -438,6 +486,10 @@ impl LiteServer { with_accounts_root: req.with_accounts_root, with_prev_blocks: req.with_accounts_root, extract_from_key_block: req.extract_from_key_block, + with_validator_set: req.with_validator_set, + with_special_smc: req.with_special_smc, + with_workchain_info: req.with_workchain_info, + with_capabilities: req.with_capabilities, }) }