mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add fee burning and blackhole address (#703)
* Fix tlbc crash * Burn specified fraction of fees * Add "blackhole" for burning TONs --------- Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
d5cd548502
commit
ef64b92f08
12 changed files with 187 additions and 57 deletions
|
@ -1393,7 +1393,13 @@ bool Collator::import_new_shard_top_blocks() {
|
|||
}
|
||||
LOG(INFO) << "total fees_imported = " << value_flow_.fees_imported.to_str()
|
||||
<< " ; out of them, total fees_created = " << import_created_.to_str();
|
||||
value_flow_.fees_collected += value_flow_.fees_imported;
|
||||
block::CurrencyCollection burned =
|
||||
config_->get_burning_config().calculate_burned_fees(value_flow_.fees_imported - import_created_);
|
||||
if (!burned.is_valid()) {
|
||||
return fatal_error("cannot calculate amount of burned imported fees");
|
||||
}
|
||||
value_flow_.burned += burned;
|
||||
value_flow_.fees_collected += value_flow_.fees_imported - burned;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2208,6 +2214,7 @@ Ref<vm::Cell> Collator::create_ordinary_transaction(Ref<vm::Cell> msg_root) {
|
|||
|
||||
register_new_msgs(*trans);
|
||||
update_max_lt(acc->last_trans_end_lt_);
|
||||
value_flow_.burned += trans->blackhole_burned;
|
||||
return trans_root;
|
||||
}
|
||||
|
||||
|
@ -3733,7 +3740,16 @@ bool Collator::compute_total_balance() {
|
|||
LOG(ERROR) << "cannot unpack CurrencyCollection from the root of OutMsgDescr";
|
||||
return false;
|
||||
}
|
||||
value_flow_.fees_collected += new_transaction_fees + new_import_fees;
|
||||
block::CurrencyCollection total_fees = new_transaction_fees + new_import_fees;
|
||||
value_flow_.fees_collected += total_fees;
|
||||
if (is_masterchain()) {
|
||||
block::CurrencyCollection burned = config_->get_burning_config().calculate_burned_fees(total_fees);
|
||||
if (!burned.is_valid()) {
|
||||
return fatal_error("cannot calculate amount of burned masterchain fees");
|
||||
}
|
||||
value_flow_.fees_collected -= burned;
|
||||
value_flow_.burned += burned;
|
||||
}
|
||||
// 3. compute total_validator_fees
|
||||
total_validator_fees_ += value_flow_.fees_collected;
|
||||
total_validator_fees_ -= value_flow_.recovered;
|
||||
|
|
|
@ -62,12 +62,10 @@ td::Status ShardTopBlockDescrQ::unpack_one_proof(BlockIdExt& cur_id, Ref<vm::Cel
|
|||
block::gen::Block::Record blk;
|
||||
block::gen::BlockInfo::Record info;
|
||||
block::gen::BlockExtra::Record extra;
|
||||
block::gen::ValueFlow::Record flow;
|
||||
block::CurrencyCollection fees_collected, funds_created;
|
||||
block::ValueFlow flow;
|
||||
if (!(tlb::unpack_cell(virt_root, blk) && tlb::unpack_cell(blk.info, info) && !info.version &&
|
||||
block::gen::t_ValueFlow.force_validate_ref(blk.value_flow) && tlb::unpack_cell(blk.value_flow, flow) &&
|
||||
/*tlb::unpack_cell(blk.extra, extra) &&*/ fees_collected.unpack(flow.fees_collected) &&
|
||||
funds_created.unpack(flow.r2.created))) {
|
||||
flow.unpack(vm::load_cell_slice_ref(blk.value_flow)))
|
||||
/*&& tlb::unpack_cell(blk.extra, extra)*/) {
|
||||
return td::Status::Error(-666, "cannot unpack block header in link for block "s + cur_id.to_str());
|
||||
}
|
||||
// remove this "try ... catch ..." later and uncomment tlb::unpack_cell(blk.extra, extra) in the previous condition
|
||||
|
@ -131,7 +129,7 @@ td::Status ShardTopBlockDescrQ::unpack_one_proof(BlockIdExt& cur_id, Ref<vm::Cel
|
|||
}
|
||||
chain_mc_blk_ids_.push_back(mc_blkid);
|
||||
chain_blk_ids_.push_back(cur_id);
|
||||
chain_fees_.emplace_back(std::move(fees_collected), std::move(funds_created));
|
||||
chain_fees_.emplace_back(std::move(flow.fees_collected), std::move(flow.created));
|
||||
creators_.push_back(extra.created_by);
|
||||
if (!is_head) {
|
||||
if (info.after_split || info.after_merge) {
|
||||
|
|
|
@ -808,6 +808,7 @@ bool ValidateQuery::fetch_config_params() {
|
|||
action_phase_cfg_.workchains = &config_->get_workchain_list();
|
||||
action_phase_cfg_.bounce_msg_body = (config_->has_capability(ton::capBounceMsgBody) ? 256 : 0);
|
||||
action_phase_cfg_.size_limits = size_limits;
|
||||
action_phase_cfg_.mc_blackhole_addr = config_->get_burning_config().blackhole_addr;
|
||||
}
|
||||
{
|
||||
// fetch block_grams_created
|
||||
|
@ -2161,6 +2162,11 @@ bool ValidateQuery::unpack_precheck_value_flow(Ref<vm::Cell> value_flow_root) {
|
|||
return reject_query("ValueFlow of block "s + id_.to_str() +
|
||||
" is invalid (non-zero recovered value in a non-masterchain block)");
|
||||
}
|
||||
if (!is_masterchain() && !value_flow_.burned.is_zero()) {
|
||||
LOG(INFO) << "invalid value flow: " << os.str();
|
||||
return reject_query("ValueFlow of block "s + id_.to_str() +
|
||||
" is invalid (non-zero burned value in a non-masterchain block)");
|
||||
}
|
||||
if (!value_flow_.recovered.is_zero() && recover_create_msg_.is_null()) {
|
||||
return reject_query("ValueFlow of block "s + id_.to_str() +
|
||||
" has a non-zero recovered fees value, but there is no recovery InMsg");
|
||||
|
@ -2243,15 +2249,10 @@ bool ValidateQuery::unpack_precheck_value_flow(Ref<vm::Cell> value_flow_root) {
|
|||
"cannot unpack CurrencyCollection with total transaction fees from the augmentation of the ShardAccountBlocks "
|
||||
"dictionary");
|
||||
}
|
||||
auto expected_fees = value_flow_.fees_imported + value_flow_.created + transaction_fees_ + import_fees_;
|
||||
if (value_flow_.fees_collected != expected_fees) {
|
||||
return reject_query(PSTRING() << "ValueFlow for " << id_.to_str() << " declares fees_collected="
|
||||
<< value_flow_.fees_collected.to_str() << " but the total message import fees are "
|
||||
<< import_fees_ << ", the total transaction fees are " << transaction_fees_.to_str()
|
||||
<< ", creation fee for this block is " << value_flow_.created.to_str()
|
||||
<< " and the total imported fees from shards are "
|
||||
<< value_flow_.fees_imported.to_str() << " with a total of "
|
||||
<< expected_fees.to_str());
|
||||
if (is_masterchain()) {
|
||||
auto x = config_->get_burning_config().calculate_burned_fees(transaction_fees_ + import_fees_);
|
||||
fees_burned_ += x;
|
||||
total_burned_ += x;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -4564,6 +4565,7 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT
|
|||
<< "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " is invalid: it has produced a set of outbound messages different from that listed in the transaction");
|
||||
}
|
||||
total_burned_ += trs->blackhole_burned;
|
||||
// check new balance and value flow
|
||||
auto new_balance = account.get_balance();
|
||||
block::CurrencyCollection total_fees;
|
||||
|
@ -4571,12 +4573,14 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT
|
|||
return reject_query(PSTRING() << "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " has an invalid total_fees value");
|
||||
}
|
||||
if (old_balance + money_imported != new_balance + money_exported + total_fees) {
|
||||
return reject_query(PSTRING() << "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " violates the currency flow condition: old balance=" << old_balance.to_str()
|
||||
<< " + imported=" << money_imported.to_str() << " does not equal new balance="
|
||||
<< new_balance.to_str() << " + exported=" << money_exported.to_str()
|
||||
<< " + total_fees=" << total_fees.to_str());
|
||||
if (old_balance + money_imported != new_balance + money_exported + total_fees + trs->blackhole_burned) {
|
||||
return reject_query(
|
||||
PSTRING() << "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " violates the currency flow condition: old balance=" << old_balance.to_str()
|
||||
<< " + imported=" << money_imported.to_str() << " does not equal new balance=" << new_balance.to_str()
|
||||
<< " + exported=" << money_exported.to_str() << " + total_fees=" << total_fees.to_str()
|
||||
<< (trs->blackhole_burned.is_zero() ? ""
|
||||
: PSTRING() << " burned=" << trs->blackhole_burned.to_str()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -5447,6 +5451,9 @@ bool ValidateQuery::check_mc_block_extra() {
|
|||
return reject_query("invalid fees_imported in value flow: declared "s + value_flow_.fees_imported.to_str() +
|
||||
", correct value is " + fees_imported.to_str());
|
||||
}
|
||||
auto x = config_->get_burning_config().calculate_burned_fees(fees_imported - import_created_);
|
||||
total_burned_ += x;
|
||||
fees_burned_ += x;
|
||||
// ^[ prev_blk_signatures:(HashmapE 16 CryptoSignaturePair)
|
||||
if (prev_signatures_.not_null() && id_.seqno() == 1) {
|
||||
return reject_query("block contains non-empty signature set for the zero state of the masterchain");
|
||||
|
@ -5464,6 +5471,26 @@ bool ValidateQuery::check_mc_block_extra() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ValidateQuery::postcheck_value_flow() {
|
||||
auto expected_fees =
|
||||
value_flow_.fees_imported + value_flow_.created + transaction_fees_ + import_fees_ - fees_burned_;
|
||||
if (value_flow_.fees_collected != expected_fees) {
|
||||
return reject_query(PSTRING() << "ValueFlow for " << id_.to_str() << " declares fees_collected="
|
||||
<< value_flow_.fees_collected.to_str() << " but the total message import fees are "
|
||||
<< import_fees_ << ", the total transaction fees are " << transaction_fees_.to_str()
|
||||
<< ", creation fee for this block is " << value_flow_.created.to_str()
|
||||
<< ", the total imported fees from shards are " << value_flow_.fees_imported.to_str()
|
||||
<< " and the burned fees are " << fees_burned_.to_str()
|
||||
<< " with a total of " << expected_fees.to_str());
|
||||
}
|
||||
if (total_burned_ != value_flow_.burned) {
|
||||
return reject_query(PSTRING() << "invalid burned in value flow: " << id_.to_str() << " declared "
|
||||
<< value_flow_.burned.to_str() << ", correct value is "
|
||||
<< total_burned_.to_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* MAIN VALIDATOR FUNCTION
|
||||
|
@ -5565,6 +5592,9 @@ bool ValidateQuery::try_validate() {
|
|||
if (!check_mc_state_extra()) {
|
||||
return reject_query("new McStateExtra is invalid");
|
||||
}
|
||||
if (!postcheck_value_flow()) {
|
||||
return reject_query("new ValueFlow is invalid");
|
||||
}
|
||||
} catch (vm::VmError& err) {
|
||||
return fatal_error(-666, err.get_msg());
|
||||
} catch (vm::VmVirtError& err) {
|
||||
|
|
|
@ -217,7 +217,7 @@ class ValidateQuery : public td::actor::Actor {
|
|||
|
||||
std::unique_ptr<vm::AugmentedDictionary> in_msg_dict_, out_msg_dict_, account_blocks_dict_;
|
||||
block::ValueFlow value_flow_;
|
||||
block::CurrencyCollection import_created_, transaction_fees_;
|
||||
block::CurrencyCollection import_created_, transaction_fees_, total_burned_{0}, fees_burned_{0};
|
||||
td::RefInt256 import_fees_;
|
||||
|
||||
ton::LogicalTime proc_lt_{0}, claimed_proc_lt_{0}, min_enq_lt_{~0ULL};
|
||||
|
@ -361,6 +361,7 @@ class ValidateQuery : public td::actor::Actor {
|
|||
bool check_one_prev_dict_update(ton::BlockSeqno seqno, Ref<vm::CellSlice> old_val_extra,
|
||||
Ref<vm::CellSlice> new_val_extra);
|
||||
bool check_mc_state_extra();
|
||||
bool postcheck_value_flow();
|
||||
td::Status check_counter_update(const block::DiscountedCounter& oc, const block::DiscountedCounter& nc,
|
||||
unsigned expected_incr);
|
||||
bool check_one_block_creator_update(td::ConstBitPtr key, Ref<vm::CellSlice> old_val, Ref<vm::CellSlice> new_val);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue