From f5ef8f0720bbc201b0b0f7819582bed4510598d8 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Wed, 24 Apr 2024 18:42:19 +0700 Subject: [PATCH 1/7] int -> uint for all fields which not require negative values --- liteapi/src/tl/request.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/liteapi/src/tl/request.rs b/liteapi/src/tl/request.rs index c84c7be..420117d 100644 --- a/liteapi/src/tl/request.rs +++ b/liteapi/src/tl/request.rs @@ -34,8 +34,8 @@ pub struct WrappedRequest { scheme_inline = r##"liteServer.waitMasterchainSeqno seqno:int timeout_ms:int = Object;"## )] pub struct WaitMasterchainSeqno { - pub seqno: i32, - pub timeout_ms: i32, + pub seqno: u32, + pub timeout_ms: u32, } #[derive(TlRead, TlWrite, Derivative)] @@ -93,7 +93,7 @@ pub struct RunSmcMethod { pub mode: u32, pub id: BlockIdExt, pub account: AccountId, - pub method_id: i64, + pub method_id: u64, pub params: Vec, } @@ -117,15 +117,15 @@ pub struct GetAllShardsInfo { pub struct GetOneTransaction { pub id: BlockIdExt, pub account: AccountId, - pub lt: i64, + pub lt: u64, } #[derive(TlRead, TlWrite, Derivative)] #[derivative(Debug, Clone, PartialEq)] pub struct GetTransactions { - pub count: i32, + pub count: u32, pub account: AccountId, - pub lt: i64, + pub lt: u64, pub hash: Int256, } @@ -136,9 +136,9 @@ pub struct LookupBlock { pub mode: (), pub id: BlockId, #[tl(flags_bit = "mode.1")] - pub lt: Option, + pub lt: Option, #[tl(flags_bit = "mode.2")] - pub utime: Option, + pub utime: Option, } #[derive(TlRead, TlWrite, Derivative)] @@ -147,7 +147,7 @@ pub struct ListBlockTransactions { pub id: BlockIdExt, #[tl(flags)] pub mode: (), - pub count: i32, + pub count: u32, #[tl(flags_bit = "mode.7")] pub after: Option, #[tl(flags_bit = "mode.6")] @@ -187,11 +187,11 @@ pub struct GetValidatorStats { #[tl(flags)] pub mode: (), id: BlockIdExt, - pub limit: i32, + pub limit: u32, #[tl(flags_bit = "mode.0")] pub start_after: Option, #[tl(flags_bit = "mode.2")] - pub modified_after: Option, + pub modified_after: Option, } #[derive(TlRead, TlWrite, Derivative)] @@ -277,4 +277,4 @@ pub enum Request { /// liteServer.getValidatorStats#091a58bc mode:# id:tonNode.blockIdExt limit:int start_after:mode.0?int256 modified_after:mode.2?int = liteServer.ValidatorStats; #[tl(id = 0xe7253699)] GetValidatorStats(GetValidatorStats), -} \ No newline at end of file +} From 9adac481bc05a43aef1f6e44a96ceca902cc44aa Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Wed, 24 Apr 2024 18:46:27 +0700 Subject: [PATCH 2/7] int -> uint --- liteapi/src/tl/common.rs | 8 ++++---- liteapi/src/tl/response.rs | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/liteapi/src/tl/common.rs b/liteapi/src/tl/common.rs index a8a6a9a..39c455d 100644 --- a/liteapi/src/tl/common.rs +++ b/liteapi/src/tl/common.rs @@ -110,7 +110,7 @@ pub struct AccountId { // #[tl(boxed, id = "liteServer.transactionId3", scheme_inline = r##"liteServer.transactionId3 account:int256 lt:long = liteServer.TransactionId3;"##)] pub struct TransactionId3 { pub account: Int256, - pub lt: i64, + pub lt: u64, } /// liteServer.signature node_id_short:int256 signature:bytes = liteServer.Signature; @@ -131,8 +131,8 @@ pub struct Signature { scheme_inline = r##"liteServer.signatureSet validator_set_hash:int catchain_seqno:int signatures:(vector liteServer.signature) = liteServer.SignatureSet;"## )] pub struct SignatureSet { - pub validator_set_hash: i32, - pub catchain_seqno: i32, + pub validator_set_hash: u32, + pub catchain_seqno: u32, pub signatures: Vec, } @@ -186,7 +186,7 @@ pub struct TransactionId { #[tl(flags_bit = "mode.0")] pub account: Option, #[tl(flags_bit = "mode.1")] - pub lt: Option, + pub lt: Option, #[tl(flags_bit = "mode.2")] pub hash: Option, } \ No newline at end of file diff --git a/liteapi/src/tl/response.rs b/liteapi/src/tl/response.rs index 2e2e71c..d84ddcb 100644 --- a/liteapi/src/tl/response.rs +++ b/liteapi/src/tl/response.rs @@ -17,11 +17,11 @@ pub struct MasterchainInfo { pub struct MasterchainInfoExt { #[tl(flags)] pub mode: (), - pub version: i32, - pub capabilities: i64, + pub version: u32, + pub capabilities: u64, pub last: BlockIdExt, - pub last_utime: i32, - pub now: i32, + pub last_utime: u32, + pub now: u32, pub state_root_hash: Int256, pub init: ZeroStateIdExt, } @@ -29,16 +29,16 @@ pub struct MasterchainInfoExt { #[derive(TlRead, TlWrite, Derivative)] #[derivative(Debug, Clone, PartialEq)] pub struct CurrentTime { - pub now: i32, + pub now: u32, } #[derive(TlRead, TlWrite, Derivative)] #[derivative(Debug, Clone, PartialEq)] pub struct Version { - pub mode: i32, - pub version: i32, - pub capabilities: i64, - pub now: i32, + pub mode: u32, + pub version: u32, + pub capabilities: u64, + pub now: u32, } #[derive(TlRead, TlWrite, Derivative)] @@ -79,7 +79,7 @@ pub struct BlockHeader { #[derive(TlRead, TlWrite, Derivative)] #[derivative(Debug, Clone, PartialEq)] pub struct SendMsgStatus { - pub status: i32, + pub status: u32, } #[derive(TlRead, TlWrite, Derivative)] @@ -157,7 +157,7 @@ pub struct TransactionId { #[tl(flags_bit = "mode.0")] pub account: Option, #[tl(flags_bit = "mode.1")] - pub lt: Option, + pub lt: Option, #[tl(flags_bit = "mode.2")] pub hash: Option, } @@ -166,7 +166,7 @@ pub struct TransactionId { #[derivative(Debug, Clone, PartialEq)] pub struct BlockTransactions { pub id: BlockIdExt, - pub req_count: i32, + pub req_count: u32, pub incomplete: bool, pub ids: Vec, pub proof: Vec, @@ -197,7 +197,7 @@ pub struct ValidatorStats { #[tl(flags)] pub mode: (), pub id: BlockIdExt, - pub count: i32, + pub count: u32, pub complete: bool, pub state_proof: Vec, pub data_proof: Vec, From 3059856754751d0b80b8213d87756b6949f40803 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Fri, 3 May 2024 20:50:14 +0700 Subject: [PATCH 3/7] Add Eq + Hash to BlockIdExt --- liteapi/src/tl/common.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liteapi/src/tl/common.rs b/liteapi/src/tl/common.rs index 39c455d..f2da238 100644 --- a/liteapi/src/tl/common.rs +++ b/liteapi/src/tl/common.rs @@ -81,7 +81,7 @@ pub struct BlockId { /// tonNode.blockIdExt workchain:int shard:long seqno:int root_hash:int256 file_hash:int256 = tonNode.BlockIdExt; #[derive(TlRead, TlWrite, Derivative)] -#[derivative(Debug, Clone, PartialEq)] +#[derivative(Debug, Clone, PartialEq, Eq, Hash)] pub struct BlockIdExt { pub workchain: i32, pub shard: u64, @@ -189,4 +189,4 @@ pub struct TransactionId { pub lt: Option, #[tl(flags_bit = "mode.2")] pub hash: Option, -} \ No newline at end of file +} From 3d1889b1c1993337f7372508e472d6277153260c Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Fri, 3 May 2024 21:11:40 +0700 Subject: [PATCH 4/7] impl Hash for Int256 --- liteapi/src/tl/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liteapi/src/tl/common.rs b/liteapi/src/tl/common.rs index f2da238..0f3d8e2 100644 --- a/liteapi/src/tl/common.rs +++ b/liteapi/src/tl/common.rs @@ -40,7 +40,7 @@ impl String { /// int256 8*[ int ] = Int256; #[derive(TlRead, TlWrite, Derivative)] -#[derivative(Debug, Clone, PartialEq, Eq, Default)] +#[derivative(Debug, Clone, PartialEq, Eq, Default, Hash)] pub struct Int256(#[derivative(Debug(format_with = "fmt_bytes"))] pub [u8; 32]); impl FromStr for Int256 { From 2de33a69a0a2d0357fed18e62afe6032409cbad2 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Sat, 4 May 2024 01:40:09 +0700 Subject: [PATCH 5/7] Add seqno flag for LookupBlock --- liteapi/src/tl/request.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/liteapi/src/tl/request.rs b/liteapi/src/tl/request.rs index 420117d..7c8c262 100644 --- a/liteapi/src/tl/request.rs +++ b/liteapi/src/tl/request.rs @@ -135,6 +135,8 @@ pub struct LookupBlock { #[tl(flags)] pub mode: (), pub id: BlockId, + #[tl(flags_bit = "mode.0")] + pub seqno: Option<()>, #[tl(flags_bit = "mode.1")] pub lt: Option, #[tl(flags_bit = "mode.2")] From 18a2eae1ddc3b46e2ec7cd75c8b1685cbdd94876 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Mon, 6 May 2024 17:42:56 +0700 Subject: [PATCH 6/7] Add debug logs --- liteapi/src/server.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/liteapi/src/server.rs b/liteapi/src/server.rs index eaa1aa9..47b41ec 100644 --- a/liteapi/src/server.rs +++ b/liteapi/src/server.rs @@ -6,7 +6,6 @@ use std::time::Duration; use adnl::AdnlPeer; use adnl::AdnlPrivateKey; -use log::error; use tokio::net::TcpListener; use tokio::net::ToSocketAddrs; use tokio_tower::multiplex::Server; @@ -40,19 +39,21 @@ pub async fn serve(addr: &A, private_key: S, mut service_maker: M) -> R // > will be logged at the `error` level, since it is still a big deal, // > and then the listener will sleep for 1 second. if !matches!(e.kind(), ErrorKind::ConnectionRefused | ErrorKind::ConnectionAborted | ErrorKind::ConnectionReset) { - error!("accept error: {e}"); + log::error!("accept error: {e}"); tokio::time::sleep(Duration::from_secs(1)).await; } continue; } }; + log::debug!("[{addr:?}] Accepted socket"); poll_fn(|cx| service_maker.poll_ready(cx)).await.expect("polling service maker failed"); let service = service_maker.make_service(addr).await.expect("making service failed"); let private_key = private_key.clone(); tokio::spawn(async move { let adnl = AdnlPeer::handle_handshake(socket, |_| Some(private_key.clone())).await.expect("handshake failed"); + log::debug!("[{addr:?}] Handshake performed"); let lite = LitePeer::new(adnl); Server::new(lite, service).await.expect("server failed"); }); } -} \ No newline at end of file +} From 86a7cfa5228fd967e308be256a392f5a65ecd441 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Thu, 9 May 2024 23:43:07 +0700 Subject: [PATCH 7/7] Add block header modes for LookupBlock --- liteapi/src/tl/request.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/liteapi/src/tl/request.rs b/liteapi/src/tl/request.rs index 7c8c262..971b7c6 100644 --- a/liteapi/src/tl/request.rs +++ b/liteapi/src/tl/request.rs @@ -141,6 +141,16 @@ pub struct LookupBlock { pub lt: Option, #[tl(flags_bit = "mode.2")] pub utime: Option, + #[tl(flags_bit = "mode.4")] + pub with_state_update: Option<()>, + #[tl(flags_bit = "mode.5")] + pub with_value_flow: Option<()>, + #[tl(flags_bit = "mode.8")] + pub with_extra: Option<()>, + #[tl(flags_bit = "mode.9")] + pub with_shard_hashes: Option<()>, + #[tl(flags_bit = "mode.10")] + pub with_prev_blk_signatures: Option<()>, } #[derive(TlRead, TlWrite, Derivative)]