Skip to content

Commit b440712

Browse files
committed
fix: issue #21
1 parent 2f89bbe commit b440712

6 files changed

Lines changed: 47 additions & 13 deletions

File tree

chain/src/engine/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl EngineConf {
9494
};
9595
// setup lowest_fee
9696
if ini_must(sec_server, "lowest_fee", "").len() > 0 {
97-
let lfepr = ini_must_amount(sec_server, "lowest_fee").compress(2, true)
97+
let lfepr = ini_must_amount(sec_server, "lowest_fee").compress(2, AmtCpr::Grow)
9898
.unwrap().to_238_u64().unwrap() / 166; // =6024, simple hac trs size
9999
cnf.lowest_fee_purity = lfepr;
100100
println!("[Config] Node accepted lowest fee purity {}.", lfepr);
@@ -125,9 +125,9 @@ impl EngineConf {
125125
if cnf.dmer_enable {
126126
cnf.dmer_reward_address = ini_must_address(sec_dmer, "reward");
127127
cnf.dmer_bid_account = ini_must_account(sec_dmer, "bid_password");
128-
cnf.dmer_bid_min = ini_must_amount(sec_dmer, "bid_min").compress(2, true).unwrap();
129-
cnf.dmer_bid_max = ini_must_amount(sec_dmer, "bid_max").compress(2, true).unwrap();
130-
cnf.dmer_bid_step = ini_must_amount(sec_dmer, "bid_step").compress(2, true).unwrap();
128+
cnf.dmer_bid_min = ini_must_amount(sec_dmer, "bid_min").compress(2, AmtCpr::Grow).unwrap();
129+
cnf.dmer_bid_max = ini_must_amount(sec_dmer, "bid_max").compress(2, AmtCpr::Grow).unwrap();
130+
cnf.dmer_bid_step = ini_must_amount(sec_dmer, "bid_step").compress(2, AmtCpr::Grow).unwrap();
131131
}
132132

133133
// ok

field/src/core/amount.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ pub enum AmtMode {
2222
BIGINT,
2323
}
2424

25+
pub enum AmtCpr {
26+
Discard,
27+
Grow,
28+
}
29+
2530

2631

2732
#[derive(Default, Hash, Clone, PartialEq, Eq)]
@@ -618,7 +623,7 @@ impl Amount {
618623
}
619624
}
620625

621-
pub fn compress(&self, btn: usize, upvalue: bool) -> Ret<Amount> {
626+
pub fn compress(&self, btn: usize, cpr: AmtCpr) -> Ret<Amount> {
622627
if self.dist < 0 {
623628
return errf!("cannot compress negative amount")
624629
}
@@ -631,7 +636,7 @@ impl Amount {
631636
return errf!("amount uint too big to compress")
632637
}
633638
let mut numpls = u128::from_be_bytes(add_left_padding(&amt.byte, U128S).try_into().unwrap()) / 10;
634-
if upvalue {
639+
if let AmtCpr::Grow = cpr {
635640
numpls += 1;
636641
}
637642
let nbts = drop_left_zero(&numpls.to_be_bytes());

node/src/diamondbid/bidding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn check_bidding_step(hnode: Arc<dyn HNode>, engcnf: &EngineConf, pending_height
4545
if *first_bid_fee > engcnf.dmer_bid_max {
4646
retry!(10); // my max too low
4747
}
48-
let Ok(first_bid_fee) = first_bid_fee.compress(2, true) else {
48+
let Ok(first_bid_fee) = first_bid_fee.compress(2, AmtCpr::Grow) else {
4949
printerr!("cannot compress fee {} to 4 legnth", &first_bid_fee);
5050
retry!(10); // move step fail
5151
};
@@ -70,7 +70,7 @@ fn check_bidding_step(hnode: Arc<dyn HNode>, engcnf: &EngineConf, pending_height
7070
);
7171
retry!(10); // move step fail
7272
};
73-
let Ok(mut new_bid_fee) = new_bid_fee.compress(2, true) else {
73+
let Ok(mut new_bid_fee) = new_bid_fee.compress(2, AmtCpr::Grow) else {
7474
printerr!("cannot compress fee {} to 4 legnth", &new_bid_fee);
7575
retry!(10); // move step fail
7676
};

node/src/handler/txblock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async fn handle_new_tx(this: Arc<MsgHandler>, peer: Option<Arc<Peer>>, body: Vec
2828
if let Err(..) = this.engine.try_execute_tx(txpr) {
2929
return // tx execute fail
3030
}
31-
if let Err(..) = this.engine.mint_checker().tx_submit(this.engine.as_read(), &txpkg) {
31+
if let Err(..) = minter.tx_submit(this.engine.as_read(), &txpkg) {
3232
return // tx check fail
3333
}
3434
// add to tx pool

server/src/api/diamond_miner.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,38 @@ async fn diamondminer_success(State(ctx): State<ApiCtx>, q: Query<Q6396>, body:
5858
return api_error("diamond prev hash error");
5959
}
6060

61-
// create trs
61+
// check current highest diamond offer
6262
let bid_addr = Address::from(cnf.dmer_bid_account.address().clone());
63-
let mut tx = TransactionType2::new_by(bid_addr, cnf.dmer_bid_min.clone(), curtimes());
63+
let mut bid_offer = cnf.dmer_bid_min.clone();
64+
if let Ok(Some(fbtx)) = ctx.hcshnd.txpool().first_at(mint::TXGID_DIAMINT) {
65+
let hbfe = fbtx.objc.fee().clone();
66+
let mmax = cnf.dmer_bid_max.clone();
67+
let step = cnf.dmer_bid_step.clone();
68+
if hbfe > mmax {
69+
bid_offer = mmax; // higher than my max
70+
} else if hbfe > bid_offer {
71+
if fbtx.objc.main() == bid_addr {
72+
// high is my self
73+
bid_offer = hbfe;
74+
} else {
75+
// my = other high + step
76+
if let Ok(new_bid) = hbfe.add_mode_u64(&step) {
77+
bid_offer = new_bid;
78+
} else {
79+
println!("[diamond miner error] cannot add fee {} with {}, ", &hbfe, step);
80+
}
81+
}
82+
}
83+
}
84+
// compress amount
85+
if let Ok(new_bid) = bid_offer.compress(2, AmtCpr::Grow) {
86+
bid_offer = new_bid;
87+
} else {
88+
println!("[diamond miner error] cannot compress fee {} to 4 legnth", &bid_offer);
89+
};
90+
91+
// create trs
92+
let mut tx = TransactionType2::new_by(bid_addr, bid_offer, curtimes());
6493
tx.push_action(Box::new(mint)).unwrap();
6594
tx.fill_sign(&cnf.dmer_bid_account).unwrap();
6695

src/version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

3-
const HACASH_NODE_VERSION: &str = "0.2.13";
4-
const HACASH_NODE_BUILD_TIME: &str = "2025/8/18(1)";
3+
const HACASH_NODE_VERSION: &str = "0.2.14";
4+
const HACASH_NODE_BUILD_TIME: &str = "2025/8/23(1)";
55
#[allow(unused)]
66
const HACASH_STATE_DB_UPDT: u32 = 3;
77

0 commit comments

Comments
 (0)