@@ -271,7 +271,7 @@ bool Account::recompute_tmp_addr(Ref<vm::CellSlice>& tmp_addr, int split_depth,
271271}
272272
273273bool Account::init_rewrite_addr (int split_depth, td::ConstBitPtr orig_addr_rewrite) {
274- if (split_depth_set_ || !created || ! set_split_depth (split_depth)) {
274+ if (split_depth_set_ || !set_split_depth (split_depth)) {
275275 return false ;
276276 }
277277 addr_orig = addr;
@@ -304,15 +304,8 @@ bool Account::unpack(Ref<vm::CellSlice> shard_account, Ref<vm::CellSlice> extra,
304304 total_state = orig_total_state = account;
305305 auto acc_cs = load_cell_slice (std::move (account));
306306 if (block::gen::t_Account.get_tag (acc_cs) == block::gen::Account::account_none) {
307- status = acc_nonexist;
308- last_paid = 0 ;
309- last_trans_end_lt_ = 0 ;
310307 is_special = special;
311- if (workchain != ton::workchainInvalid) {
312- addr_orig = addr;
313- addr_rewrite = addr.cbits ();
314- }
315- return compute_my_addr () && acc_cs.size_ext () == 1 ;
308+ return acc_cs.size_ext () == 1 && init_new (now);
316309 }
317310 block::gen::Account::Record_account acc;
318311 block::gen::AccountStorage::Record storage;
@@ -328,6 +321,7 @@ bool Account::unpack(Ref<vm::CellSlice> shard_account, Ref<vm::CellSlice> extra,
328321 case block::gen::AccountState::account_uninit:
329322 status = orig_status = acc_uninit;
330323 state_hash = addr;
324+ forget_split_depth ();
331325 break ;
332326 case block::gen::AccountState::account_frozen:
333327 status = orig_status = acc_frozen;
@@ -396,10 +390,42 @@ bool Account::init_new(ton::UnixTime now) {
396390 state_hash = addr_orig;
397391 status = orig_status = acc_nonexist;
398392 split_depth_set_ = false ;
399- created = true ;
400393 return true ;
401394}
402395
396+ bool Account::forget_split_depth () {
397+ split_depth_set_ = false ;
398+ split_depth_ = 0 ;
399+ addr_orig = addr;
400+ my_addr = my_addr_exact;
401+ addr_rewrite = addr.bits ();
402+ return true ;
403+ }
404+
405+ bool Account::deactivate () {
406+ if (status == acc_active) {
407+ return false ;
408+ }
409+ // forget special (tick/tock) info
410+ tick = tock = false ;
411+ if (status == acc_nonexist || status == acc_uninit) {
412+ // forget split depth and address rewriting info
413+ forget_split_depth ();
414+ // forget specific state hash for deleted or uninitialized accounts (revert to addr)
415+ state_hash = addr;
416+ }
417+ // forget code and data (only active accounts remember these)
418+ code.clear ();
419+ data.clear ();
420+ library.clear ();
421+ // if deleted, balance must be zero
422+ if (status == acc_nonexist && !balance.is_zero ()) {
423+ return false ;
424+ }
425+ return true ;
426+ }
427+
428+
403429bool Account::belongs_to_shard (ton::ShardIdFull shard) const {
404430 return workchain == shard.workchain && ton::shard_is_ancestor (shard.shard , addr);
405431}
@@ -2214,7 +2240,7 @@ Ref<vm::Cell> Transaction::commit(Account& acc) {
22142240 CHECK ((const void *)&acc == (const void *)&account);
22152241 // export all fields modified by the Transaction into original account
22162242 // NB: this is the only method that modifies account
2217- if (orig_addr_rewrite_set && new_split_depth >= 0 && acc.status == Account::acc_nonexist &&
2243+ if (orig_addr_rewrite_set && new_split_depth >= 0 && acc.status != Account::acc_active &&
22182244 acc_status == Account::acc_active) {
22192245 LOG (DEBUG) << " setting address rewriting info for newly-activated account " << acc.addr .to_hex ()
22202246 << " with split_depth=" << new_split_depth
@@ -2243,9 +2269,7 @@ Ref<vm::Cell> Transaction::commit(Account& acc) {
22432269 acc.tick = new_tick;
22442270 acc.tock = new_tock;
22452271 } else {
2246- acc.tick = acc.tock = false ;
2247- acc.split_depth_set_ = false ;
2248- acc.created = true ;
2272+ CHECK (acc.deactivate ());
22492273 }
22502274 end_lt = 0 ;
22512275 acc.push_transaction (root, start_lt);
0 commit comments