Skip to content

Commit

Permalink
Merge branch 'main' into fix-actions-indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 11, 2022
2 parents b338dc9 + 6d2c4fb commit de89656
Show file tree
Hide file tree
Showing 84 changed files with 2,051 additions and 483 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
/docker/ @ZcashFoundation/devops-reviewers
cloudbuild.yaml @ZcashFoundation/devops-reviewers
codecov.yml @ZcashFoundation/devops-reviewers
.dockerignore @ZcashFoundation/devops-reviewers
firebase.json @ZcashFoundation/devops-reviewers
katex-header.html @ZcashFoundation/devops-reviewers

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/test-full-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ jobs:
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker logs --follow ${{ env.CONTAINER_NAME }}"
EXIT_CODE=$(\
gcloud compute ssh \
full-sync-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker wait ${{ env.CONTAINER_NAME }}")
exit ${EXIT_CODE}
- name: Get sync height from logs
run: |
SYNC_HEIGHT=""
Expand Down
26 changes: 23 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ jobs:
# this job will take a few hours, because it will do a full rebuild.
- name: Get specific changed files
id: changed-files-specific
uses: tj-actions/changed-files@v18.6
uses: tj-actions/changed-files@v18.7
with:
files: |
zebra-state/**/constants.rs
Expand Down Expand Up @@ -318,7 +318,7 @@ jobs:
echo "::set-output name=zebra_container::$CONTAINER_NAME"
sleep 60
- name: Regenerate stateful disks logs
- name: Regenerate stateful disks
id: sync-to-checkpoint
if: ${{ steps.create-instance.outcome == 'success' }}
run: |
Expand All @@ -328,6 +328,16 @@ jobs:
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker logs --follow ${{ env.ZEBRA_CONTAINER }}"
EXIT_CODE=$(\
gcloud compute ssh \
regenerate-disk-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker wait ${{ env.ZEBRA_CONTAINER }}")
exit ${EXIT_CODE}
env:
ZEBRA_CONTAINER: ${{ steps.get-container-name.outputs.zebra_container }}

Expand Down Expand Up @@ -449,7 +459,7 @@ jobs:
echo "::set-output name=zebra_container::$CONTAINER_NAME"
sleep 60
- name: Sync past mandatory checkpoint logs
- name: Sync past mandatory checkpoint
id: sync-past-checkpoint
run: |
gcloud compute ssh \
Expand All @@ -458,6 +468,16 @@ jobs:
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker logs --follow ${{ env.ZEBRA_CONTAINER }}"
EXIT_CODE=$(\
gcloud compute ssh \
sync-checkpoint-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \
--zone ${{ env.ZONE }} \
--quiet \
--ssh-flag="-o ServerAliveInterval=5" \
--command="docker wait ${{ env.ZEBRA_CONTAINER }}")
exit ${EXIT_CODE}
env:
ZEBRA_CONTAINER: ${{ steps.get-container-name.outputs.zebra_container }}

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

File renamed without changes.
73 changes: 28 additions & 45 deletions zebra-chain/src/transparent/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ use ripemd160::{Digest, Ripemd160};
use secp256k1::PublicKey;
use sha2::Sha256;

#[cfg(test)]
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*};

use crate::{
parameters::Network,
serialization::{SerializationError, ZcashDeserialize, ZcashSerialize},
transparent::Script,
};

use super::Script;
#[cfg(test)]
use proptest::prelude::*;

/// Magic numbers used to identify what networks Transparent Addresses
/// are associated with.
Expand All @@ -41,7 +40,11 @@ mod magics {
/// to a Bitcoin address just by removing the "t".)
///
/// https://zips.z.cash/protocol/protocol.pdf#transparentaddrencoding
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(
any(test, feature = "proptest-impl"),
derive(proptest_derive::Arbitrary)
)]
pub enum Address {
/// P2SH (Pay to Script Hash) addresses
PayToScriptHash {
Expand Down Expand Up @@ -208,6 +211,26 @@ impl Address {
}
}

/// Returns the network for this address.
pub fn network(&self) -> Network {
match *self {
Address::PayToScriptHash { network, .. } => network,
Address::PayToPublicKeyHash { network, .. } => network,
}
}

/// Returns the hash bytes for this address, regardless of the address type.
///
/// # Correctness
///
/// Use [`ZcashSerialize`] and [`ZcashDeserialize`] for consensus-critical serialization.
pub fn hash_bytes(&self) -> [u8; 20] {
match *self {
Address::PayToScriptHash { script_hash, .. } => script_hash,
Address::PayToPublicKeyHash { pub_key_hash, .. } => pub_key_hash,
}
}

/// A hash of a transparent address payload, as used in
/// transparent pay-to-script-hash and pay-to-publickey-hash
/// addresses.
Expand All @@ -224,46 +247,6 @@ impl Address {
}
}

#[cfg(test)]
impl Address {
fn p2pkh_strategy() -> impl Strategy<Value = Self> {
(any::<Network>(), vec(any::<u8>(), 20))
.prop_map(|(network, payload_bytes)| {
let mut bytes = [0; 20];
bytes.copy_from_slice(payload_bytes.as_slice());
Self::PayToPublicKeyHash {
network,
pub_key_hash: bytes,
}
})
.boxed()
}

fn p2sh_strategy() -> impl Strategy<Value = Self> {
(any::<Network>(), vec(any::<u8>(), 20))
.prop_map(|(network, payload_bytes)| {
let mut bytes = [0; 20];
bytes.copy_from_slice(payload_bytes.as_slice());
Self::PayToScriptHash {
network,
script_hash: bytes,
}
})
.boxed()
}
}

#[cfg(test)]
impl Arbitrary for Address {
type Parameters = ();

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
prop_oneof![Self::p2pkh_strategy(), Self::p2sh_strategy(),].boxed()
}

type Strategy = BoxedStrategy<Self>;
}

#[cfg(test)]
mod tests {

Expand Down
6 changes: 6 additions & 0 deletions zebra-chain/src/transparent/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ use crate::{
pub struct Utxo {
/// The output itself.
pub output: transparent::Output,

// TODO: replace the height and from_coinbase fields with OutputLocation,
// and provide lookup/calculation methods for height and from_coinbase
//
/// The height at which the output was created.
pub height: block::Height,
/// Whether the output originated in a coinbase transaction.
Expand All @@ -35,6 +39,8 @@ pub struct Utxo {
any(test, feature = "proptest-impl"),
derive(proptest_derive::Arbitrary)
)]
//
// TODO: after modifying UTXO to contain an OutputLocation, replace this type with UTXO
pub struct OrderedUtxo {
/// An unspent transaction output.
pub utxo: Utxo,
Expand Down
4 changes: 2 additions & 2 deletions zebra-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ dirs = "4.0.0"
displaydoc = "0.2.3"
futures = "0.3.21"
hex = "0.4.3"
itertools = "0.10.3"
lazy_static = "1.4.0"
metrics = "0.17.1"
mset = "0.1.0"
proptest = { version = "0.10.1", optional = true }
proptest-derive = { version = "0.3.0", optional = true }
regex = "1.5.5"
rlimit = "0.7.0"
rlimit = "0.8.3"
rocksdb = "0.18.0"
serde = { version = "1.0.136", features = ["serde_derive"] }
tempfile = "3.3.0"
Expand All @@ -35,7 +36,6 @@ zebra-test = { path = "../zebra-test/", optional = true }

[dev-dependencies]
color-eyre = "0.6.0"
itertools = "0.10.3"
once_cell = "1.10.0"
spandoc = "0.2.1"

Expand Down
2 changes: 1 addition & 1 deletion zebra-state/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub use zebra_chain::transparent::MIN_TRANSPARENT_COINBASE_MATURITY;
pub const MAX_BLOCK_REORG_HEIGHT: u32 = MIN_TRANSPARENT_COINBASE_MATURITY - 1;

/// The database format version, incremented each time the database format changes.
pub const DATABASE_FORMAT_VERSION: u32 = 14;
pub const DATABASE_FORMAT_VERSION: u32 = 18;

/// The maximum number of blocks to check for NU5 transactions,
/// before we assume we are on a pre-NU5 legacy chain.
Expand Down
8 changes: 2 additions & 6 deletions zebra-state/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use zebra_chain::{
value_balance::{ValueBalance, ValueBalanceError},
};

// Allow *only* this unused import, so that rustdoc link resolution
// will work with inline links.
/// Allow *only* this unused import, so that rustdoc link resolution
/// will work with inline links.
#[allow(unused_imports)]
use crate::Response;

Expand Down Expand Up @@ -119,10 +119,6 @@ pub struct FinalizedBlock {
/// New transparent outputs created in this block, indexed by
/// [`Outpoint`](transparent::Outpoint).
///
/// Each output is tagged with its transaction index in the block.
/// (The outputs of earlier transactions in a block can be spent by later
/// transactions.)
///
/// Note: although these transparent outputs are newly created, they may not
/// be unspent, since a later transaction in a block can spend outputs of an
/// earlier transaction.
Expand Down
7 changes: 6 additions & 1 deletion zebra-state/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,12 @@ impl StateService {
.or_else(|| self.disk.db().height(hash))
}

/// Return the [`Utxo`] pointed to by `outpoint` if it exists in any chain.
/// Return the [`Utxo`] pointed to by `outpoint`, if it exists in any chain,
/// or in any pending block.
///
/// Some of the returned UTXOs may be invalid, because:
/// - they are not in the best chain, or
/// - their block fails contextual validation.
pub fn any_utxo(&self, outpoint: &transparent::OutPoint) -> Option<transparent::Utxo> {
self.mem
.any_utxo(outpoint)
Expand Down
Loading

0 comments on commit de89656

Please sign in to comment.