Skip to content

Commit

Permalink
Merge branch 'development' into core-ban-peer-for-advertising-incorre…
Browse files Browse the repository at this point in the history
…ct-chain-metadata

* development: (32 commits)
  test: improve cucumber with wallets (tari-project#3507)
  feat: optimize pending transactions inbound query (tari-project#3500)
  test: add trace logs to wallet's base node monitor (tari-project#3502)
  fix: improve test Wallet should display transactions made (tari-project#3501)
  test: change timeouts in ci to reasonable values (tari-project#3494)
  fix: correct panic in tracing for comms (tari-project#3499)
  feat: optimize get transactions query (tari-project#3496)
  fix: fix config file whitespace issue when auto generated in windows (tari-project#3491)
  bump to rerun tests
  fix: improve responsiveness of wallet base node switching (tari-project#3488)
  feat: add decay_params method (tari-project#3454)
  Revert "macos-11"
  macos-11
  clean
  remove scripts after install
  install to tmp then use script to copy to home
  wip
  wip
  path
  wip
  ...
  • Loading branch information
sdbondi committed Oct 28, 2021
2 parents 62c9b3e + 45eb940 commit de00313
Show file tree
Hide file tree
Showing 45 changed files with 1,165 additions and 4,694 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

defaults:
rust_image: &rust_image quay.io/tarilabs/rust_tari-build-with-deps:nightly-2021-08-17
rust_image: &rust_image quay.io/tarilabs/rust_tari-build-with-deps:nightly-2021-08-18

commands:
test:
Expand Down
2 changes: 1 addition & 1 deletion .github/wip_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-08-17
toolchain: nightly-2021-08-18
components: clippy, rustfmt
override: true
- name: dependencies
Expand Down
44 changes: 41 additions & 3 deletions .github/workflows/base_node_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-08-17
toolchain: nightly-2021-08-18
components: rustfmt
override: true

Expand All @@ -87,7 +87,7 @@ jobs:
# sudo apt-get -y upgrade
- name: Install macOS dependencies
if: startsWith(runner.os,'macOS')
run: brew install cmake zip
run: brew install cmake zip coreutils

- name: Install Windows dependencies
if: startsWith(runner.os,'Windows')
Expand Down Expand Up @@ -162,14 +162,52 @@ jobs:
#BINFILE="${TBN_FILENAME}-${VERSION}-${VSHA_SHORT}-${{ matrix.os }}-${{ matrix.target_cpu }}-${{ matrix.features }}${TBN_EXT}"
BINFILE="${TBN_FILENAME}-${VERSION}-${VSHA_SHORT}-${{ matrix.os }}-${{ matrix.target_cpu }}${TBN_EXT}"
echo "BINFILE=${BINFILE}" >> $GITHUB_ENV
echo "Copying files for ${BINFILE} too $(pwd)"
echo "Copying files for ${BINFILE} to $(pwd)"
#cp -v "$GITHUB_WORKSPACE/target/release/${TBN_FILENAME}${TBN_EXT}" "./${BINFILE}"
ls -la "$GITHUB_WORKSPACE/target/release/"
cp -v "$GITHUB_WORKSPACE/target/release/tari_base_node${TBN_EXT}" .
cp -v "$GITHUB_WORKSPACE/target/release/tari_console_wallet${TBN_EXT}" .
cp -v "$GITHUB_WORKSPACE/target/release/tari_merge_mining_proxy${TBN_EXT}" .
cp -v "$GITHUB_WORKSPACE/target/release/tari_mining_node${TBN_EXT}" .
- name: Build the macos pkg
if: startsWith(runner.os,'macOS')
env:
MACOS_KEYCHAIN_PASS: ${{ secrets.MACOS_KEYCHAIN_PASS }}
MACOS_APPLICATION_CERT: ${{ secrets.MACOS_APPLICATION_CERT }}
MACOS_APPLICATION_PASS: ${{ secrets.MACOS_APPLICATION_PASS }}
MACOS_INSTALLER_CERT: ${{ secrets.MACOS_INSTALLER_CERT }}
MACOS_INSTALLER_PASS: ${{ secrets.MACOS_INSTALLER_PASS }}
run: |
echo $MACOS_APPLICATION_CERT | base64 --decode > application.p12
echo $MACOS_INSTALLER_CERT | base64 --decode > installer.p12
security create-keychain -p $MACOS_KEYCHAIN_PASS build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p $MACOS_KEYCHAIN_PASS build.keychain
security import application.p12 -k build.keychain -P $MACOS_APPLICATION_PASS -T /usr/bin/codesign
security import installer.p12 -k build.keychain -P $MACOS_INSTALLER_PASS -T /usr/bin/pkgbuild
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_KEYCHAIN_PASS build.keychain
cd buildtools
./create_osx_install_zip.sh unused nozip
FILES=("tari_base_node" "tari_console_wallet" "tari_mining_node" "tari_merge_mining_proxy")
for FILE in "${FILES[@]}"; do
codesign --force -s "Developer ID Application: Tari Labs, LLC (8XGMD9X2H2)" "/tmp/tari_testnet/runtime/$FILE" -v
codesign --verify --deep --display --verbose=4 "/tmp/tari_testnet/runtime/$FILE"
done
pkgbuild --root /tmp/tari_testnet \
--identifier "com.tarilabs.pkg" \
--version "$VERSION" \
--install-location "/tmp/tari" \
--scripts "/tmp/tari_testnet/scripts" \
--sign "Developer ID Installer: Tari Labs, LLC (8XGMD9X2H2)" \
"${{ github.workspace }}${{ env.TBN_DIST }}/tari-${{ env.VERSION }}.pkg"
- name: Artifact macos pkg
if: startsWith(runner.os,'macOS')
uses: actions/upload-artifact@v2
with:
name: tari-${{ env.VERSION }}.pkg
path: "${{ github.workspace }}${{ env.TBN_DIST }}/tari-${{ env.VERSION }}.pkg"

- name: Build the windows installer
shell: cmd
if: startsWith(runner.os,'Windows')
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-08-17
toolchain: nightly-2021-08-18
components: clippy, rustfmt
override: true
- name: cargo fmt
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-08-17
toolchain: nightly-2021-08-18
components: clippy, rustfmt
override: true

Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
- name: toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-08-17
toolchain: nightly-2021-08-18
components: clippy, rustfmt
override: true

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/libwallet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-08-17
toolchain: nightly-2021-08-18
target: aarch64-apple-ios
components: rustfmt
override: true
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-08-17
toolchain: nightly-2021-08-18
target: x86_64-apple-ios
components: rustfmt
override: true
Expand Down
2 changes: 2 additions & 0 deletions applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ async fn run_node(node_config: Arc<GlobalConfig>, bootstrap: ConfigBootstrap) ->
fn enable_tracing() {
// To run:
// docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 jaegertracing/all-in-one:latest
// To view the UI after starting the container (default):
// http://localhost:16686
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("tari::base_node")
Expand Down
41 changes: 22 additions & 19 deletions applications/tari_console_wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() {
eprintln!("{:?}", exit_code);
error!(
target: LOG_TARGET,
"Exiting with code ({}): {:?}",
"Exiting with code ({:?}): {:?}",
exit_code.as_i32(),
exit_code
);
Expand All @@ -65,6 +65,10 @@ fn main_inner() -> Result<(), ExitCodes> {

let (bootstrap, global_config, _) = init_configuration(ApplicationType::ConsoleWallet)?;

if bootstrap.tracing_enabled {
enable_tracing();
}

info!(
target: LOG_TARGET,
"== {} ({}) ==",
Expand All @@ -91,7 +95,6 @@ fn main_inner() -> Result<(), ExitCodes> {
info!(target: LOG_TARGET, "Default configuration created. Done.");
}

enable_tracing_if_specified(&bootstrap);
// get command line password if provided
let arg_password = bootstrap.password.clone();
let seed_words_file_name = bootstrap.seed_words_file_name.clone();
Expand Down Expand Up @@ -185,21 +188,21 @@ fn get_recovery_master_key(
}
}

fn enable_tracing_if_specified(bootstrap: &ConfigBootstrap) {
if bootstrap.tracing_enabled {
// To run: docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 \
// jaegertracing/all-in-one:latest
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("tari::console_wallet")
.with_tags(vec![KeyValue::new("pid", process::id().to_string()), KeyValue::new("current_exe", env::current_exe().unwrap().to_str().unwrap_or_default().to_owned())])
// TODO: uncomment when using tokio 1
// .install_batch(opentelemetry::runtime::Tokio)
.install_simple()
.unwrap();
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let subscriber = Registry::default().with(telemetry);
tracing::subscriber::set_global_default(subscriber)
.expect("Tracing could not be set. Try running without `--tracing-enabled`");
}
fn enable_tracing() {
// To run:
// docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 jaegertracing/all-in-one:latest
// To view the UI after starting the container (default):
// http://localhost:16686
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("tari::console_wallet")
.with_tags(vec![KeyValue::new("pid", process::id().to_string()), KeyValue::new("current_exe", env::current_exe().unwrap().to_str().unwrap_or_default().to_owned())])
// TODO: uncomment when using tokio 1
// .install_batch(opentelemetry::runtime::Tokio)
.install_simple()
.unwrap();
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let subscriber = Registry::default().with(telemetry);
tracing::subscriber::set_global_default(subscriber)
.expect("Tracing could not be set. Try running without `--tracing-enabled`");
}
79 changes: 79 additions & 0 deletions base_layer/core/src/consensus/emission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,67 @@ impl EmissionSchedule {
EmissionSchedule { initial, decay, tail }
}

/// Utility function to calculate the decay parameters that are provided in [EmissionSchedule::new]. This function
/// is provided as a convenience and for the record, but is kept as a separate step. For performance reasons the
/// parameters are 'hard-coded' as a static array rather than a heap allocation.
///
/// Input : `k`: A string representing a floating point number of (nearly) arbitrary precision, and less than one.
///
/// Returns: An array of powers of negative two when when applied as a shift right and sum operation is equal to
/// (1-k)*n (to 1/2^64 precision).
///
/// None - If k is not a valid floating point number less than one.
pub fn decay_params(k: &str) -> Option<Vec<u8>> {
// Convert string into a vector of digits. e.g. 0.9635 -> [9,6,3,5]
fn frac_vec(n: &str) -> Option<Vec<u8>> {
if !n.starts_with("0.") {
return None;
}
if !n.chars().skip(2).all(|i| ('0'..='9').contains(&i)) {
return None;
}
let arr = n.chars().skip(2).map(|i| i as u8 - 48).collect::<Vec<u8>>();
Some(arr)
}
// Multiply a vector of decimal fractional digits by 2. The bool indicates whether the result was greater than
// one
fn times_two(num: &mut [u8]) -> bool {
let len = num.len();
let mut carry_last = 0u8;
for i in 0..len {
let index = len - 1 - i;
let carry = if num[index] >= 5 { 1 } else { 0 };
num[index] = (2 * num[index]) % 10 + carry_last;
carry_last = carry;
}
carry_last > 0
}

fn is_zero(v: &[u8]) -> bool {
v.iter().all(|i| *i == 0u8)
}

let mut next = frac_vec(k)?;
let mut result = Vec::with_capacity(32);
let mut index = 1u8;
let mut exact = true;
while !is_zero(&next) {
let overflow = times_two(&mut next);
if !overflow {
result.push(index);
}
if index >= 63 {
exact = false;
break;
}
index += 1;
}
if exact {
result.push(index - 1);
}
Some(result)
}

/// Return an iterator over the block reward and total supply. This is the most efficient way to iterate through
/// the emission curve if you're interested in the supply as well as the reward.
///
Expand Down Expand Up @@ -260,4 +321,22 @@ mod test {
assert_eq!(emission.block_reward(), schedule.block_reward(8));
assert_eq!(emission.supply(), schedule.supply_at_block(8))
}

#[test]
fn calc_array() {
assert_eq!(EmissionSchedule::decay_params("1.00"), None);
assert_eq!(EmissionSchedule::decay_params("56345"), None);
assert_eq!(EmissionSchedule::decay_params("0.75").unwrap(), vec![2]);
assert_eq!(EmissionSchedule::decay_params("0.25").unwrap(), vec![1, 2]);
assert_eq!(EmissionSchedule::decay_params("0.5").unwrap(), vec![1]);
assert_eq!(EmissionSchedule::decay_params("0.875").unwrap(), vec![3]);
assert_eq!(EmissionSchedule::decay_params("0.125").unwrap(), vec![1, 2, 3]);
assert_eq!(EmissionSchedule::decay_params("0.64732").unwrap(), vec![
2, 4, 5, 7, 10, 13, 16, 19, 20, 21, 22, 25, 29, 32, 33, 34, 35, 36, 38, 45, 47, 51, 53, 58, 59, 60, 62, 63
]);
assert_eq!(EmissionSchedule::decay_params("0.9999991208182701").unwrap(), vec![
21, 22, 23, 25, 26, 37, 38, 39, 41, 45, 49, 50, 51, 52, 55, 57, 59, 60, 63
]);
assert_eq!(EmissionSchedule::decay_params("0.0").unwrap(), vec![0]);
}
}
2 changes: 1 addition & 1 deletion base_layer/wallet/src/base_node_service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct BaseNodeServiceConfig {
impl Default for BaseNodeServiceConfig {
fn default() -> Self {
Self {
base_node_monitor_refresh_interval: Duration::from_secs(5),
base_node_monitor_refresh_interval: Duration::from_secs(3),
base_node_rpc_pool_size: 10,
request_max_age: Duration::from_secs(60),
event_channel_size: 250,
Expand Down
13 changes: 8 additions & 5 deletions base_layer/wallet/src/base_node_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,21 @@ where T: WalletBackend + 'static
context.spawn_when_ready(move |handles| async move {
let wallet_connectivity = handles.expect_handle::<WalletConnectivityHandle>();

let service = BaseNodeService::new(
let result = BaseNodeService::new(
config,
request_stream,
wallet_connectivity,
event_publisher,
handles.get_shutdown_signal(),
db,
)
.start();
futures::pin_mut!(service);
let _ = service.await;
info!(target: LOG_TARGET, "Wallet Base Node Service shutdown");
.start()
.await;

info!(
target: LOG_TARGET,
"Wallet Base Node Service shutdown with result {:?}", result
);
});

Ok(())
Expand Down
Loading

0 comments on commit de00313

Please sign in to comment.