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 6, 2024
1 parent c8a19c0 commit 0eb0161
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 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.

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
4 changes: 2 additions & 2 deletions server/src/jrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl JrpcServer {
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)?;
let (key_block, config) = serialize_block(&block.1)?;
(
Arc::new(ArcSwapOption::new(Some(key_block))),
Arc::new(ArcSwapOption::new(Some(config))),
Expand All @@ -97,7 +97,7 @@ impl JrpcServer {
let data = key_block_rx
.borrow_and_update()
.as_ref()
.map(serialize_block);
.map(|(_, block)| serialize_block(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 0eb0161

Please sign in to comment.