Skip to content

Commit

Permalink
Merge branch 'development' into transcoder_config_update
Browse files Browse the repository at this point in the history
  • Loading branch information
aviator-app[bot] authored Aug 4, 2021
2 parents 06ed848 + 29ba9c4 commit 1564e5f
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 4,882 deletions.
39 changes: 34 additions & 5 deletions applications/tari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ use bitflags::bitflags;
use futures::{stream::Fuse, StreamExt};
use log::*;
use qrcode::{render::unicode, QrCode};
use std::{collections::HashMap, sync::Arc};
use std::{
collections::HashMap,
sync::Arc,
time::{Duration, Instant},
};
use tari_common::{configuration::Network, GlobalConfig};
use tari_comms::{
connectivity::ConnectivityEventRx,
Expand Down Expand Up @@ -72,8 +76,10 @@ const LOG_TARGET: &str = "wallet::console_wallet::app_state";
pub struct AppState {
inner: Arc<RwLock<AppStateInner>>,
cached_data: AppStateData,
cache_update_cooldown: Option<Instant>,
completed_tx_filter: TransactionFilter,
node_config: GlobalConfig,
config: AppStateConfig,
}

impl AppState {
Expand All @@ -91,8 +97,10 @@ impl AppState {
Self {
inner: Arc::new(RwLock::new(inner)),
cached_data,
cache_update_cooldown: None,
completed_tx_filter: TransactionFilter::ABANDONED_COINBASES,
node_config,
config: AppStateConfig::default(),
}
}

Expand Down Expand Up @@ -126,10 +134,18 @@ impl AppState {
}

pub async fn update_cache(&mut self) {
let mut inner = self.inner.write().await;
let updated_state = inner.get_updated_app_state();
if let Some(data) = updated_state {
self.cached_data = data;
let update = match self.cache_update_cooldown {
Some(last_update) => last_update.elapsed() > self.config.cache_update_cooldown,
None => true,
};

if update {
let mut inner = self.inner.write().await;
let updated_state = inner.get_updated_app_state();
if let Some(data) = updated_state {
self.cached_data = data;
self.cache_update_cooldown = Some(Instant::now());
}
}
}

Expand Down Expand Up @@ -897,3 +913,16 @@ bitflags! {
const ABANDONED_COINBASES = 0b0000_0001;
}
}

#[derive(Clone)]
struct AppStateConfig {
pub cache_update_cooldown: Duration,
}

impl Default for AppStateConfig {
fn default() -> Self {
Self {
cache_update_cooldown: Duration::from_secs(2),
}
}
}
5 changes: 5 additions & 0 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,11 @@ where TBackend: OutputManagerBackend + 'static
fees: MicroTari,
block_height: u64,
) -> Result<Transaction, OutputManagerError> {
debug!(
target: LOG_TARGET,
"Building coinbase transaction for block_height {} with TxId: {}", block_height, tx_id
);

let (spending_key, script_key) = self
.resources
.master_key_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,23 @@ where TBackend: TransactionBackend + 'static
let completed_tx = match self.resources.db.get_completed_transaction(self.tx_id).await {
Ok(tx) => tx,
Err(e) => {
error!(
info!(
target: LOG_TARGET,
"Cannot find Completed Transaction (TxId: {}) referred to by this Coinbase Monitoring \
Protocol: {:?}",
self.tx_id,
e
"Cannot find Coinbase Transaction (TxId: {}) likely due to being cancelled: {}", self.tx_id, e
);
return Err(TransactionServiceProtocolError::new(
self.tx_id,
TransactionServiceError::TransactionDoesNotExistError,
));
let _ = self
.resources
.event_publisher
.send(Arc::new(TransactionEvent::TransactionCancelled(self.tx_id)))
.map_err(|e| {
trace!(
target: LOG_TARGET,
"Error sending event, usually because there are no subscribers: {:?}",
e
);
e
});
return Ok(self.tx_id);
},
};
debug!(
Expand Down Expand Up @@ -332,9 +338,7 @@ where TBackend: TransactionBackend + 'static
}
}
}
result = self.query_coinbase_transaction(
signature.clone(), completed_tx.clone(), &mut client
).fuse() => {
result = self.query_coinbase_transaction(signature.clone(), completed_tx.clone(), &mut client).fuse() => {
let (coinbase_kernel_found, metadata) = match result {
Ok(r) => r,
_ => (false, None),
Expand Down
22 changes: 11 additions & 11 deletions integration_tests/features/WalletMonitoring.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ Feature: Wallet Monitoring
And I have mining node MINER2 connected to base node NODE2 and wallet WALLET2

When I co-mine <numBlocks> blocks via merge mining proxy PROXY1 and mining node MINER2
Then node NODE1 is at the same height as node NODE2
Then node SEED_A is at the same height as node NODE1
# This wait is here to give a chance for re-orgs to settle out
Then I wait 30 seconds
Then all nodes are on the same chain at height <numBlocks>

And mining node MINER_SEED_A mines 5 blocks
Then all nodes are at the same height as node SEED_A
Then all nodes are on the same chain at height <endBlocks>

When I wait 1 seconds
Then wallets WALLET1,WALLET2 account for all valid spendable coinbase transactions on the blockchain
Then wallets WALLET1,WALLET2 should have <numBlocks> spendable coinbase outputs
@critical
Examples:
| numBlocks |
| 10 |
| 100 |
| numBlocks | endBlocks |
| 10 | 15 |
| 100 | 105 |

@long-running
Examples:
| numBlocks |
| 1000 |
| 4500 |

| numBlocks | endBlocks |
| 1000 | 1005 |
| 4500 | 4505 |
11 changes: 6 additions & 5 deletions integration_tests/features/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ Then(
await this.forEachClientAsync(async (client, name) => {
await waitFor(async () => client.getTipHeight(), height, 115 * 1000);
const currTip = await client.getTipHeader();
console.log("the node is at tip ", currTip);
expect(currTip.height).to.equal(height);
if (!tipHash) {
tipHash = currTip.hash.toString("hex");
Expand Down Expand Up @@ -2517,9 +2518,9 @@ Then(
);

Then(
/wallets ([A-Za-z0-9,]+) account for all valid spendable coinbase transactions on the blockchain/,
/wallets ([A-Za-z0-9,]+) should have (.*) spendable coinbase outputs/,
{ timeout: 610 * 1000 },
async function (wallets) {
async function (wallets, amountOfCoinBases) {
const walletClients = wallets
.split(",")
.map((wallet) => this.getWallet(wallet).getClient());
Expand All @@ -2536,7 +2537,7 @@ Then(
console.log(client.name, "count", count);
spendableCoinbaseCount += count;
}
return spendableCoinbaseCount === this.lastResult;
return spendableCoinbaseCount.toString() === amountOfCoinBases;
},
true,
600 * 1000,
Expand All @@ -2552,10 +2553,10 @@ Then(
"with",
spendableCoinbaseCount,
"being valid and Mined_Confirmed, expected",
this.lastResult,
amountOfCoinBases,
"\n"
);
expect(spendableCoinbaseCount).to.equal(this.lastResult);
expect(spendableCoinbaseCount.toString()).to.equal(amountOfCoinBases);
}
);

Expand Down
7 changes: 5 additions & 2 deletions integration_tests/helpers/mergeMiningProxyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ class MergeMiningProxyClient {
const template = await this.getBlockTemplate();
const block = template.blocktemplate_blob;
// Need to insert a nonce into the template as xmrig would for it to be a valid block.
await this.submitBlock(block);
tipHeight = parseInt(await this.baseNodeClient.getTipHeight());
} while (tipHeight < height);
if (tipHeight >= height) {
break;
}
await this.submitBlock(block);
} while (tipHeight + 1 < height);
return await this.baseNodeClient.getTipHeight();
}
}
Expand Down
6 changes: 4 additions & 2 deletions integration_tests/helpers/transactionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ class TransactionBuilder {
flags: 0,
maturity: 0,
};
let key = Math.floor(Math.random() * 500 + 1);
let key = Math.floor(Math.random() * 500000000000 + 1);
let privateKey = Buffer.from(toLittleEndian(key, 256)).toString("hex");
let scriptKey = Math.floor(Math.random() * 500000000000 + 1);
let scriptPrivateKey = Buffer.from(toLittleEndian(scriptKey, 256)).toString(
"hex"
);
let scriptOffsetPrivateKeyNum = Math.floor(Math.random() * 500 + 1);
let scriptOffsetPrivateKeyNum = Math.floor(
Math.random() * 500000000000 + 1
);
let scriptOffsetPrivateKey = Buffer.from(
toLittleEndian(scriptOffsetPrivateKeyNum, 256)
).toString("hex");
Expand Down
Loading

0 comments on commit 1564e5f

Please sign in to comment.