Skip to content

Commit

Permalink
Merge branch 'testnet-dibbler' into dibbler-merge
Browse files Browse the repository at this point in the history
* testnet-dibbler:
  feat(wallet): allow UTXO selection by specific outputs and by token (tari-project#4227)
  feat(ci): build both x86/arm64 docker images from GHA  (tari-project#4204)
  • Loading branch information
sdbondi committed Jun 23, 2022
2 parents 10613c8 + f2a7e18 commit b8f3343
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 219 deletions.
127 changes: 93 additions & 34 deletions .github/workflows/launchpad_docker.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
name: Build launchpad docker images

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
# branches:
# - development
branches:
- build-gha-docker-*
workflow_dispatch:
inputs:
docker_tag:
description: "Docker tag"
required: true
default: "development"

name: Build launchpad docker images

env:
toolchain: nightly-2021-11-20
CARGO_HTTP_MULTIPLEXING: false
Expand All @@ -26,69 +27,127 @@ jobs:
matrix:
image_name:
[
frontail,
monerod,
tari_base_node,
tari_console_wallet,
tari_mm_proxy,
tari_sha3_miner,
tor,
xmrig,
]
include:
- image_name: tari_base_node
app_name: base_node
app_exec: tari_base_node
- image_name: tari_wallet
app_name: wallet
app_exec: tari_console_wallet
- image_name: tari_mm_proxy
app_name: mm_proxy
app_exec: tari_merge_mining_proxy
- image_name: tari_sha3_miner
app_name: sha3_miner
app_exec: tari_miner

runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: recursive

- name: set env
id: environments
run: |
TAG=""
REF=${{github.ref}}
if [ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]
then
REF=${{github.ref}}
TAG="${REF/refs\/tags\//}"
echo "docker tag from git: $TAG"
else
# Pull App version from file
VAPP=$(awk -F ' = ' \
'$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' \
"${GITHUB_WORKSPACE}/applications/tari_base_node/Cargo.toml")
VBRANCH=$(echo ${GITHUB_REF#refs/heads/})
VSHA_SHORT=$(git rev-parse --short HEAD)
TAG="v${VAPP}_${VBRANCH}_$(date -u '+%Y%m%d')_${VSHA_SHORT}"
echo "docker tag from App Version _ git branch _ \
date stamp _ git short hash: ${TAG}"
fi
echo "event name: ${{ github.event_name }}"
if [ "${{ github.event_name }}" == "workflow_dispatch" ]
then
TAG="${{ github.event.inputs.docker_tag }}"
echo "docker tag from workflow dispatch: $TAG"
fi
echo "TAG=$TAG" >> $GITHUB_ENV
IMAGE=${{ matrix.image_name }}
echo "image: $IMAGE"
TEMP=${IMAGE/tari_/}
# echo "temp: $TEMP"
SERVICE="${TEMP/console_/}"
echo "service: $SERVICE"
echo "SERVICE=$SERVICE" >> $GITHUB_ENV
- name: build docker image
run: |
if [ -z $SERVICE ]
# Setup dockerfile to use
if [ "${IMAGE:0:5}" == "tari_" ]
then
echo "service is undefined!"
exit 1
echo ::set-output name=dockerfile::tarilabs.Dockerfile
# Strip tari_
IMAGE=${IMAGE/tari_/}
# Strip console_
IMAGE=${IMAGE/console_/}
echo ::set-output name=app_name::${IMAGE}
echo ::set-output name=dockercontext::./
else
DOCKERFILE=${IMAGE}.Dockerfile
DOCKERCONTEXT=./applications/launchpad/docker_rig/
# Pull the docker image TAG from dockerfile
SUBTAG=$(awk -F '=' '/ARG .*_VERSION=/ \
{ gsub(/["]/, "", $2); printf("%s",$2) }' \
"${GITHUB_WORKSPACE}/${DOCKERCONTEXT}${DOCKERFILE}")
echo ::set-output name=dockerfile::${DOCKERFILE}
echo ::set-output name=dockercontext::${DOCKERCONTEXT}
if [ ! -z "${SUBTAG}" ]
then
TAG="${SUBTAG}_${TAG}"
echo "Adding subtag: ${TAG}"
fi
fi
cd applications/launchpad/docker_rig
docker-compose build $SERVICE
- name: Login to Quay.io
# Set docker image tag
echo "tag: ${TAG}"
echo ::set-output name=tag::$TAG
- name: Login to Docker Image Provider
uses: docker/login-action@v1
with:
registry: quay.io
registry: ${{ secrets.DOCKER_PROVIDER }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

- name: tag and push image
run: |
echo "tag: $TAG"
if [ -n "$TAG" ]
then
docker tag quay.io/tarilabs/${{ matrix.image_name }}:latest quay.io/tarilabs/${{ matrix.image_name }}:$TAG
- name: Set up QEMU for Docker
uses: docker/setup-qemu-action@v2

docker push quay.io/tarilabs/${{ matrix.image_name }}:latest
docker push quay.io/tarilabs/${{ matrix.image_name }}:$TAG
fi
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Docker image build and push
uses: docker/build-push-action@v3
with:
context: ${{ steps.environments.outputs.dockercontext }}
file: ./applications/launchpad/docker_rig/${{ steps.environments.outputs.dockerfile }}
platforms: linux/arm64, linux/amd64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ steps.environments.outputs.tag }}
APP_NAME=${{ matrix.app_name }}
APP_EXEC=${{ matrix.app_exec }}
tags: |
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ matrix.image_name }}:latest
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ matrix.image_name }}:${{ steps.environments.outputs.tag }}
126 changes: 126 additions & 0 deletions base_layer/wallet/src/output_manager_service/input_selection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2022. The Tari Project
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
// disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// 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 std::{
fmt,
fmt::{Display, Formatter},
};

use tari_common_types::types::PublicKey;

use crate::output_manager_service::storage::models::DbUnblindedOutput;

#[derive(Debug, Clone, Default)]
pub struct UtxoSelectionCriteria {
pub filter: UtxoSelectionFilter,
pub ordering: UtxoSelectionOrdering,
}

impl UtxoSelectionCriteria {
pub fn largest_first() -> Self {
Self {
filter: UtxoSelectionFilter::Standard,
ordering: UtxoSelectionOrdering::LargestFirst,
}
}

pub fn for_token(unique_id: Vec<u8>, parent_public_key: Option<PublicKey>) -> Self {
Self {
filter: UtxoSelectionFilter::TokenOutput {
unique_id,
parent_public_key,
},
ordering: UtxoSelectionOrdering::Default,
}
}
}

impl Display for UtxoSelectionCriteria {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "filter: {}, ordering: {}", self.filter, self.ordering)
}
}

/// UTXO selection ordering
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UtxoSelectionOrdering {
/// The Default ordering is heuristic and depends on the requested value and the value of the available UTXOs.
/// If the requested value is larger than the largest available UTXO, we select LargerFirst as inputs, otherwise
/// SmallestFirst.
Default,
/// Start from the smallest UTXOs and work your way up until the amount is covered. Main benefit
/// is removing small UTXOs from the blockchain, con is that it costs more in fees
SmallestFirst,
/// A strategy that selects the largest UTXOs first. Preferred when the amount is large
LargestFirst,
}

impl Default for UtxoSelectionOrdering {
fn default() -> Self {
UtxoSelectionOrdering::Default
}
}

impl Display for UtxoSelectionOrdering {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
UtxoSelectionOrdering::SmallestFirst => write!(f, "Smallest"),
UtxoSelectionOrdering::LargestFirst => write!(f, "Largest"),
UtxoSelectionOrdering::Default => write!(f, "Default"),
}
}
}

#[derive(Debug, Clone)]
pub enum UtxoSelectionFilter {
/// Select OutputType::Standard or OutputType::Coinbase outputs only
Standard,
/// Select matching token outputs. This will be deprecated in future.
TokenOutput {
unique_id: Vec<u8>,
parent_public_key: Option<PublicKey>,
},
/// Selects specific outputs. All outputs must be exist and be spendable.
SpecificOutputs { outputs: Vec<DbUnblindedOutput> },
}

impl Default for UtxoSelectionFilter {
fn default() -> Self {
UtxoSelectionFilter::Standard
}
}

impl Display for UtxoSelectionFilter {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
UtxoSelectionFilter::Standard => {
write!(f, "Standard")
},
UtxoSelectionFilter::TokenOutput { .. } => {
write!(f, "TokenOutput{{..}}")
},
UtxoSelectionFilter::SpecificOutputs { outputs } => {
write!(f, "Specific({} output(s))", outputs.len())
},
}
}
}
25 changes: 14 additions & 11 deletions base_layer/wallet/src/output_manager_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@
// 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 std::sync::Arc;
pub mod config;
pub mod error;
pub mod handle;

mod input_selection;
pub use input_selection::{UtxoSelectionCriteria, UtxoSelectionFilter, UtxoSelectionOrdering};

mod recovery;
pub mod resources;
pub mod service;
pub mod storage;
mod tasks;

use std::{marker::PhantomData, sync::Arc};

use futures::future;
use log::*;
Expand All @@ -47,16 +60,6 @@ use crate::{
},
};

pub mod config;
pub mod error;
pub mod handle;
mod recovery;
pub mod resources;
pub mod service;
pub mod storage;
mod tasks;
use std::marker::PhantomData;

const LOG_TARGET: &str = "wallet::output_manager_service::initializer";

pub struct OutputManagerServiceInitializer<T, TKeyManagerInterface>
Expand Down
Loading

0 comments on commit b8f3343

Please sign in to comment.