Skip to content

Commit

Permalink
Merge branch 'main' into transaction-ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed May 6, 2024
2 parents e130bc8 + 5e85631 commit 4384c1c
Show file tree
Hide file tree
Showing 52 changed files with 685 additions and 256 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,15 @@ jobs:
run: cargo +nightly install mdbook mdbook-katex mdbook-mermaid mdbook-linkcheck

- name: Build software guide
run: cd docs/guide && mdbook build

- name: Move software guide to subdirectory
run: |
cd docs/guide
rm -rf firebase-tmp
mkdir firebase-tmp
mv book/html firebase-tmp/${{ github.event.inputs.image_tag || github.ref_name }}
tree firebase-tmp
working-directory: docs/guide
run: mdbook build

- name: Deploy software guide to firebase
uses: w9jds/[email protected]
with:
args: deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: penumbra-guide
PROJECT_PATH: docs/guide

- name: Build protocol spec
Expand Down
24 changes: 7 additions & 17 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,16 @@ jobs:
- name: Install cometbft binary
run: ./deployments/scripts/install-cometbft

- name: Install process-compose
run: >-
sh -c "$(curl --location https://raw.githubusercontent.com/F1bonacc1/process-compose/main/scripts/get-pc.sh)" --
-d -b ~/bin
- name: Run the smoke test suite
run: |
export PATH="$HOME/bin:$PATH"
./deployments/scripts/smoke-test.sh
- name: Display comet logs
if: always()
run: cat deployments/logs/comet.log
- name: Display pd runtime logs
if: always()
run: cat deployments/logs/pd.log
- name: Display pd test logs
- name: Display smoke-test logs
if: always()
run: cat deployments/logs/pd-tests.log
- name: Display pclientd logs
if: always()
run: cat deployments/logs/pclientd.log
- name: Display pcli logs
if: always()
run: cat deployments/logs/pcli.log
env:
TESTNET_RUNTIME: 2m

run: cat deployments/logs/smoke-*.log
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ wallet-next/pwalletd-db.sqlite-wal

*.DS_STORE

book
# mdbook docs builds
docs/*/book/*
# firebase config
.firebase/
# For some reason mdbook dumps this here because the main page is ../README.md
#index.html
# Used for deployments
firebase-tmp/
firebase-debug.log
docs/*/firebase-tmp/

# Nix build output goes here
result
Expand Down
29 changes: 13 additions & 16 deletions crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use auction::AuctionCmd;
use liquidity_position::PositionCmd;
use penumbra_asset::{asset, asset::Metadata, Value, STAKING_TOKEN_ASSET_ID};
use penumbra_dex::{lp::position, swap_claim::SwapClaimPlan};
use penumbra_fee::Fee;
use penumbra_governance::{proposal::ProposalToml, proposal_state::State as ProposalState, Vote};
use penumbra_keys::{keys::AddressIndex, Address};
use penumbra_num::Amount;
Expand Down Expand Up @@ -321,6 +320,9 @@ impl TxCmd {
}

pub async fn exec(&self, app: &mut App) -> Result<()> {
// TODO: use a command line flag to determine the fee token,
// and pull the appropriate GasPrices out of this rpc response,
// the rest should follow
let gas_prices = app
.view
.as_mut()
Expand Down Expand Up @@ -423,6 +425,7 @@ impl TxCmd {
} => {
let input = input.parse::<Value>()?;
let into = asset::REGISTRY.parse_unit(into.as_str()).base();
let fee_tier: FeeTier = (*fee_tier).into();

let fvk = app.config.full_viewing_key.clone();

Expand All @@ -434,20 +437,14 @@ impl TxCmd {
let mut planner = Planner::new(OsRng);
planner
.set_gas_prices(gas_prices.clone())
.set_fee_tier((*fee_tier).into());
// The swap claim requires a pre-paid fee, however gas costs might change in the meantime.
// This shouldn't be an issue, since the planner will account for the difference and add additional
// spends alongside the swap claim transaction as necessary.
//
// Regardless, we apply a gas adjustment factor of 2.0 up-front to reduce the likelihood of
// requiring an additional spend at the time of claim.
//
// Since the swap claim fee needs to be passed in to the planner to build the swap (it is
// part of the `SwapPlaintext`), we can't use the planner to estimate the fee and need to
// call the helper method directly.
let estimated_claim_fee = Fee::from_staking_token_amount(
Amount::from(2u32) * gas_prices.fee(&swap_claim_gas_cost()),
);
.set_fee_tier(fee_tier.into());

// We don't expect much of a drift in gas prices in a few blocks, and the fee tier
// adjustments should be enough to cover it.
let estimated_claim_fee = gas_prices
.fee(&swap_claim_gas_cost())
.apply_tier(fee_tier.into());

planner.swap(input, into.id(), estimated_claim_fee, claim_address)?;

let plan = planner
Expand Down Expand Up @@ -503,7 +500,7 @@ impl TxCmd {
let mut planner = Planner::new(OsRng);
planner
.set_gas_prices(gas_prices)
.set_fee_tier((*fee_tier).into());
.set_fee_tier(fee_tier.into());
let plan = planner
.swap_claim(SwapClaimPlan {
swap_plaintext,
Expand Down
22 changes: 1 addition & 21 deletions crates/bin/pcli/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use anyhow::Context;
use decaf377_rdsa::{Signature, SpendAuth};
use futures::{FutureExt, TryStreamExt};
use penumbra_fee::GasPrices;
use penumbra_governance::ValidatorVoteBody;
use penumbra_proto::{
custody::v1::{AuthorizeValidatorDefinitionRequest, AuthorizeValidatorVoteRequest},
util::tendermint_proxy::v1::tendermint_proxy_service_client::TendermintProxyServiceClient,
view::v1::broadcast_transaction_response::Status as BroadcastStatus,
view::v1::GasPricesRequest,
DomainType,
};
use penumbra_stake::validator::Validator;
use penumbra_transaction::{gas::GasCost, txhash::TransactionId, Transaction, TransactionPlan};
use penumbra_transaction::{txhash::TransactionId, Transaction, TransactionPlan};
use penumbra_view::ViewClient;
use std::future::Future;
use tonic::transport::{Channel, ClientTlsConfig};
Expand All @@ -24,25 +22,7 @@ impl App {
&mut self,
plan: TransactionPlan,
) -> anyhow::Result<TransactionId> {
let gas_prices: GasPrices = self
.view
.as_mut()
.context("view service must be initialized")?
.gas_prices(GasPricesRequest {})
.await?
.into_inner()
.gas_prices
.expect("gas prices must be available")
.try_into()?;
let transaction = self.build_transaction(plan).await?;
let gas_cost = transaction.gas_cost();
let fee = gas_prices.fee(&gas_cost);
assert!(
transaction.transaction_parameters().fee.amount() >= fee,
"paid fee {} must be greater than minimum fee {}",
transaction.transaction_parameters().fee.amount(),
fee
);
self.submit_transaction(transaction).await
}

Expand Down
10 changes: 6 additions & 4 deletions crates/bin/pcli/tests/network_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ const TEST_ASSET: &str = "1020test_usd";
const TIMEOUT_COMMAND_SECONDS: u64 = 20;

// The time to wait before attempting to perform an undelegation claim.
// By default the epoch duration is 100 blocks, the block time is ~500 ms,
// and the number of unbonding epochs is 2.
// The "unbonding_delay" value is specified in blocks, and in the smoke tests,
// block time is set to ~500ms, so we'll take the total number of blocks
// that must elapse and sleep half that many seconds.
static UNBONDING_DURATION: Lazy<Duration> = Lazy::new(|| {
let blocks: f64 = std::env::var("EPOCH_DURATION")
let blocks: f64 = std::env::var("UNBONDING_DELAY")
.unwrap_or("100".to_string())
.parse()
.unwrap();
Duration::from_secs((1.5 * blocks) as u64)
// 0.5 -> 0.6 for comfort, since 500ms is only an estimate.
Duration::from_secs((0.6 * blocks) as u64)
});

/// Import the wallet from seed phrase into a temporary directory.
Expand Down
18 changes: 18 additions & 0 deletions crates/bin/pd/src/testnet/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::testnet::config::{get_testnet_dir, TestnetTendermintConfig, ValidatorKeys};
use anyhow::{Context, Result};
use penumbra_app::params::AppParameters;
use penumbra_asset::{asset, STAKING_TOKEN_ASSET_ID};
use penumbra_fee::genesis::Content as FeeContent;
use penumbra_governance::genesis::Content as GovernanceContent;
use penumbra_keys::{keys::SpendKey, Address};
Expand Down Expand Up @@ -223,7 +224,24 @@ impl TestnetConfig {
compact_block_space_price: gas_price_simple,
verification_price: gas_price_simple,
execution_price: gas_price_simple,
asset_id: *STAKING_TOKEN_ASSET_ID,
},
fixed_alt_gas_prices: vec![
penumbra_fee::GasPrices {
block_space_price: 10 * gas_price_simple,
compact_block_space_price: 10 * gas_price_simple,
verification_price: 10 * gas_price_simple,
execution_price: 10 * gas_price_simple,
asset_id: asset::REGISTRY.parse_unit("gm").id(),
},
penumbra_fee::GasPrices {
block_space_price: 10 * gas_price_simple,
compact_block_space_price: 10 * gas_price_simple,
verification_price: 10 * gas_price_simple,
execution_price: 10 * gas_price_simple,
asset_id: asset::REGISTRY.parse_unit("gn").id(),
},
],
},
},
governance_content: GovernanceContent {
Expand Down
11 changes: 6 additions & 5 deletions crates/core/app/src/action_handler/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use super::AppActionHandler;
mod stateful;
mod stateless;

use self::stateful::{claimed_anchor_is_valid, fee_greater_than_base_fee, fmd_parameters_valid};
use self::stateful::{
claimed_anchor_is_valid, fmd_parameters_valid, tx_parameters_historical_check,
};
use stateless::{
check_memo_exists_if_outputs_absent_if_not, num_clues_equal_to_num_outputs,
valid_binding_signature,
Expand Down Expand Up @@ -56,14 +58,13 @@ impl AppActionHandler for Transaction {
async fn check_historical<S: StateRead + 'static>(&self, state: Arc<S>) -> Result<()> {
let mut action_checks = JoinSet::new();

// TODO: these could be pushed into the action checks and run concurrently if needed

// SAFETY: Transaction parameters (chain id, expiry height, fee) against chain state
// that cannot change during transaction execution.
tx_parameters_historical_check(state.clone(), self).await?;
// SAFETY: anchors are historical data and cannot change during transaction execution.
claimed_anchor_is_valid(state.clone(), self).await?;
// SAFETY: FMD parameters cannot change during transaction execution.
fmd_parameters_valid(state.clone(), self).await?;
// SAFETY: gas prices cannot change during transaction execution.
fee_greater_than_base_fee(state.clone(), self).await?;

// Currently, we need to clone the component actions so that the spawned
// futures can have 'static lifetimes. In the future, we could try to
Expand Down
Loading

0 comments on commit 4384c1c

Please sign in to comment.