Skip to content

Commit

Permalink
delete some flags from reserve (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeHor05 authored Dec 23, 2024
1 parent 8360c45 commit 8e9b7db
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 83 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [2.3.3] – 2024-12-18

### New
- Delete some flags from RawReserve instruction

## [2.3.2] – 2024-12-18

### Fixed
Expand Down
42 changes: 21 additions & 21 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ members = [
"tvm_tests"
]
[workspace.package]
version = "2.3.2"
version = "2.3.3"

rust-version = "1.76.0"

Expand Down
5 changes: 0 additions & 5 deletions tvm_block/src/out_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ pub const SENDMSG_VALID_FLAGS: u8 = SENDMSG_ORDINARY
/// variants of reserve action
pub const RESERVE_EXACTLY: u8 = 0;
pub const RESERVE_ALL_BUT: u8 = 1;
pub const RESERVE_IGNORE_ERROR: u8 = 2;
pub const RESERVE_PLUS_ORIG: u8 = 4;
pub const RESERVE_REVERSE: u8 = 8;
pub const RESERVE_VALID_MODES: u8 =
RESERVE_EXACTLY | RESERVE_ALL_BUT | RESERVE_IGNORE_ERROR | RESERVE_PLUS_ORIG | RESERVE_REVERSE;

pub const CHANGE_LIB_REMOVE: u8 = 0;
pub const SET_LIB_CODE_REMOVE: u8 = 1;
Expand Down
9 changes: 5 additions & 4 deletions tvm_executor/src/ordinary_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,15 @@ impl TransactionExecutor for OrdinaryTransactionExecutor {
log::debug!(target: "executor", "action_phase: lt={}", lt);
action_phase_processed = true;

let message_src_dapp_id = if let Some(AccountState::AccountActive { state_init: _ }) = account.state() {
let message_src_dapp_id = if let Some(AccountState::AccountActive {
state_init: _,
}) = account.state()
{
if !is_previous_state_active {
if in_msg.int_header().is_some() {
params.src_dapp_id.clone()
} else {
Some(
account.get_id().unwrap().get_bytestring(0).as_slice().into(),
)
Some(account.get_id().unwrap().get_bytestring(0).as_slice().into())
}
} else {
account.get_dapp_id().cloned().unwrap()
Expand Down
66 changes: 14 additions & 52 deletions tvm_executor/src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ use tvm_block::MsgAddressInt;
use tvm_block::OutAction;
use tvm_block::OutActions;
use tvm_block::RESERVE_ALL_BUT;
use tvm_block::RESERVE_IGNORE_ERROR;
use tvm_block::RESERVE_PLUS_ORIG;
use tvm_block::RESERVE_REVERSE;
use tvm_block::RESERVE_VALID_MODES;
use tvm_block::SENDMSG_ALL_BALANCE;
use tvm_block::SENDMSG_DELETE_IF_EMPTY;
use tvm_block::SENDMSG_IGNORE_ERROR;
Expand Down Expand Up @@ -784,8 +780,6 @@ pub trait TransactionExecutor {
my_addr,
&total_reserved_value,
&mut account_deleted,
need_to_reserve,
need_to_burn,
);
match result {
Ok(_) => {
Expand All @@ -801,7 +795,6 @@ pub trait TransactionExecutor {
match reserve_action_handler(
mode,
&mut value,
original_acc_balance,
&mut acc_remaining_balance,
&mut need_to_reserve,
) {
Expand Down Expand Up @@ -944,8 +937,6 @@ pub trait TransactionExecutor {
my_addr,
&total_reserved_value,
&mut account_deleted,
need_to_reserve,
need_to_burn,
);
if need_to_reserve != 0 {
free_to_send.grams.add(&Grams::from(need_to_reserve))?;
Expand Down Expand Up @@ -1450,8 +1441,6 @@ fn outmsg_action_handler(
my_addr: &MsgAddressInt,
reserved_value: &CurrencyCollection,
account_deleted: &mut bool,
need_to_reserve: u64,
need_to_burn: u64,
) -> std::result::Result<CurrencyCollection, i32> {
// we cannot send all balance from account and from message simultaneously ?
let invalid_flags = SENDMSG_REMAINING_MSG_BALANCE | SENDMSG_ALL_BALANCE;
Expand Down Expand Up @@ -1527,16 +1516,16 @@ fn outmsg_action_handler(
if (mode & SENDMSG_ALL_BALANCE) != 0 {
// send all remaining account balance
result_value = acc_balance.clone();
/* if need_to_reserve != 0 {
match result_value.grams.sub(&Grams::from(need_to_burn)) {
Ok(true) => (),
Ok(false) => {
result_value.grams = Grams::zero();
return Err(skip.map(|_| RESULT_CODE_NOT_ENOUGH_GRAMS).unwrap_or_default());
}
Err(_) => return Err(RESULT_CODE_UNSUPPORTED),
}
}*/
// if need_to_reserve != 0 {
// match result_value.grams.sub(&Grams::from(need_to_burn)) {
// Ok(true) => (),
// Ok(false) => {
// result_value.grams = Grams::zero();
// return Err(skip.map(|_| RESULT_CODE_NOT_ENOUGH_GRAMS).unwrap_or_default());
// }
// Err(_) => return Err(RESULT_CODE_UNSUPPORTED),
// }
// }
int_header.value = result_value.clone();

mode &= !SENDMSG_PAY_FEE_SEPARATELY;
Expand Down Expand Up @@ -1663,10 +1652,12 @@ fn outmsg_action_handler(
fn reserve_action_handler(
mode: u8,
val: &mut CurrencyCollection,
original_acc_balance: &CurrencyCollection,
acc_remaining_balance: &mut CurrencyCollection,
need_to_reserve: &mut u64,
) -> std::result::Result<CurrencyCollection, i32> {
if mode > RESERVE_ALL_BUT {
return Err(RESULT_CODE_UNKNOWN_OR_INVALID_ACTION);
}
if mode & RESERVE_ALL_BUT == 0 {
if *need_to_reserve != 0 {
match val.grams.add(&Grams::from(*need_to_reserve)) {
Expand All @@ -1684,38 +1675,9 @@ fn reserve_action_handler(
*need_to_reserve = 0;
}
}
if mode & !RESERVE_VALID_MODES != 0 {
return Err(RESULT_CODE_UNKNOWN_OR_INVALID_ACTION);
}
log::debug!(target: "executor", "Reserve with mode = {} value = {}", mode, balance_to_string(val));

let mut reserved;
if mode & RESERVE_PLUS_ORIG != 0 {
// Append all currencies
if mode & RESERVE_REVERSE != 0 {
reserved = original_acc_balance.clone();
let result = reserved.sub(val);
match result {
Err(_) => return Err(RESULT_CODE_INVALID_BALANCE),
Ok(false) => return Err(RESULT_CODE_UNSUPPORTED),
Ok(true) => (),
}
} else {
reserved = val.clone();
reserved.add(original_acc_balance).or(Err(RESULT_CODE_INVALID_BALANCE))?;
}
} else {
if mode & RESERVE_REVERSE != 0 {
// flag 8 without flag 4 unacceptable
return Err(RESULT_CODE_UNKNOWN_OR_INVALID_ACTION);
}
reserved = val.clone();
}
if mode & RESERVE_IGNORE_ERROR != 0 {
// Only grams
reserved.grams = min(reserved.grams, acc_remaining_balance.grams);
}

let mut reserved = val.clone();
let mut remaining = acc_remaining_balance.clone();
if remaining.grams.as_u128() < reserved.grams.as_u128() {
return Err(RESULT_CODE_NOT_ENOUGH_GRAMS);
Expand Down

0 comments on commit 8e9b7db

Please sign in to comment.