Skip to content

Commit

Permalink
fix: update GetBlockchainConfig response
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon authored and 0xdeafbeef committed Sep 7, 2024
1 parent c8a19c0 commit c65a1fd
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum RpcClient {
}

impl RpcClient {
pub async fn new<I: IntoIterator<Item=Url> + Send + Clone>(
pub async fn new<I: IntoIterator<Item = Url> + Send + Clone>(
endpoints: I,
options: ClientOptions,
) -> Result<Self> {
Expand Down Expand Up @@ -265,7 +265,7 @@ pub trait Client<T>: Send + Sync + Sized
where
T: Connection + Ord + Clone + 'static,
{
async fn new<I: IntoIterator<Item=Url> + Send>(
async fn new<I: IntoIterator<Item = Url> + Send>(
endpoints: I,
options: ClientOptions,
) -> Result<Self> {
Expand All @@ -285,7 +285,7 @@ where
}

/// `endpoints` - full URLs of the RPC endpoints.
async fn with_client<I: IntoIterator<Item=Url> + Send>(
async fn with_client<I: IntoIterator<Item = Url> + Send>(
client: reqwest::Client,
endpoints: I,
options: ClientOptions,
Expand Down Expand Up @@ -602,7 +602,7 @@ impl<'a, T: Serialize + Send + Sync> RpcRequest<'a, T> {

pub enum RpcResponse<D>
where
for<'de> D: Deserialize<'de>,
for<'de> D: Deserialize<'de>,
{
JRPC(Answer<D>),
PROTO(Answer<rpc::Response>),
Expand Down
1 change: 1 addition & 0 deletions models/src/jrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct GetBlockchainConfigResponse {
pub global_id: i32,
#[serde(with = "serde_ton_block")]
pub config: ton_block::ConfigParams,
pub seqno: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tower-http = { version = "0.4.0", features = ["cors", "timeout"] }
tracing = "0.1.37"
metrics = "0.22.0"
uuid = { version = "1.6", features = ["v4", "serde"] }
weedb = { version = "0.2.4", features = ["zstd", "lz4", "jemalloc"] }
weedb = { version = "0.2.5", features = ["zstd", "lz4", "jemalloc"] }

nekoton-abi = { git = "https://github.com/broxus/nekoton.git", default-features = false }
nekoton-proto = { git = "https://github.com/broxus/nekoton.git", default-features = false }
Expand Down
8 changes: 5 additions & 3 deletions server/src/jrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl JrpcServer {

// Prepare key block response listener
fn serialize_block(
seqno: u32,
block: &ton_block::Block,
) -> Result<(Arc<serde_json::Value>, Arc<serde_json::Value>)> {
let extra = block.read_extra()?;
Expand All @@ -66,15 +67,16 @@ impl JrpcServer {
let config_response = serde_json::to_value(jrpc::GetBlockchainConfigResponse {
global_id: block.global_id,
config: config.clone(),
seqno,
})?;

Ok((Arc::new(key_block_response), Arc::new(config_response)))
}

let mut key_block_rx = state.runtime_storage.subscribe_to_key_blocks();
let (key_block_response, config_response) = match &*key_block_rx.borrow_and_update() {
Some(block) => {
let (key_block, config) = serialize_block(block)?;
Some((seqno, block)) => {
let (key_block, config) = serialize_block(*seqno, block)?;
(
Arc::new(ArcSwapOption::new(Some(key_block))),
Arc::new(ArcSwapOption::new(Some(config))),
Expand All @@ -97,7 +99,7 @@ impl JrpcServer {
let data = key_block_rx
.borrow_and_update()
.as_ref()
.map(serialize_block);
.map(|(seqno, block)| serialize_block(*seqno, block));

match data {
Some(Ok((key_block, config))) => {
Expand Down
7 changes: 4 additions & 3 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ impl RpcState {
match engine.load_last_key_block().await {
Ok(last_key_block) => {
self.runtime_storage
.update_key_block(last_key_block.block());
.update_key_block(last_key_block.id().seq_no, last_key_block.block());
}
Err(e) => {
if self.config.api_config.common().generate_stub_keyblock {
let zerostate = engine.load_mc_zero_state().await?;
self.runtime_storage
.update_key_block(&make_key_block_stub(&zerostate)?);
.update_key_block(0, &make_key_block_stub(&zerostate)?);
} else {
return Err(e);
}
Expand Down Expand Up @@ -237,7 +237,8 @@ impl RpcState {
}

if block_info.key_block() {
self.runtime_storage.update_key_block(block);
self.runtime_storage
.update_key_block(block_id.seq_no, block);
}

if let Some(storage) = &self.persistent_storage {
Expand Down
8 changes: 5 additions & 3 deletions server/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl ProtoServer {

// Prepare key block response listener
fn serialize_block(
seqno: u32,
block: &ton_block::Block,
) -> Result<(
Arc<rpc::response::GetLatestKeyBlock>,
Expand All @@ -74,15 +75,16 @@ impl ProtoServer {
let config_response = rpc::response::GetBlockchainConfig {
global_id: block.global_id,
config: Bytes::from(config.write_to_bytes()?),
seqno,
};

Ok((Arc::new(key_block_response), Arc::new(config_response)))
}

let mut key_block_rx = state.runtime_storage.subscribe_to_key_blocks();
let (key_block_response, config_response) = match &*key_block_rx.borrow_and_update() {
Some(block) => {
let (key_block, config) = serialize_block(block)?;
Some((seqno, block)) => {
let (key_block, config) = serialize_block(*seqno, block)?;
(
Arc::new(ArcSwapOption::new(Some(key_block))),
Arc::new(ArcSwapOption::new(Some(config))),
Expand All @@ -105,7 +107,7 @@ impl ProtoServer {
let data = key_block_rx
.borrow_and_update()
.as_ref()
.map(serialize_block);
.map(|(seqno, block)| serialize_block(*seqno, block));

match data {
Some(Ok((key_block, config))) => {
Expand Down
8 changes: 4 additions & 4 deletions server/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{PersistentStorageConfig, TransactionsGcOptions};
pub mod tables;

pub struct RuntimeStorage {
key_block: watch::Sender<Option<ton_block::Block>>,
key_block: watch::Sender<Option<(u32, ton_block::Block)>>,
masterchain_accounts_cache: RwLock<Option<ShardAccounts>>,
shard_accounts_cache: RwLock<FxHashMap<ton_block::ShardIdent, ShardAccounts>>,
}
Expand All @@ -36,12 +36,12 @@ impl Default for RuntimeStorage {
}

impl RuntimeStorage {
pub fn subscribe_to_key_blocks(&self) -> watch::Receiver<Option<ton_block::Block>> {
pub fn subscribe_to_key_blocks(&self) -> watch::Receiver<Option<(u32, ton_block::Block)>> {
self.key_block.subscribe()
}

pub fn update_key_block(&self, block: &ton_block::Block) {
self.key_block.send_replace(Some(block.clone()));
pub fn update_key_block(&self, seqno: u32, block: &ton_block::Block) {
self.key_block.send_replace(Some((seqno, block.clone())));
}

pub fn update_contract_states(
Expand Down

0 comments on commit c65a1fd

Please sign in to comment.