Separate expiry and anchor heights

This commit is contained in:
Hanh 2023-02-08 08:06:37 +10:00
parent ec460dc550
commit 880fd98729
4 changed files with 18 additions and 12 deletions

View File

@ -18,6 +18,8 @@ use zcash_primitives::transaction::builder::Progress;
#[allow(dead_code)]
type PaymentProgressCallback = Box<dyn Fn(Progress) + Send + Sync>;
const EXPIRY_HEIGHT_OFFSET: u32 = 50;
pub async fn build_tx_plan(
coin: u8,
account: u32,
@ -39,11 +41,12 @@ pub async fn build_tx_plan(
}
}
let (fvk, checkpoint_height) = {
let (fvk, checkpoint_height, expiry_height) = {
let db = c.db()?;
let AccountData { fvk, .. } = db.get_account_info(account)?;
let checkpoint_height = get_checkpoint_height(&db, last_height, confirmations)?;
(fvk, checkpoint_height)
let latest_height = get_latest_height().await?;
(fvk, checkpoint_height, latest_height + EXPIRY_HEIGHT_OFFSET)
};
let change_address = get_unified_address(coin, account, 7)?;
let context = TxBuilderContext::from_height(coin, checkpoint_height)?;
@ -77,6 +80,7 @@ pub async fn build_tx_plan(
network,
&fvk,
checkpoint_height,
expiry_height,
&context.orchard_anchor,
&utxos,
&orders,

View File

@ -68,8 +68,6 @@ impl TxBuilderContext {
}
}
const EXPIRY_HEIGHT: u32 = 50;
pub fn build_tx(
network: &Network,
skeys: &SecretKeys,
@ -98,7 +96,7 @@ pub fn build_tx(
};
let mut has_orchard = false;
let mut builder = Builder::new(*network, BlockHeight::from_u32(plan.height));
let mut builder = Builder::new(*network, BlockHeight::from_u32(plan.anchor_height));
let anchor: Anchor = orchard::tree::MerkleHashOrchard::from_bytes(&plan.orchard_anchor)
.unwrap()
.into();
@ -202,7 +200,7 @@ pub fn build_tx(
get_prover(),
&mut ctx,
&mut rng,
BlockHeight::from_u32(plan.height),
BlockHeight::from_u32(plan.anchor_height),
None,
)
.unwrap();
@ -212,7 +210,8 @@ pub fn build_tx(
orchard_bundle = Some(orchard_builder.build(rng.clone()).unwrap());
}
let consensus_branch_id = BranchId::for_height(network, BlockHeight::from_u32(plan.height));
let consensus_branch_id =
BranchId::for_height(network, BlockHeight::from_u32(plan.anchor_height));
let version = TxVersion::suggested_for_branch(consensus_branch_id);
let unauthed_tx: TransactionData<zcash_primitives::transaction::Unauthorized> =
@ -220,7 +219,7 @@ pub fn build_tx(
version,
consensus_branch_id,
0,
BlockHeight::from_u32(plan.height + EXPIRY_HEIGHT),
BlockHeight::from_u32(plan.expiry_height),
transparent_bundle,
None,
sapling_bundle,
@ -262,7 +261,7 @@ pub fn build_tx(
version,
consensus_branch_id,
0,
BlockHeight::from_u32(plan.height + EXPIRY_HEIGHT),
BlockHeight::from_u32(plan.expiry_height),
transparent_bundle,
None,
sapling_bundle,

View File

@ -289,7 +289,8 @@ pub fn outputs_for_change(
pub fn build_tx_plan<F: FeeCalculator>(
network: &Network,
fvk: &str,
height: u32,
anchor_height: u32,
expiry_height: u32,
orchard_anchor: &Option<Hash>,
utxos: &[UTXO],
orders: &[Order],
@ -320,7 +321,8 @@ pub fn build_tx_plan<F: FeeCalculator>(
if updated_fee == fee {
let tx_plan = TransactionPlan {
fvk: fvk.to_string(),
height,
anchor_height,
expiry_height,
orchard_anchor: orchard_anchor.unwrap_or(Hash::default()),
spends: notes,
outputs: fills,

View File

@ -128,7 +128,8 @@ pub struct RecipientShort {
#[serde_as]
pub struct TransactionPlan {
pub fvk: String,
pub height: u32,
pub anchor_height: u32,
pub expiry_height: u32,
#[serde(with = "SerHex::<Strict>")]
pub orchard_anchor: Hash,
pub spends: Vec<UTXO>,