Skip to content

Commit 760aa74

Browse files
committed
mend
1 parent 21b8b21 commit 760aa74

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

ex/native/rdb/src/consensus/bic/protocol.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
use crate::consensus::bic::coin;
22
use crate::consensus::consensus_kv;
33

4+
pub const AMA_1_DOLLAR: i128 = 1_000_000_000;
5+
pub const AMA_10_CENT: i128 = 100_000_000;
6+
pub const AMA_1_CENT: i128 = 10_000_000;
7+
8+
pub const COST_PER_BYTE_HISTORICAL: i128 = 1; //cost to increase the ledger size
9+
pub const COST_PER_BYTE_STATE: i128 = 1; //cost to grow the contract state
10+
pub const COST_PER_OP_WASM: i128 = 1; //cost to execute a wasm op
11+
12+
pub const COST_PER_SOL: i128 = AMA_1_CENT; //cost to submit_sol
13+
pub const COST_PER_NEW_LEAF_MERKLE: i128 = COST_PER_BYTE_STATE * (128+32); //cost to grow the merkle tree
14+
15+
416
//1 cent AMA per 1kb
517
pub fn tx_cost_per_byte(_epoch: u64, tx_encoded_len: usize) -> i128 {
618
let bytes = tx_encoded_len + 32 + 96;

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub struct ApplyEnv<'db> {
8282
pub muts_gas: Vec<consensus_muts::Mutation>,
8383
pub muts_rev: Vec<consensus_muts::Mutation>,
8484
pub muts_rev_gas: Vec<consensus_muts::Mutation>,
85-
pub result_log: Vec<HashMap<&'static str, &'static str>>,
85+
pub result_log: Vec<HashMap<String, String>>,
8686
pub testnet: bool,
8787
pub testnet_peddlebikes: Vec<Vec<u8>>,
8888
}
@@ -94,7 +94,7 @@ impl<'db> ApplyEnv<'db> {
9494
Transaction<'db, TransactionDB<MultiThreaded>>,
9595
Vec<consensus_muts::Mutation>,
9696
Vec<consensus_muts::Mutation>,
97-
Vec<HashMap<&'static str, &'static str>>,
97+
Vec<HashMap<String, String>>,
9898
) {
9999
(self.txn, self.muts_final, self.muts_final_rev, self.result_log)
100100
}
@@ -140,7 +140,7 @@ pub fn apply_entry<'db, 'a>(db: &'db TransactionDB<MultiThreaded>, pk: &[u8], sk
140140
entry_vr: &[u8; 96], entry_vr_b3: &[u8; 32], entry_dr: &[u8; 32],
141141
txus: Vec<rustler::Term<'a>>, txn: Transaction<'db, TransactionDB<MultiThreaded>>,
142142
testnet: bool, testnet_peddlebikes: Vec<Vec<u8>>,
143-
) -> (Transaction<'db, TransactionDB<MultiThreaded>>, Vec<consensus_muts::Mutation>, Vec<consensus_muts::Mutation>, Vec<HashMap<&'static str, &'static str>>) {
143+
) -> (Transaction<'db, TransactionDB<MultiThreaded>>, Vec<consensus_muts::Mutation>, Vec<consensus_muts::Mutation>, Vec<HashMap<String, String>>) {
144144
let cf_h = db.cf_handle("contractstate").unwrap();
145145
let cf2_h = db.cf_handle("contractstate").unwrap();
146146
let cf_tree_h = db.cf_handle("contractstate_tree").unwrap();
@@ -202,6 +202,7 @@ pub fn apply_entry<'db, 'a>(db: &'db TransactionDB<MultiThreaded>, pk: &[u8], sk
202202
}));
203203

204204
let tx_cost = txu.map_get(crate::atoms::tx_cost()).unwrap().decode::<i128>().unwrap();
205+
let tx_cost = (tx_cost as u64).to_string();
205206
match res {
206207
Ok(_) => {
207208
applyenv.muts_final.append(&mut applyenv.muts);
@@ -232,9 +233,9 @@ pub fn apply_entry<'db, 'a>(db: &'db TransactionDB<MultiThreaded>, pk: &[u8], sk
232233
}
233234
*/
234235
let mut m = std::collections::HashMap::new();
235-
m.insert("error", "ok");
236+
m.insert("error".to_string(), "ok".to_string());
236237
if applyenv.caller_env.entry_height >= 416_00000 {
237-
m.insert("gas_used", "0");
238+
m.insert("gas_used".to_string(), tx_cost.clone());
238239
}
239240
applyenv.result_log.push(m);
240241
}
@@ -245,18 +246,18 @@ pub fn apply_entry<'db, 'a>(db: &'db TransactionDB<MultiThreaded>, pk: &[u8], sk
245246
consensus_kv::revert(&mut applyenv);
246247

247248
if let Some(&s) = payload.downcast_ref::<&'static str>() {
248-
let mut m: HashMap<&'static str, &'static str> = HashMap::new();
249-
m.insert("error", s);
249+
let mut m = std::collections::HashMap::new();
250+
m.insert("error".to_string(), s.to_string());
250251
if applyenv.caller_env.entry_height >= 416_00000 {
251-
m.insert("gas_used", "0");
252+
m.insert("gas_used".to_string(), tx_cost.clone());
252253
}
253254
applyenv.result_log.push(m);
254255
} else {
255-
let mut m: HashMap<&'static str, &'static str> = HashMap::new();
256-
m.insert("error", "unknown");
256+
let mut m = std::collections::HashMap::new();
257+
m.insert("error".to_string(), "unknown".to_string());
257258
if applyenv.caller_env.entry_height >= 416_00000 {
258259
//(tx_cost as u64).to_string().into_bytes()
259-
m.insert("gas_used", "0");
260+
m.insert("gas_used".to_string(), tx_cost.clone());
260261
}
261262
applyenv.result_log.push(m);
262263
}

0 commit comments

Comments
 (0)