Skip to content

Commit 82af48c

Browse files
committed
apply epoch 419
1 parent 7eb29f3 commit 82af48c

4 files changed

Lines changed: 24 additions & 47 deletions

File tree

ex/lib/node/txpool.ex

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,8 @@ defmodule TXPool do
6363
batch_state = Map.put(batch_state, {:chain_nonce, txu.tx.signer}, txu.tx.nonce)
6464

6565
balance = Map.get_lazy(batch_state, {:balance, txu.tx.signer}, fn()-> DB.Chain.balance(txu.tx.signer) end)
66-
balance = if chain_height >= RDBProtocol.forkheight() do
67-
balance = balance - (RDBProtocol.reserve_ama_per_tx() * 2)
68-
balance = balance - TX.historical_cost(txu)
69-
else
70-
balance = balance - TX.exec_cost(chain_epoch, txu)
71-
balance = balance - BIC.Coin.to_cents(1)
72-
end
66+
balance = balance - (RDBProtocol.reserve_ama_per_tx() * 2)
67+
balance = balance - TX.historical_cost(txu)
7368
if balance < 0, do: throw(%{error: :not_enough_tx_exec_balance, key: {txu.tx.nonce, txu.hash}})
7469
batch_state = Map.put(batch_state, {:balance, txu.tx.signer}, balance)
7570

ex/native/rdb/src/consensus/consensus_apply.rs

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub fn apply_entry<'db, 'a>(db: &'db TransactionDB<MultiThreaded>, pk: &[u8], sk
207207
}
208208
}
209209
}));
210+
210211
applyenv.exec_track = false;
211212

212213
let tx_cost = txu.map_get(crate::atoms::tx_cost()).unwrap().decode::<i128>().unwrap();
@@ -243,10 +244,7 @@ pub fn apply_entry<'db, 'a>(db: &'db TransactionDB<MultiThreaded>, pk: &[u8], sk
243244
*/
244245
let mut m = std::collections::HashMap::new();
245246
m.insert("error".to_string(), "ok".to_string());
246-
m.insert("exec_used".to_string(), tx_cost.clone());
247-
if applyenv.caller_env.entry_height >= protocol::FORKHEIGHT {
248-
m.insert("exec_used".to_string(), exec_cost_total.clone());
249-
}
247+
m.insert("exec_used".to_string(), exec_cost_total.clone());
250248
applyenv.result_log.push(m);
251249
}
252250
Err(payload) => {
@@ -257,18 +255,12 @@ pub fn apply_entry<'db, 'a>(db: &'db TransactionDB<MultiThreaded>, pk: &[u8], sk
257255
if let Some(&s) = payload.downcast_ref::<&'static str>() {
258256
let mut m = std::collections::HashMap::new();
259257
m.insert("error".to_string(), s.to_string());
260-
m.insert("exec_used".to_string(), tx_cost.clone());
261-
if applyenv.caller_env.entry_height >= protocol::FORKHEIGHT {
262-
m.insert("exec_used".to_string(), exec_cost_total.clone());
263-
}
258+
m.insert("exec_used".to_string(), exec_cost_total.clone());
264259
applyenv.result_log.push(m);
265260
} else {
266261
let mut m = std::collections::HashMap::new();
267262
m.insert("error".to_string(), "unknown".to_string());
268-
m.insert("exec_used".to_string(), tx_cost.clone());
269-
if applyenv.caller_env.entry_height >= protocol::FORKHEIGHT {
270-
m.insert("exec_used".to_string(), exec_cost_total.clone());
271-
}
263+
m.insert("exec_used".to_string(), exec_cost_total.clone());
272264
applyenv.result_log.push(m);
273265
}
274266
}
@@ -404,22 +396,20 @@ impl ToTerm for Vec<HashMap<String, String>> {
404396

405397
fn refund_exec_deposit(applyenv: &mut ApplyEnv) {
406398
//Refund remainer of the exec budget
407-
if applyenv.caller_env.entry_height >= protocol::FORKHEIGHT {
408-
applyenv.muts = Vec::new();
409-
applyenv.muts_rev = Vec::new();
410-
let refund = applyenv.exec_left.max(0);
411-
if refund > 0 {
412-
let key = &crate::bcat(&[b"account:", &applyenv.caller_env.account_origin, b":balance:AMA"]);
413-
consensus_kv::kv_increment(applyenv, key, refund);
414-
}
415-
// Increment validator / burn
416-
let cost = applyenv.exec_max - refund;
417-
consensus_kv::kv_increment(applyenv, &crate::bcat(&[b"account:", &applyenv.caller_env.entry_signer, b":balance:AMA"]), cost/2);
418-
consensus_kv::kv_increment(applyenv, &crate::bcat(&[b"account:", &consensus::bic::coin::BURN_ADDRESS, b":balance:AMA"]), cost/2);
419-
420-
applyenv.muts_final.append(&mut applyenv.muts);
421-
applyenv.muts_final_rev.append(&mut applyenv.muts_rev);
399+
applyenv.muts = Vec::new();
400+
applyenv.muts_rev = Vec::new();
401+
let refund = applyenv.exec_left.max(0);
402+
if refund > 0 {
403+
let key = &crate::bcat(&[b"account:", &applyenv.caller_env.account_origin, b":balance:AMA"]);
404+
consensus_kv::kv_increment(applyenv, key, refund);
422405
}
406+
// Increment validator / burn
407+
let cost = applyenv.exec_max - refund;
408+
consensus_kv::kv_increment(applyenv, &crate::bcat(&[b"account:", &applyenv.caller_env.entry_signer, b":balance:AMA"]), cost/2);
409+
consensus_kv::kv_increment(applyenv, &crate::bcat(&[b"account:", &consensus::bic::coin::BURN_ADDRESS, b":balance:AMA"]), cost/2);
410+
411+
applyenv.muts_final.append(&mut applyenv.muts);
412+
applyenv.muts_final_rev.append(&mut applyenv.muts_rev);
423413
}
424414

425415
fn call_txs_pre_upfront_cost<'a>(env: &mut ApplyEnv, txus: &[rustler::Term<'a>]) {
@@ -437,15 +427,10 @@ fn call_txs_pre_upfront_cost<'a>(env: &mut ApplyEnv, txus: &[rustler::Term<'a>])
437427
consensus_kv::kv_put(env, &crate::bcat(&[b"account:", &tx_signer, b":attribute:nonce"]), &tx_nonce.to_string().into_bytes());
438428

439429
// Deduct tx historical cost
440-
if env.caller_env.entry_height >= protocol::FORKHEIGHT {
441-
let tx_historical_cost = txu.map_get(crate::atoms::tx_historical_cost()).unwrap().decode::<i128>().unwrap();
442-
protocol::pay_cost(env, tx_historical_cost);
443-
//lock 0.1 AMA during execution
444-
consensus_kv::kv_increment(env, &crate::bcat(&[b"account:", &env.caller_env.account_origin, b":balance:AMA"]), -protocol::AMA_10_CENT);
445-
} else {
446-
let tx_cost = txu.map_get(crate::atoms::tx_cost()).unwrap().decode::<i128>().unwrap();
447-
protocol::pay_cost(env, tx_cost);
448-
}
430+
let tx_historical_cost = txu.map_get(crate::atoms::tx_historical_cost()).unwrap().decode::<i128>().unwrap();
431+
protocol::pay_cost(env, tx_historical_cost);
432+
//lock 0.1 AMA during execution
433+
consensus_kv::kv_increment(env, &crate::bcat(&[b"account:", &env.caller_env.account_origin, b":balance:AMA"]), -protocol::AMA_10_CENT);
449434
}
450435
env.muts_final.append(&mut env.muts);
451436
env.muts_final_rev.append(&mut env.muts_rev);

ex/native/rdb/src/consensus/consensus_kv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn exec_budget_decr(env: &mut ApplyEnv, amount: i128) {
1111
panic_any("invalid_exec_amount_negative");
1212
}
1313

14-
if env.caller_env.entry_height >= protocol::FORKHEIGHT && env.exec_track {
14+
if env.exec_track {
1515
match env.exec_left.checked_sub(amount) {
1616
Some(new_budget) => {
1717
if new_budget < 0 {

ex/native/rdb/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,6 @@ fn bintree_contractstate_root_prove<'a>(env: Env<'a>, db: ResourceArc<DbResource
875875
key.as_slice(),
876876
);
877877

878-
let result = crate::consensus::bintree::Hubt::verify(&proof, namespace, key.as_slice().to_vec(), b"8".to_vec());
879-
println!("{:?}", result);
880-
881878
let nodes_list: Vec<Term> = proof.nodes.iter().map(|node| {
882879
let mut map = Term::map_new(env);
883880

0 commit comments

Comments
 (0)