Skip to content

Commit

Permalink
Merge pull request #51 from tonlabs/master-RC
Browse files Browse the repository at this point in the history
Automatic update project. #none
  • Loading branch information
tonjen authored Sep 25, 2021
2 parents 2df360c + de1df46 commit e723300
Show file tree
Hide file tree
Showing 21 changed files with 380 additions and 372 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
edition = "2018"
build = "build.rs"
name = "ton_block"
version = "1.7.24"
version = "1.7.26"

[target.'cfg(target_arch = "wasm32")'.dependencies]
clear_on_drop = { version = "0.2", features = ["no_cc"] }
Expand Down
9 changes: 7 additions & 2 deletions src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ impl fmt::Display for AccountStorage {
/// account_something_new$001 = AccountState;
///
#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug, Eq, PartialEq)]
enum AccountState {
AccountUninit,
Expand Down Expand Up @@ -1026,7 +1027,9 @@ impl Account {
}
/// setting due payment
pub fn set_due_payment(&mut self, due_payment: Option<Grams>) {
self.stuff_mut().map(|s| s.storage_stat.due_payment = due_payment);
if let Some(stuff) = self.stuff_mut() {
stuff.storage_stat.due_payment = due_payment
}
}

/// getting balance of the account
Expand All @@ -1039,7 +1042,9 @@ impl Account {

/// setting balance of the account
pub fn set_balance(&mut self, balance: CurrencyCollection) {
self.stuff_mut().map(|s| s.storage.balance = balance);
if let Some(stuff) = self.stuff_mut() {
stuff.storage.balance = balance
}
}

/// adding funds to account (for example, for credit phase transaction)
Expand Down
14 changes: 7 additions & 7 deletions src/bintree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait BinTreeType<X: Default + Serializable + Deserializable> {
}
}
if key.is_empty() {
X::construct_from(&mut cursor).map(|x| Some(x))
Ok(Some(X::construct_from(&mut cursor)?))
} else {
Ok(None)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ where F: FnOnce(X, X) -> Result<X>, X: Default + Serializable + Deserializable
fn internal_split<X, F>(data: &SliceData, mut key: SliceData, splitter: F) -> Result<Option<BuilderData>>
where F: FnOnce(X) -> Result<(X, X)>, X: Default + Serializable + Deserializable
{
if data.remaining_bits() == 1 && data.get_bits(0, 1)? == 1 { // bt_fork$1 {X:Type} left:^(BinTree X) right:^(BinTree X)
if data.remaining_bits() == 1 && data.get_bit(0)? { // bt_fork$1 {X:Type} left:^(BinTree X) right:^(BinTree X)
if data.remaining_references() < 2 {
return Ok(None)
}
Expand Down Expand Up @@ -139,7 +139,7 @@ where F: FnOnce(X) -> Result<(X, X)>, X: Default + Serializable + Deserializable
fn internal_update<X, F>(data: &SliceData, mut key: SliceData, mutator: F) -> Result<Option<BuilderData>>
where F: FnOnce(X) -> Result<X>, X: Default + Serializable + Deserializable
{
if data.remaining_bits() == 1 && data.get_bits(0, 1)? == 1 { // bt_fork$1 {X:Type} left:^(BinTree X) right:^(BinTree X)
if data.remaining_bits() == 1 && data.get_bit(0)? { // bt_fork$1 {X:Type} left:^(BinTree X) right:^(BinTree X)
if data.remaining_references() < 2 {
return Ok(None)
}
Expand Down Expand Up @@ -203,16 +203,16 @@ where
let left = X::construct_from(cursor)?;
match sibling {
Some(cell) => {
let mut cursor = SliceData::from(cell.clone());
let mut cursor = SliceData::from(cell);
if cursor.get_next_bit()? {
func(key.clone(), left, None)?
func(key, left, None)?
} else if check_sibling {
func(key, left, Some(X::construct_from(&mut cursor)?))?
} else {
true
}
}
None => func(key.clone(), left, None)?
None => func(key, left, None)?
}
};
Ok(result)
Expand Down Expand Up @@ -362,7 +362,7 @@ impl<X: Default + Serializable + Deserializable, Y: Augmentable> BinTreeAug<X, Y
}
if key.is_empty() {
X::skip(&mut cursor)?;
Y::construct_from(&mut cursor).map(|extra| Some(extra))
Ok(Some(Y::construct_from(&mut cursor)?))
} else {
Ok(None)
}
Expand Down
18 changes: 9 additions & 9 deletions src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,9 @@ impl Block {
let mut data = [0_u8; Self::DATA_FOR_SIGN_SIZE];
{
let mut cur = Cursor::new(&mut data[..]);
cur.write(&Self::DATA_FOR_SIGN_TAG).unwrap();
cur.write(root_hash.as_slice()).unwrap();
cur.write(file_hash.as_slice()).unwrap();
cur.write_all(&Self::DATA_FOR_SIGN_TAG).unwrap();
cur.write_all(root_hash.as_slice()).unwrap();
cur.write_all(file_hash.as_slice()).unwrap();
}
data
}
Expand Down Expand Up @@ -1043,14 +1043,14 @@ impl Deserializable for ValueFlow {
}
)
}
let ref mut cell1 = cell.checked_drain_reference()?.into();
let cell1 = &mut cell.checked_drain_reference()?.into();
self.from_prev_blk.read_from(cell1)?;
self.to_next_blk.read_from(cell1)?;
self.imported.read_from(cell1)?;
self.exported.read_from(cell1)?;
self.fees_collected.read_from(cell)?;

let ref mut cell2 = cell.checked_drain_reference()?.into();
let cell2 = &mut cell.checked_drain_reference()?.into();
self.fees_imported.read_from(cell2)?;
self.recovered.read_from(cell2)?;
self.created.read_from(cell2)?;
Expand Down Expand Up @@ -1258,7 +1258,7 @@ impl Deserializable for TopBlockDescr {
self.proof_for.read_from(slice)?;
self.signatures = BlockSignatures::read_maybe_from(slice)?;
let len = slice.get_next_int(8)?;
if !(len >= 1 && len <= 8) {
if !(1..=8).contains(&len) {
fail!(
BlockError::InvalidData(
"Failed check: `len >= 1 && len <= 8`".to_string()
Expand All @@ -1271,7 +1271,7 @@ impl Deserializable for TopBlockDescr {
if slice.remaining_references() == 0 {
fail!(BlockError::TvmException(ExceptionCode::CellUnderflow))
}
self.chain.push(slice.checked_drain_reference()?.clone());
self.chain.push(slice.checked_drain_reference()?);
if i != 0 {
if slice.remaining_references() == 0 {
fail!(BlockError::TvmException(ExceptionCode::CellUnderflow))
Expand All @@ -1296,14 +1296,14 @@ pub struct TopBlockDescrSet {
impl TopBlockDescrSet {
pub fn get_top_block_descr(&self, shard: &ShardIdent) -> Result<Option<TopBlockDescr>> {
match self.collection.0.get(shard.full_key_with_tag()?)? {
Some(slice) => TopBlockDescr::construct_from_cell(slice.reference(0)?).map(|r| Some(r)),
Some(slice) => TopBlockDescr::construct_from_cell(slice.reference(0)?).map(Some),
None => Ok(None)
}
}
pub fn insert(&mut self, shard: &ShardIdent, descr: &TopBlockDescr) -> Result<()> {
let key = shard.full_key_with_tag()?;
let value = descr.serialize()?;
self.collection.0.setref(key, &value.into()).map(|_|())
self.collection.0.setref(key, &value).map(|_|())
}
pub fn is_empty(&self) -> bool {
self.collection.is_empty()
Expand Down
13 changes: 10 additions & 3 deletions src/config_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ impl ConfigParams {
_ => fail!("no elector params in config")
}
}
pub fn validators_count(&self) -> Result<ConfigParam16> {
match self.config(16)? {
Some(ConfigParamEnum::ConfigParam16(param)) => Ok(param),
_ => fail!("no elector params in config")
}
}
// TODO 16 validators count
// TODO 17 stakes config
pub fn storage_prices(&self) -> Result<ConfigParam18> {
Expand Down Expand Up @@ -317,6 +323,7 @@ pub enum GlobalCapabilities {
CapMbppEnabled = 64,
CapFastStorageStat = 128,
CapInitCodeHash = 256,
CapOffHypercube = 512,
}

impl ConfigParams {
Expand Down Expand Up @@ -2709,13 +2716,13 @@ impl ConfigParam39 {
pub fn get(&self, key: &UInt256) -> Result<ValidatorSignedTempKey> {
self
.validator_keys
.get(key)
.and_then(|vtk| vtk.ok_or_else(|| error!(BlockError::InvalidArg(key.to_hex_string()))))
.get(key)?
.ok_or_else(|| error!(BlockError::InvalidArg(format!("{:x}", key))))
}

/// insert value
pub fn insert(&mut self, key: &UInt256, validator_key: &ValidatorSignedTempKey) -> Result<()> {
self.validator_keys.set(key, &validator_key)
self.validator_keys.set(key, validator_key)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/envelope_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,13 @@ impl MsgEnvelope {
/// is message route in one workchain
pub fn same_workchain(&self) -> Result<bool> {
let msg = self.read_message()?;
debug_assert!(msg.is_internal(), "Message with hash {} is not internal",
self.message_cell().repr_hash().to_hex_string());
debug_assert!(msg.is_internal(), "Message with hash {:x} is not internal",
self.message_cell().repr_hash());
if let (Some(src), Some(dst)) = (msg.src_ref(), msg.dst_ref()) {
return Ok(src.get_workchain_id() == dst.get_workchain_id())
}
fail!("Message with hash {} has wrong type of src/dst address",
self.message_cell().repr_hash().to_hex_string())
fail!("Message with hash {:x} has wrong type of src/dst address",
self.message_cell().repr_hash())
}
}

Expand Down
83 changes: 39 additions & 44 deletions src/hashmapaug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use ton_types::{
error, fail, Result, IBitstring, BuilderData, Cell, SliceData,
ExceptionCode, HashmapType, Leaf, HashmapFilterResult, HashmapRemover,
};
use std::cmp::Ordering;

/// trait for types used as Augment to calc aug on forks
pub trait Augmentable: Clone + Default + Serializable + Deserializable {
Expand Down Expand Up @@ -70,29 +71,16 @@ macro_rules! define_HashmapAugE {
/// Constructs new HashmapAugE for bit_len keys
pub fn new() -> Self {
Self {
extra: Default::default(),
extra: <$y_type>::default(),
bit_len: $bit_len,
data: None,
}
}
/// Deserialization from SliceData - just clone and set window
pub fn with_data(slice: &mut SliceData) -> Result<Self> {
let data = match slice.get_next_bit()? {
true => Some(slice.checked_drain_reference()?),
false => None
};
let extra = <$y_type>::construct_from(slice)?;
Ok(Self {
extra,
bit_len: $bit_len,
data
})
}
/// Constructs from cell, extracts total aug
pub fn with_hashmap(data: Option<Cell>) -> Result<Self> {
let extra = match data {
Some(ref root) => Self::find_extra(&mut root.into(), $bit_len)?,
None => Default::default()
None => <$y_type>::default()
};
Ok(Self {
extra,
Expand Down Expand Up @@ -208,7 +196,7 @@ macro_rules! define_HashmapAugE {
impl Default for $varname {
fn default() -> Self {
Self {
extra: Default::default(),
extra: <$y_type>::default(),
bit_len: $bit_len,
data: None
}
Expand All @@ -229,9 +217,17 @@ macro_rules! define_HashmapAugE {
}

impl Deserializable for $varname {
fn read_from(&mut self, slice: &mut SliceData) -> Result<()>{
*self = $varname::with_data(slice)?;
Ok(())
fn construct_from(slice: &mut SliceData) -> Result<Self>{
let data = match slice.get_next_bit()? {
true => Some(slice.checked_drain_reference()?),
false => None
};
let extra = <$y_type>::construct_from(slice)?;
Ok(Self {
extra,
bit_len: $bit_len,
data
})
}
}

Expand All @@ -252,7 +248,7 @@ pub trait HashmapAugType<K: Deserializable + Serializable, X: Deserializable + S
fn update_root_extra(&mut self) -> Result<&Y> {
let aug = match self.data() {
Some(root) => Self::find_extra(&mut SliceData::from(root), self.bit_len())?,
None => Default::default()
None => Y::default(),
};
self.set_root_extra(aug);
Ok(self.root_extra())
Expand Down Expand Up @@ -698,39 +694,38 @@ pub trait HashmapAugType<K: Deserializable + Serializable, X: Deserializable + S
where F: FnMut(&[u8], usize, SliceData) -> Result<crate::hashmapaug::TraverseNextStep<R>> {
let label = cursor.get_label(bit_len)?;
let label_length = label.remaining_bits();
if label_length < bit_len {
bit_len -= label_length + 1;
match label_length.cmp(&bit_len) {
Ordering::Less => {
bit_len -= label_length + 1;

let mut aug = cursor.clone();
aug.checked_drain_reference()?;
aug.checked_drain_reference()?;
key.checked_append_references_and_data(&label)?;
let to_visit = match callback(key.data(), key.length_in_bits(), aug)? {
TraverseNextStep::Stop => return Ok(None),
TraverseNextStep::End(r) => return Ok(Some(r)),
TraverseNextStep::VisitZero => [Some(0), None],
TraverseNextStep::VisitOne => [Some(1), None],
TraverseNextStep::VisitZeroOne => [Some(0), Some(1)],
TraverseNextStep::VisitOneZero => [Some(1), Some(0)],
};
for i in to_visit.iter() {
if let Some(i) = i {
let mut aug = cursor.clone();
aug.checked_drain_reference()?;
aug.checked_drain_reference()?;
key.checked_append_references_and_data(&label)?;
let to_visit = match callback(key.data(), key.length_in_bits(), aug)? {
TraverseNextStep::Stop => return Ok(None),
TraverseNextStep::End(r) => return Ok(Some(r)),
TraverseNextStep::VisitZero => [Some(0), None],
TraverseNextStep::VisitOne => [Some(1), None],
TraverseNextStep::VisitZeroOne => [Some(0), Some(1)],
TraverseNextStep::VisitOneZero => [Some(1), Some(0)],
};
for i in to_visit.iter().flatten() {
let mut key = key.clone();
key.append_bit_bool(*i != 0)?;
let ref mut child = SliceData::from(cursor.reference(*i)?);
let child = &mut SliceData::from(cursor.reference(*i)?);
if let Some(r) = Self::traverse_internal(child, key, bit_len, callback)? {
return Ok(Some(r))
}
}
}
} else if label_length == bit_len {
key.checked_append_references_and_data(&label)?;
return match callback(key.data(), key.length_in_bits(), cursor.clone())? {
TraverseNextStep::End(r) => Ok(Some(r)),
_ => Ok(None),
Ordering::Equal => {
key.checked_append_references_and_data(&label)?;
if let TraverseNextStep::End(r) = callback(key.data(), key.length_in_bits(), cursor.clone())? {
return Ok(Some(r))
}
}
} else {
fail!(BlockError::InvalidData("label_length > bit_len".to_string()))
_ => fail!(BlockError::InvalidData("label_length > bit_len".to_string()))
}
Ok(None)
}
Expand Down
Loading

0 comments on commit e723300

Please sign in to comment.