Skip to content

Commit 77e5a2f

Browse files
committed
Merge branch 'testnet' into tvm-v9
2 parents d3485e4 + 710514b commit 77e5a2f

24 files changed

+169
-76
lines changed

Changelog.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Besides the work of the core team, this update is based on the efforts of @krigg
3131
## 2024.08 Update
3232

3333
1. Introduction of dispatch queues, message envelopes with transaction chain metadata, and explicitly stored msg_queue size, which will be activated by `Config8.version >= 8` and new `Config8.capabilities` bits: `capStoreOutMsgQueueSize`, `capMsgMetadata`, `capDeferMessages`.
34-
2. A number of changes to transcation executor which will activated for `Config8.version >= 8`:
34+
2. A number of changes to transaction executor which will activated for `Config8.version >= 8`:
3535
- Check mode on invalid `action_send_msg`. Ignore action if `IGNORE_ERROR` (+2) bit is set, bounce if `BOUNCE_ON_FAIL` (+16) bit is set.
3636
- Slightly change random seed generation to fix mix of `addr_rewrite` and `addr`.
3737
- Fill in `skipped_actions` for both invalid and valid messages with `IGNORE_ERROR` mode that can't be sent.
@@ -103,7 +103,7 @@ Besides the work of the core team, this update is based on the efforts of @akifo
103103
* Fix error in proof generation for blocks after merge
104104
* Fix most of `block is not applied` issues related to sending too recent block in Proofs
105105
* LS now check external messages till `accept_message` (`set_gas`).
106-
3. Improvements in DHT work and storage, CellDb, config.json ammendment, peer misbehavior detection, validator session stats collection, emulator.
106+
3. Improvements in DHT work and storage, CellDb, config.json amendment, peer misbehavior detection, validator session stats collection, emulator.
107107
4. Change in CTOS and XLOAD behavior activated through setting `version >= 5` in `ConfigParam 8;`:
108108
* Loading "nested libraries" (i.e. a library cell that points to another library cell) throws an exception.
109109
* Loading a library consumes gas for cell load only once (for the library cell), not twice (both for the library cell and the cell in the library).
@@ -114,7 +114,7 @@ Besides the work of the Core team, this update is based on the efforts of @XaBbl
114114
## 2023.12 Update
115115

116116
1. Optimized message queue handling, now queue cleaning speed doesn't depend on total queue size
117-
* Cleaning delivered messages using lt augmentation instead of random search / consequtive walk
117+
* Cleaning delivered messages using lt augmentation instead of random search / consecutive walk
118118
* Keeping root cell of queue message in memory until outdated (caching)
119119
2. Changes to block collation/validation limits
120120
3. Stop accepting new external message if message queue is overloaded
@@ -206,7 +206,7 @@ Besides the work of the core team, this update is based on the efforts of @vtama
206206
Besides the work of the core team, this update is based on the efforts of @tvorogme (debug improvements), @AlexeyFSL (WASM builds) and third-party security auditors.
207207

208208
## 2022.08 Update
209-
* Blockchain state serialization now works via separate db-handler which simplfies memory clearing after serialization
209+
* Blockchain state serialization now works via separate db-handler which simplifies memory clearing after serialization
210210
* CellDB now works asynchronously which substantially increase database access throughput
211211
* Abseil-cpp and crc32 updated: solve issues with compilation on recent OS distributives
212212
* Fixed a series of UBs and issues for exotic endianness hosts

adnl/adnl-peer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void AdnlPeerPairImpl::discover() {
119119
void AdnlPeerPairImpl::receive_packet_checked(AdnlPacket packet) {
120120
last_received_packet_ = td::Timestamp::now();
121121
try_reinit_at_ = td::Timestamp::never();
122+
drop_addr_list_at_ = td::Timestamp::never();
122123
request_reverse_ping_after_ = td::Timestamp::in(15.0);
123124
auto d = Adnl::adnl_start_time();
124125
if (packet.dst_reinit_date() > d) {
@@ -415,6 +416,9 @@ void AdnlPeerPairImpl::send_packet_continue(AdnlPacket packet, td::actor::ActorI
415416
if (!try_reinit_at_ && last_received_packet_ < td::Timestamp::in(-5.0)) {
416417
try_reinit_at_ = td::Timestamp::in(10.0);
417418
}
419+
if (!drop_addr_list_at_ && last_received_packet_ < td::Timestamp::in(-60.0 * 9.0)) {
420+
drop_addr_list_at_ = td::Timestamp::in(60.0);
421+
}
418422
packet.run_basic_checks().ensure();
419423
auto B = serialize_tl_object(packet.tl(), true);
420424
if (via_channel) {
@@ -692,6 +696,16 @@ void AdnlPeerPairImpl::reinit(td::int32 date) {
692696
}
693697

694698
td::Result<std::pair<td::actor::ActorId<AdnlNetworkConnection>, bool>> AdnlPeerPairImpl::get_conn() {
699+
if (drop_addr_list_at_ && drop_addr_list_at_.is_in_past()) {
700+
drop_addr_list_at_ = td::Timestamp::never();
701+
priority_addr_list_ = AdnlAddressList{};
702+
priority_conns_.clear();
703+
addr_list_ = AdnlAddressList{};
704+
conns_.clear();
705+
has_reverse_addr_ = false;
706+
return td::Status::Error(ErrorCode::notready, "no active connections");
707+
}
708+
695709
if (!priority_addr_list_.empty() && priority_addr_list_.expire_at() < td::Clocks::system()) {
696710
priority_addr_list_ = AdnlAddressList{};
697711
priority_conns_.clear();

adnl/adnl-peer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class AdnlPeerPairImpl : public AdnlPeerPair {
266266

267267
td::Timestamp last_received_packet_ = td::Timestamp::never();
268268
td::Timestamp try_reinit_at_ = td::Timestamp::never();
269+
td::Timestamp drop_addr_list_at_ = td::Timestamp::never();
269270

270271
bool has_reverse_addr_ = false;
271272
td::Timestamp request_reverse_ping_after_ = td::Timestamp::now();

crypto/block/block.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,36 @@ CurrencyCollection CurrencyCollection::operator-(td::RefInt256 other_grams) cons
13191319
}
13201320
}
13211321

1322+
bool CurrencyCollection::clamp(const CurrencyCollection& other) {
1323+
if (!is_valid() || !other.is_valid()) {
1324+
return invalidate();
1325+
}
1326+
grams = std::min(grams, other.grams);
1327+
vm::Dictionary dict1{extra, 32}, dict2(other.extra, 32);
1328+
bool ok = dict1.check_for_each([&](td::Ref<vm::CellSlice> cs1, td::ConstBitPtr key, int n) {
1329+
CHECK(n == 32);
1330+
td::Ref<vm::CellSlice> cs2 = dict2.lookup(key, 32);
1331+
td::RefInt256 val1 = tlb::t_VarUIntegerPos_32.as_integer(cs1);
1332+
if (val1.is_null()) {
1333+
return false;
1334+
}
1335+
td::RefInt256 val2 = cs2.is_null() ? td::zero_refint() : tlb::t_VarUIntegerPos_32.as_integer(cs2);
1336+
if (val2.is_null()) {
1337+
return false;
1338+
}
1339+
if (val1 > val2) {
1340+
if (val2->sgn() == 0) {
1341+
dict1.lookup_delete(key, 32);
1342+
} else {
1343+
dict1.set(key, 32, cs2);
1344+
}
1345+
}
1346+
return true;
1347+
});
1348+
extra = dict1.get_root_cell();
1349+
return ok || invalidate();
1350+
}
1351+
13221352
bool CurrencyCollection::operator==(const CurrencyCollection& other) const {
13231353
return is_valid() && other.is_valid() && !td::cmp(grams, other.grams) &&
13241354
(extra.not_null() == other.extra.not_null()) &&

crypto/block/block.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ struct CurrencyCollection {
390390
CurrencyCollection operator-(const CurrencyCollection& other) const;
391391
CurrencyCollection operator-(CurrencyCollection&& other) const;
392392
CurrencyCollection operator-(td::RefInt256 other_grams) const;
393+
bool clamp(const CurrencyCollection& other);
393394
bool store(vm::CellBuilder& cb) const;
394395
bool store_or_zero(vm::CellBuilder& cb) const;
395396
bool fetch(vm::CellSlice& cs);

crypto/block/block.tlb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ transaction$0111 account_addr:bits256 lt:uint64
296296
total_fees:CurrencyCollection state_update:^(HASH_UPDATE Account)
297297
description:^TransactionDescr = Transaction;
298298

299-
!merkle_update#02 {X:Type} old_hash:bits256 new_hash:bits256
299+
!merkle_update#04 {X:Type} old_hash:bits256 new_hash:bits256 old_depth:uint16 new_depth:uint16
300300
old:^X new:^X = MERKLE_UPDATE X;
301301
update_hashes#72 {X:Type} old_hash:bits256 new_hash:bits256
302302
= HASH_UPDATE X;

crypto/block/transaction.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,22 +2795,25 @@ int Transaction::try_action_reserve_currency(vm::CellSlice& cs, ActionPhase& ap,
27952795
LOG(DEBUG) << "cannot reserve a negative amount: " << reserve.to_str();
27962796
return -1;
27972797
}
2798-
if (reserve.grams > ap.remaining_balance.grams) {
2799-
if (mode & 2) {
2800-
reserve.grams = ap.remaining_balance.grams;
2798+
if (mode & 2) {
2799+
if (cfg.reserve_extra_enabled) {
2800+
if (!reserve.clamp(ap.remaining_balance)) {
2801+
LOG(DEBUG) << "failed to clamp reserve amount" << mode;
2802+
return -1;
2803+
}
28012804
} else {
2802-
LOG(DEBUG) << "cannot reserve " << reserve.grams << " nanograms : only " << ap.remaining_balance.grams
2803-
<< " available";
2804-
return 37; // not enough grams
2805+
reserve.grams = std::min(reserve.grams, ap.remaining_balance.grams);
28052806
}
28062807
}
2808+
if (reserve.grams > ap.remaining_balance.grams) {
2809+
LOG(DEBUG) << "cannot reserve " << reserve.grams << " nanograms : only " << ap.remaining_balance.grams
2810+
<< " available";
2811+
return 37; // not enough grams
2812+
}
28072813
if (!block::sub_extra_currency(ap.remaining_balance.extra, reserve.extra, newc.extra)) {
28082814
LOG(DEBUG) << "not enough extra currency to reserve: " << block::CurrencyCollection{0, reserve.extra}.to_str()
28092815
<< " required, only " << block::CurrencyCollection{0, ap.remaining_balance.extra}.to_str()
28102816
<< " available";
2811-
if (mode & 2) {
2812-
// TODO: process (mode & 2) correctly by setting res_extra := inf (reserve.extra, ap.remaining_balance.extra)
2813-
}
28142817
return 38; // not enough (extra) funds
28152818
}
28162819
newc.grams = ap.remaining_balance.grams - reserve.grams;
@@ -3813,6 +3816,7 @@ td::Status FetchConfigParams::fetch_config_params(
38133816
action_phase_cfg->bounce_on_fail_enabled = config.get_global_version() >= 4;
38143817
action_phase_cfg->message_skip_enabled = config.get_global_version() >= 8;
38153818
action_phase_cfg->disable_custom_fess = config.get_global_version() >= 8;
3819+
action_phase_cfg->reserve_extra_enabled = config.get_global_version() >= 9;
38163820
action_phase_cfg->mc_blackhole_addr = config.get_burning_config().blackhole_addr;
38173821
}
38183822
{

crypto/block/transaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct ActionPhaseConfig {
169169
bool bounce_on_fail_enabled{false};
170170
bool message_skip_enabled{false};
171171
bool disable_custom_fess{false};
172+
bool reserve_extra_enabled{false};
172173
td::optional<td::Bits256> mc_blackhole_addr;
173174
const MsgPrices& fetch_msg_prices(bool is_masterchain) const {
174175
return is_masterchain ? fwd_mc : fwd_std;

crypto/smc-envelope/SmartContract.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,17 @@ td::Ref<vm::Tuple> prepare_vm_c7(SmartContract::Args args, td::Ref<vm::Cell> cod
149149
}
150150

151151
std::vector<vm::StackEntry> tuple = {
152-
td::make_refint(0x076ef1ea), // [ magic:0x076ef1ea
153-
td::make_refint(0), // actions:Integer
154-
td::make_refint(0), // msgs_sent:Integer
155-
td::make_refint(now), // unixtime:Integer
156-
td::make_refint(0), //TODO: // block_lt:Integer
157-
td::make_refint(0), //TODO: // trans_lt:Integer
158-
std::move(rand_seed_int), // rand_seed:Integer
159-
block::CurrencyCollection(args.balance).as_vm_tuple(), // balance_remaining:[Integer (Maybe Cell)]
160-
vm::load_cell_slice_ref(address), // myself:MsgAddressInt
161-
vm::StackEntry::maybe(config) // vm::StackEntry::maybe(td::Ref<vm::Cell>())
152+
td::make_refint(0x076ef1ea), // [ magic:0x076ef1ea
153+
td::make_refint(0), // actions:Integer
154+
td::make_refint(0), // msgs_sent:Integer
155+
td::make_refint(now), // unixtime:Integer
156+
td::make_refint(0), // block_lt:Integer (TODO)
157+
td::make_refint(0), // trans_lt:Integer (TODO)
158+
std::move(rand_seed_int), // rand_seed:Integer
159+
block::CurrencyCollection(args.balance, args.extra_currencies)
160+
.as_vm_tuple(), // balance_remaining:[Integer (Maybe Cell)]
161+
vm::load_cell_slice_ref(address), // myself:MsgAddressInt
162+
vm::StackEntry::maybe(config) // vm::StackEntry::maybe(td::Ref<vm::Cell>())
162163
};
163164
if (args.config && args.config.value()->get_global_version() >= 4) {
164165
tuple.push_back(vm::StackEntry::maybe(code)); // code:Cell

crypto/smc-envelope/SmartContract.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SmartContract : public td::CntObject {
6464
bool ignore_chksig{false};
6565
td::uint64 amount{0};
6666
td::uint64 balance{0};
67+
td::Ref<vm::Cell> extra_currencies;
6768
int vm_log_verbosity_level{0};
6869
bool debug_enabled{false};
6970

@@ -121,6 +122,10 @@ class SmartContract : public td::CntObject {
121122
this->balance = balance;
122123
return std::move(*this);
123124
}
125+
Args&& set_extra_currencies(td::Ref<vm::Cell> extra_currencies) {
126+
this->extra_currencies = std::move(extra_currencies);
127+
return std::move(*this);
128+
}
124129
Args&& set_address(block::StdAddress address) {
125130
this->address = address;
126131
return std::move(*this);

0 commit comments

Comments
 (0)