Skip to content

Commit

Permalink
feat: add out msg queue for tycho block new struct
Browse files Browse the repository at this point in the history
  • Loading branch information
serejkaaa512 committed Aug 15, 2024
1 parent 0c88092 commit 5053f18
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/models/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ pub struct Block {
/// Merkle update for the shard state.
pub state_update: Lazy<MerkleUpdate>,
/// Merkle updates for the outgoing messages queue.
#[cfg(not(feature = "tycho"))]
pub out_msg_queue_updates: Option<Dict<u32, Lazy<MerkleUpdate>>>,
/// Processed upto and diff hash queue msg update
#[cfg(feature = "tycho")]
pub out_msg_queue_updates: Option<MsgQueueUpdates>,
/// Block content.
pub extra: Lazy<BlockExtra>,
}
Expand Down Expand Up @@ -128,11 +132,15 @@ impl<'a> Load<'a> for Block {
let global_id = ok!(slice.load_u32()) as i32;
let info = ok!(Lazy::load_from(slice));
let value_flow = ok!(Lazy::load_from(slice));

let (state_update, out_msg_queue_updates) = if with_out_msg_queue_updates {
let slice = &mut ok!(slice.load_reference_as_slice());
(
ok!(Lazy::load_from(slice)),
#[cfg(not(feature = "tycho"))]
Some(ok!(Dict::load_from(slice))),
#[cfg(feature = "tycho")]
Some(ok!(MsgQueueUpdates::load_from(slice))),
)
} else {
(ok!(Lazy::load_from(slice)), None)
Expand Down Expand Up @@ -669,3 +677,14 @@ impl<'a> Load<'a> for ValueFlow {
})
}
}

#[cfg(any(feature = "venom", feature = "tycho"))]
/// Message queue updates
#[derive(Debug, Clone, Eq, PartialEq, Store, Load)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct MsgQueueUpdates {
/// Diff hash
pub diff_hash: HashBytes,
/// Processed up to
pub processed_to: Dict<ShardIdentFull, (u64, HashBytes)>,
}
Binary file not shown.
138 changes: 137 additions & 1 deletion src/models/block/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::HashMap;

use super::*;
use crate::prelude::*;
use crate::{
models::{ExtraCurrencyCollection, GlobalCapabilities},
prelude::*,
};

fn serialize_any<T: Store>(data: T) -> Cell {
CellBuilder::build_from(data).unwrap()
Expand Down Expand Up @@ -351,3 +354,136 @@ fn proof_for_shardchain_block() {

assert_eq!(serialize_any(proof).as_ref(), boc.as_ref());
}

#[test]
#[cfg(feature = "tycho")]
fn block_with_tycho_updates_store_load() {
let block = Block {
global_id: 42,
info: Lazy::new(&BlockInfo {
version: 0,
gen_utime_ms: 123,
after_merge: false,
before_split: false,
after_split: false,
want_split: false,
want_merge: true,
key_block: false,
flags: 1,
seqno: 24721433,
vert_seqno: 0,
shard: ShardIdent::new(-1, 0x8000000000000000).unwrap(),
gen_utime: 1674507085,
start_lt: 34671157000000,
end_lt: 34671157000005,
gen_validator_list_hash_short: 3236125243,
gen_catchain_seqno: 343054,
min_ref_mc_seqno: 24721430,
prev_key_block_seqno: 24715347,
gen_software: GlobalVersion {
version: 34,
capabilities: GlobalCapabilities::new(464814),
},
master_ref: None,
prev_ref: Cell::empty_cell(),
prev_vert_ref: None,
})
.unwrap(),
value_flow: Lazy::new(&ValueFlow {
from_prev_block: CurrencyCollection {
tokens: Tokens::new(3610625966274374005),
other: ExtraCurrencyCollection::new(),
},
to_next_block: CurrencyCollection {
tokens: Tokens::new(3610625969470214036),
other: ExtraCurrencyCollection::new(),
},
imported: CurrencyCollection {
tokens: Tokens::new(0),
other: ExtraCurrencyCollection::new(),
},
exported: CurrencyCollection {
tokens: Tokens::new(0),
other: ExtraCurrencyCollection::new(),
},
fees_collected: CurrencyCollection {
tokens: Tokens::new(3195840031),
other: ExtraCurrencyCollection::new(),
},
fees_imported: CurrencyCollection {
tokens: Tokens::new(1495840031),
other: ExtraCurrencyCollection::new(),
},
recovered: CurrencyCollection {
tokens: Tokens::new(3195840031),
other: ExtraCurrencyCollection::new(),
},
created: CurrencyCollection {
tokens: Tokens::new(1700000000),
other: ExtraCurrencyCollection::new(),
},
minted: CurrencyCollection {
tokens: Tokens::new(0),
other: ExtraCurrencyCollection::new(),
},
copyleft_rewards: Dict::new(),
})
.unwrap(),
state_update: Lazy::new(&MerkleUpdate {
old_hash: HashBytes::ZERO,
new_hash: HashBytes::ZERO,
old_depth: 182,
new_depth: 182,
old: Cell::empty_cell(),
new: Cell::empty_cell(),
})
.unwrap(),
extra: Lazy::new(&BlockExtra {
in_msg_description: Lazy::new(&AugDict::new()).unwrap(),
out_msg_description: Lazy::new(&AugDict::new()).unwrap(),
account_blocks: Lazy::new(&AugDict::new()).unwrap(),
rand_seed: HashBytes::ZERO,
created_by: HashBytes::ZERO,
custom: None,
})
.unwrap(),
out_msg_queue_updates: Some(MsgQueueUpdates {
diff_hash: HashBytes::ZERO,
processed_to: {
let mut dict = Dict::new();
dict.add(
ShardIdentFull {
workchain: -1,
prefix: 0x8000000000000000,
},
(12345, HashBytes::ZERO),
)
.unwrap();
dict
},
}),
};
let encoded = BocRepr::encode(&block).unwrap();

let cell: Cell = Boc::decode(&*encoded).unwrap();
assert_eq!(
Block::load_from(&mut cell.as_slice().unwrap())
.unwrap()
.out_msg_queue_updates,
Some(MsgQueueUpdates {
diff_hash: HashBytes::ZERO,
processed_to: {
let mut dict = Dict::new();
dict.add(
ShardIdentFull {
workchain: -1,
prefix: 0x8000000000000000,
},
(12345, HashBytes::ZERO),
)
.unwrap();
dict
},
})
);
}

0 comments on commit 5053f18

Please sign in to comment.