Skip to content

Commit

Permalink
Merge pull request #864 from SaitoTech/develop
Browse files Browse the repository at this point in the history
0.2.31
  • Loading branch information
SankaD authored Nov 13, 2024
2 parents 282c446 + 9bb9699 commit e186241
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.30
0.2.31
4 changes: 3 additions & 1 deletion saito-core/src/core/consensus/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,11 @@ impl Mempool {
return None;
}
if !self.blocks_queue.is_empty() {
debug!("there are blocks in queue");
return None;
}
if self.transactions.is_empty() || !self.new_tx_added {
debug!("there are no transactions in queue");
return None;
}
if !blockchain.is_golden_ticket_count_valid(
Expand All @@ -300,7 +302,7 @@ impl Mempool {
configs.is_browser(),
configs.is_spv_mode(),
) {
trace!("waiting till more golden tickets come in");
debug!("waiting till more golden tickets come in");
return None;
}

Expand Down
11 changes: 8 additions & 3 deletions saito-core/src/core/consensus_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ impl ConsensusThread {
}
}

pub async fn produce_block(&mut self, timestamp: Timestamp) {
pub async fn produce_block(&mut self, timestamp: Timestamp, produce_without_limits: bool) {
debug!("producing a block");
let configs = self.network.config_lock.read().await;

let mut blockchain = self.blockchain_lock.write().await;
Expand Down Expand Up @@ -154,7 +155,9 @@ impl ConsensusThread {
}

let mut block = None;
if !configs.is_browser() && !configs.is_spv_mode() && !blockchain.blocks.is_empty() {
if (produce_without_limits || (!configs.is_browser() && !configs.is_spv_mode()))
&& !blockchain.blocks.is_empty()
{
block = mempool
.bundle_block(
blockchain.deref_mut(),
Expand All @@ -164,6 +167,8 @@ impl ConsensusThread {
&self.storage,
)
.await;
} else {
info!("skipped bundling block");
}
if let Some(block) = block {
debug!(
Expand Down Expand Up @@ -278,7 +283,7 @@ impl ProcessEvent<ConsensusEvent> for ConsensusThread {
// generate blocks
self.block_producing_timer += duration_value;
if self.produce_blocks_by_timer && self.block_producing_timer >= BLOCK_PRODUCING_TIMER {
self.produce_block(timestamp).await;
self.produce_block(timestamp, false).await;

work_done = true;
}
Expand Down
3 changes: 1 addition & 2 deletions saito-core/src/core/mining_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ pub struct MiningThread {

impl MiningThread {
pub async fn mine(&mut self) -> Option<GoldenTicket> {
assert!(self.miner_active);

// assert!(self.miner_active, "Miner is not active");
if self.public_key == [0; 33] {
let wallet = self.wallet_lock.read().await;
if wallet.public_key == [0; 33] {
Expand Down
8 changes: 8 additions & 0 deletions saito-js/lib/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,12 @@ export default class Block extends WasmWrapper<WasmBlock> {
return this.instance.fee_transaction_index;
}

public get totalPayoutAtr(): bigint {
return this.instance.total_payout_atr;
}

public get avgPayoutMining(): bigint {
return this.instance.avg_payout_mining;
}

}
7 changes: 4 additions & 3 deletions saito-wasm/src/saitowasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,13 +1150,14 @@ pub async fn write_issuance_file(threshold: Currency) {
}

#[wasm_bindgen]
pub async fn disable_bundling_blocks_by_timer() {
pub async fn disable_producing_blocks_by_timer() {
let mut saito = SAITO.lock().await;
saito
.as_mut()
.unwrap()
.consensus_thread
.produce_blocks_by_timer = false;
// saito.as_mut().unwrap().mining_thread.enabled = true;
}
#[wasm_bindgen]
pub async fn produce_block_with_gt() {
Expand Down Expand Up @@ -1189,7 +1190,7 @@ pub async fn produce_block_with_gt() {
.as_mut()
.unwrap()
.consensus_thread
.produce_block(timestamp)
.produce_block(timestamp, true)
.await;
}

Expand All @@ -1206,7 +1207,7 @@ pub async fn produce_block_without_gt() {
.as_mut()
.unwrap()
.consensus_thread
.produce_block(timestamp)
.produce_block(timestamp, true)
.await;
}

Expand Down
10 changes: 10 additions & 0 deletions saito-wasm/src/wasm_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ impl WasmBlock {
pub fn fee_transaction_index(&self) -> u64 {
self.block.fee_transaction_index
}

#[wasm_bindgen(getter = total_payout_atr)]
pub fn total_payout_atr(&self) -> u64 {
self.block.total_payout_atr
}

#[wasm_bindgen(getter = avg_payout_mining)]
pub fn avg_payout_mining(&self) -> u64 {
self.block.avg_payout_mining
}
}

impl WasmBlock {
Expand Down

0 comments on commit e186241

Please sign in to comment.