Skip to content

Commit

Permalink
Merge branch 'development' into st-val-merge2
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Jun 30, 2022
2 parents 1313005 + 90a5ec3 commit fd2a7c7
Show file tree
Hide file tree
Showing 51 changed files with 735 additions and 599 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dan_layer_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
command: build
args: --release --bin tari_validator_node -Z unstable-options
- name: npm ci
run: cd integration_tests && npm ci && cd node_modules/wallet-grpc-client && npm ci
run: cd integration_tests && npm ci && cd node_modules/wallet-grpc-client && npm install
- name: Run integration tests
run: cd integration_tests && mkdir -p cucumber_output && node_modules/.bin/cucumber-js --profile "non-critical" --tags "@dan and not @broken" --format json:cucumber_output/tests.cucumber --exit --retry 2 --retry-tag-filter "@flaky and not @broken"
- name: Generate report
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ members = [

]
#
#[profile.release]
#debug = true

# Shutdown when panicking so we can see the error, specifically for the wallet
[profile.release]
Expand All @@ -47,3 +45,4 @@ panic = 'abort'
liblmdb-sys = { git = "https://github.com/tari-project/lmdb-rs", tag = "0.7.6-tari.1" }
#pgp = { git = "https://github.com/rpgp/rpgp.git", rev = "21081b6aaaaa5750ab937cfef30bae879a740d23" }
pgp = { git = "https://github.com/tari-project/rpgp.git", rev = "32939dbe86565d5ede769a7907ec42dfdf353849" }

17 changes: 15 additions & 2 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use tari_core::transactions::{
ContractAmendment,
ContractDefinition,
ContractUpdateProposal,
OutputFeatures,
SideChainConsensus,
SideChainFeatures,
TransactionOutput,
Expand Down Expand Up @@ -141,7 +142,13 @@ pub async fn send_tari(
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_transaction(dest_pubkey, amount, fee_per_gram * uT, message)
.send_transaction(
dest_pubkey,
amount,
OutputFeatures::default(),
fee_per_gram * uT,
message,
)
.await
.map_err(CommandError::TransactionServiceError)
}
Expand Down Expand Up @@ -205,7 +212,13 @@ pub async fn send_one_sided(
message: String,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_one_sided_transaction(dest_pubkey, amount, fee_per_gram * uT, message)
.send_one_sided_transaction(
dest_pubkey,
amount,
OutputFeatures::default(),
fee_per_gram * uT,
message,
)
.await
.map_err(CommandError::TransactionServiceError)
}
Expand Down
20 changes: 16 additions & 4 deletions applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,13 @@ impl wallet_server::Wallet for WalletGrpcServer {
(
address,
transaction_service
.send_transaction(pk, amount.into(), fee_per_gram.into(), message)
.send_transaction(
pk,
amount.into(),
OutputFeatures::default(),
fee_per_gram.into(),
message,
)
.await,
)
});
Expand All @@ -467,7 +473,13 @@ impl wallet_server::Wallet for WalletGrpcServer {
(
address,
transaction_service
.send_one_sided_transaction(pk, amount.into(), fee_per_gram.into(), message)
.send_one_sided_transaction(
pk,
amount.into(),
OutputFeatures::default(),
fee_per_gram.into(),
message,
)
.await,
)
});
Expand Down Expand Up @@ -857,8 +869,8 @@ impl wallet_server::Wallet for WalletGrpcServer {
.map_err(|e| Status::internal(e.to_string()))?;

let message = format!("Sidechain state checkpoint for {}", contract_id);
let _ = transaction_service
.submit_transaction(tx_id, transaction, 0.into(), message)
transaction_service
.submit_transaction(tx_id, transaction, 10.into(), message)
.await
.map_err(|e| Status::internal(e.to_string()))?;

Expand Down
19 changes: 15 additions & 4 deletions applications/tari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use tari_comms::{
};
use tari_core::transactions::{
tari_amount::{uT, MicroTari},
transaction_components::OutputFeatures,
weight::TransactionWeight,
};
use tari_crypto::ristretto::RistrettoPublicKey;
Expand Down Expand Up @@ -295,13 +296,18 @@ impl AppState {
Err(_) => EmojiId::str_to_pubkey(public_key.as_str()).map_err(|_| UiError::PublicKeyParseError)?,
};

let output_features = OutputFeatures {
unique_id,
parent_public_key,
..Default::default()
};

let fee_per_gram = fee_per_gram * uT;
let tx_service_handle = inner.wallet.transaction_service.clone();
tokio::spawn(send_transaction_task(
public_key,
MicroTari::from(amount),
unique_id,
parent_public_key,
output_features,
message,
fee_per_gram,
tx_service_handle,
Expand All @@ -327,13 +333,18 @@ impl AppState {
Err(_) => EmojiId::str_to_pubkey(public_key.as_str()).map_err(|_| UiError::PublicKeyParseError)?,
};

let output_features = OutputFeatures {
unique_id,
parent_public_key,
..Default::default()
};

let fee_per_gram = fee_per_gram * uT;
let tx_service_handle = inner.wallet.transaction_service.clone();
tokio::spawn(send_one_sided_transaction_task(
public_key,
MicroTari::from(amount),
unique_id,
parent_public_key,
output_features,
message,
fee_per_gram,
tx_service_handle,
Expand Down
13 changes: 5 additions & 8 deletions applications/tari_console_wallet/src/ui/state/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use tari_common_types::types::PublicKey;
use tari_comms::types::CommsPublicKey;
use tari_core::transactions::tari_amount::MicroTari;
use tari_core::transactions::{tari_amount::MicroTari, transaction_components::OutputFeatures};
use tari_wallet::transaction_service::handle::{TransactionEvent, TransactionSendStatus, TransactionServiceHandle};
use tokio::sync::{broadcast, watch};

Expand All @@ -33,8 +32,7 @@ const LOG_TARGET: &str = "wallet::console_wallet::tasks ";
pub async fn send_transaction_task(
public_key: CommsPublicKey,
amount: MicroTari,
unique_id: Option<Vec<u8>>,
parent_public_key: Option<PublicKey>,
output_features: OutputFeatures,
message: String,
fee_per_gram: MicroTari,
mut transaction_service_handle: TransactionServiceHandle,
Expand All @@ -44,7 +42,7 @@ pub async fn send_transaction_task(
let mut event_stream = transaction_service_handle.get_event_stream();
let mut send_status = TransactionSendStatus::default();
match transaction_service_handle
.send_transaction_or_token(public_key, amount, unique_id, parent_public_key, fee_per_gram, message)
.send_transaction(public_key, amount, output_features, fee_per_gram, message)
.await
{
Err(e) => {
Expand Down Expand Up @@ -102,8 +100,7 @@ pub async fn send_transaction_task(
pub async fn send_one_sided_transaction_task(
public_key: CommsPublicKey,
amount: MicroTari,
unique_id: Option<Vec<u8>>,
parent_public_key: Option<PublicKey>,
output_features: OutputFeatures,
message: String,
fee_per_gram: MicroTari,
mut transaction_service_handle: TransactionServiceHandle,
Expand All @@ -112,7 +109,7 @@ pub async fn send_one_sided_transaction_task(
let _result = result_tx.send(UiTransactionSendStatus::Initiated);
let mut event_stream = transaction_service_handle.get_event_stream();
match transaction_service_handle
.send_one_sided_transaction_or_token(public_key, amount, unique_id, parent_public_key, fee_per_gram, message)
.send_one_sided_transaction(public_key, amount, output_features, fee_per_gram, message)
.await
{
Err(e) => {
Expand Down
4 changes: 3 additions & 1 deletion applications/tari_validator_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ pub struct ValidatorNodeConfig {
pub p2p: P2pConfig,
pub constitution_auto_accept: bool,
/// Constitution polling interval in block height
pub constitution_management_polling_interval: u64,
pub constitution_management_confirmation_time: u64,
pub constitution_management_polling_interval: u64,
pub constitution_management_polling_interval_in_seconds: u64,
pub grpc_address: Option<Multiaddr>,
}

Expand Down Expand Up @@ -116,6 +117,7 @@ impl Default for ValidatorNodeConfig {
constitution_auto_accept: false,
constitution_management_confirmation_time: 20,
constitution_management_polling_interval: 120,
constitution_management_polling_interval_in_seconds: 60,
p2p,
grpc_address: Some("/ip4/127.0.0.1/tcp/18144".parse().unwrap()),
}
Expand Down
43 changes: 31 additions & 12 deletions applications/tari_validator_node/src/contract_worker_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use tari_dan_core::{
WalletClient,
},
storage::{
global::{GlobalDb, GlobalDbMetadataKey},
global::{ContractState, GlobalDb, GlobalDbMetadataKey},
StorageError,
},
workers::ConsensusWorker,
Expand Down Expand Up @@ -134,6 +134,9 @@ impl ContractWorkerManager {
// TODO: Uncomment line to scan from previous block height once we can
// start up asset workers for existing contracts.
// self.load_initial_state()?;
if self.config.constitution_auto_accept {
info!("constitution_auto_accept is true")
}

if !self.config.scan_for_assets {
info!(
Expand All @@ -155,7 +158,7 @@ impl ContractWorkerManager {
next_scan_height
);
tokio::select! {
_ = time::sleep(Duration::from_secs(60)) => {},
_ = time::sleep(Duration::from_secs(self.config.constitution_management_polling_interval_in_seconds)) => {},
_ = &mut self.shutdown => break,
}
continue;
Expand All @@ -170,20 +173,29 @@ impl ContractWorkerManager {
info!(target: LOG_TARGET, "{} new contract(s) found", active_contracts.len());

for contract in active_contracts {
info!(
target: LOG_TARGET,
"Posting acceptance transaction for contract {}", contract.contract_id
);
self.post_contract_acceptance(&contract).await?;
// TODO: Scan for acceptances and once enough are present, start working on the contract
// for now, we start working immediately.
let kill = self.spawn_asset_worker(contract.contract_id, &contract.constitution);
self.active_workers.insert(contract.contract_id, kill);
self.global_db
.save_contract(contract.contract_id, contract.mined_height, ContractState::Pending)?;

if self.config.constitution_auto_accept {
info!(
target: LOG_TARGET,
"Posting acceptance transaction for contract {}", contract.contract_id
);
self.post_contract_acceptance(&contract).await?;

self.global_db
.update_contract_state(contract.contract_id, ContractState::Accepted)?;

// TODO: Scan for acceptances and once enough are present, start working on the contract
// for now, we start working immediately.
let kill = self.spawn_asset_worker(contract.contract_id, &contract.constitution);
self.active_workers.insert(contract.contract_id, kill);
}
}
self.set_last_scanned_block(tip)?;

tokio::select! {
_ = time::sleep(Duration::from_secs(60)) => {},
_ = time::sleep(Duration::from_secs(self.config.constitution_management_polling_interval_in_seconds)) => {},
_ = &mut self.shutdown => break,
}
}
Expand Down Expand Up @@ -234,6 +246,7 @@ impl ContractWorkerManager {
let mut new_contracts = vec![];
for utxo in outputs {
let output = some_or_continue!(utxo.output.into_unpruned_output());
let mined_height = utxo.mined_height;
let sidechain_features = some_or_continue!(output.features.sidechain_features);
let contract_id = sidechain_features.contract_id;
let constitution = some_or_continue!(sidechain_features.constitution);
Expand All @@ -258,12 +271,17 @@ impl ContractWorkerManager {
constitution.acceptance_requirements.acceptance_period_expiry,
tip.height_of_longest_chain
);

self.global_db
.save_contract(contract_id, mined_height, ContractState::Expired)?;

continue;
}

new_contracts.push(ActiveContract {
contract_id,
constitution,
mined_height,
});
}

Expand Down Expand Up @@ -438,4 +456,5 @@ pub enum WorkerManagerError {
struct ActiveContract {
pub contract_id: FixedHash,
pub constitution: ContractConstitution,
pub mined_height: u64,
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use tari_app_grpc::{
tari_rpc as grpc,
tari_rpc::{
CreateFollowOnAssetCheckpointRequest,
CreateInitialAssetCheckpointRequest,
SubmitContractAcceptanceRequest,
SubmitContractUpdateProposalAcceptanceRequest,
},
Expand Down Expand Up @@ -67,18 +68,32 @@ impl WalletClient for GrpcWalletClient {
&mut self,
contract_id: &FixedHash,
state_root: &StateRoot,
is_initial: bool,
) -> Result<(), DigitalAssetError> {
let inner = self.connection().await?;

let request = CreateFollowOnAssetCheckpointRequest {
contract_id: contract_id.to_vec(),
merkle_root: state_root.as_bytes().to_vec(),
};

let _res = inner
.create_follow_on_asset_checkpoint(request)
.await
.map_err(|e| DigitalAssetError::FatalError(format!("Could not create checkpoint:{}", e)))?;
if is_initial {
let request = CreateInitialAssetCheckpointRequest {
contract_id: contract_id.to_vec(),
merkle_root: state_root.as_bytes().to_vec(),
committee: vec![],
};

let _res = inner
.create_initial_asset_checkpoint(request)
.await
.map_err(|e| DigitalAssetError::FatalError(format!("Could not create checkpoint:{}", e)))?;
} else {
let request = CreateFollowOnAssetCheckpointRequest {
contract_id: contract_id.to_vec(),
merkle_root: state_root.as_bytes().to_vec(),
};

let _res = inner
.create_follow_on_asset_checkpoint(request)
.await
.map_err(|e| DigitalAssetError::FatalError(format!("Could not create checkpoint:{}", e)))?;
}

Ok(())
}
Expand Down
Loading

0 comments on commit fd2a7c7

Please sign in to comment.