Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transaction downloader and verifier #2679

Merged
merged 19 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1eb5720
Add transaction downloader
conradoplg Aug 26, 2021
5f2e744
Changed mempool downloader to be like inbound
conradoplg Aug 27, 2021
8cc6eef
Verifier working (logs result)
conradoplg Aug 27, 2021
345c86d
Apply suggestions from code review
conradoplg Aug 30, 2021
033bb28
Apply suggestions from code review
conradoplg Aug 30, 2021
37ddeb0
Fix coinbase check for mempool, improve is_coinbase() docs
conradoplg Aug 30, 2021
8da4f40
Change other downloads.rs docs to reflect the mempool downloads.rs ch…
conradoplg Aug 30, 2021
a68bf1c
Change TIMEOUTs to downloads.rs; add docs
conradoplg Aug 30, 2021
91e8cfe
Merge remote-tracking branch 'origin/main' into transaction-sync-veri…
conradoplg Aug 30, 2021
5e4488a
Merge branch 'main' into transaction-sync-verifier
conradoplg Aug 30, 2021
315eaf5
Renamed is_coinbase() to has_valid_coinbase_transaction_inputs() and …
conradoplg Aug 31, 2021
bc5fc1f
Merge remote-tracking branch 'origin/main' into transaction-sync-veri…
conradoplg Aug 31, 2021
d90463c
Validate network upgrade for V4 transactions; check before computing …
conradoplg Aug 31, 2021
a3b73f5
Add block_ prefix to downloads and verifier
conradoplg Aug 31, 2021
930ea62
Merge remote-tracking branch 'origin/main' into transaction-sync-veri…
conradoplg Aug 31, 2021
1b01f3c
Update zebra-consensus/src/transaction.rs
conradoplg Sep 1, 2021
6969c31
Add consensus doc; add more Block prefixes
conradoplg Sep 1, 2021
647bcd8
Merge remote-tracking branch 'origin/main' into transaction-sync-veri…
conradoplg Sep 1, 2021
8b06f6d
Merge branch 'main' into transaction-sync-verifier
teor2345 Sep 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 207 additions & 0 deletions grafana/transaction_verification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
{
"__inputs": [
{
"name": "DS_PROMETHEUS-ZEBRA",
"label": "Prometheus-Zebra",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "8.1.2"
},
{
"type": "panel",
"id": "graph",
"name": "Graph (old)",
"version": ""
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": null,
"iteration": 1630092146360,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 0
},
"hiddenSeries": false,
"id": 6,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "8.1.2",
"pointradius": 2,
"points": false,
"renderer": "flot",
"repeatDirection": "h",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"exemplar": true,
"expr": "rate(gossip_downloaded_transaction_count{job=\"$job\"}[1m]) * 60",
"interval": "",
"legendFormat": "gossip_downloaded_transaction_count per min",
"refId": "C"
},
{
"exemplar": true,
"expr": "rate(gossip_verified_transaction_count{job=\"$job\"}[1m]) * 60",
"interval": "",
"legendFormat": "gossip_verified_transaction_count per min",
"refId": "D"
},
{
"exemplar": true,
"expr": "gossip_queued_transaction_count{job=\"$job\"}",
"interval": "",
"legendFormat": "gossip_queued_transaction_count",
"refId": "E"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Transaction Verifier Gossip Count - $job",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"refresh": "5s",
"schemaVersion": 30,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"allValue": null,
"current": {},
"datasource": "${DS_PROMETHEUS-ZEBRA}",
"definition": "label_values(zcash_chain_verified_block_height, job)",
"description": null,
"error": null,
"hide": 0,
"includeAll": true,
"label": null,
"multi": true,
"name": "job",
"options": [],
"query": {
"query": "label_values(zcash_chain_verified_block_height, job)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 1,
"tagValuesQuery": "",
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-30m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "transaction verification",
"uid": "oBEHvS4nz",
"version": 2
}
7 changes: 4 additions & 3 deletions zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,9 @@ impl Transaction {
}
}

/// Returns `true` if this transaction is a coinbase transaction.
pub fn is_coinbase(&self) -> bool {
/// Returns `true` if this transaction has valid inputs for a coinbase
/// transaction, that is, has a single input and it is a coinbase input.
pub fn has_valid_coinbase_transaction_inputs(&self) -> bool {
self.inputs().len() == 1
&& matches!(
self.inputs().get(0),
Expand All @@ -386,7 +387,7 @@ impl Transaction {
}

/// Returns `true` if transaction contains any coinbase inputs.
pub fn contains_coinbase_input(&self) -> bool {
pub fn has_any_coinbase_inputs(&self) -> bool {
self.inputs()
.iter()
.any(|input| matches!(input, transparent::Input::Coinbase { .. }))
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl Transaction {
&mut self,
outputs: &HashMap<transparent::OutPoint, transparent::Output>,
) -> Result<Amount<NonNegative>, ValueBalanceError> {
if self.is_coinbase() {
if self.has_valid_coinbase_transaction_inputs() {
// TODO: if needed, fixup coinbase:
// - miner subsidy
// - founders reward or funding streams (hopefully not?)
Expand Down
11 changes: 10 additions & 1 deletion zebra-chain/src/transaction/unmined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! unmined transactions. They can be used to handle transactions regardless of version,
//! and get the [`WtxId`] or [`Hash`] when required.

use std::sync::Arc;
use std::{fmt, sync::Arc};

#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;
Expand Down Expand Up @@ -93,6 +93,15 @@ impl From<&WtxId> for UnminedTxId {
}
}

impl fmt::Display for UnminedTxId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Legacy(hash) => hash.fmt(f),
Witnessed(id) => id.fmt(f),
}
}
}

impl UnminedTxId {
/// Create a new `UnminedTxId` using a v1-v4 legacy transaction ID.
///
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transparent/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub(crate) fn new_transaction_ordered_outputs(
) -> HashMap<transparent::OutPoint, OrderedUtxo> {
let mut new_ordered_outputs = HashMap::new();

let from_coinbase = transaction.is_coinbase();
let from_coinbase = transaction.has_valid_coinbase_transaction_inputs();
for (output_index_in_transaction, output) in transaction.outputs().iter().cloned().enumerate() {
let output_index_in_transaction = output_index_in_transaction
.try_into()
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/block/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub fn coinbase_is_first(block: &Block) -> Result<(), BlockError> {
.get(0)
.ok_or(BlockError::NoTransactions)?;
let mut rest = block.transactions.iter().skip(1);
if !first.is_coinbase() {
if !first.has_valid_coinbase_transaction_inputs() {
return Err(TransactionError::CoinbasePosition)?;
}
if rest.any(|tx| tx.contains_coinbase_input()) {
if rest.any(|tx| tx.has_any_coinbase_inputs()) {
return Err(TransactionError::CoinbaseAfterFirst)?;
}

Expand Down
3 changes: 3 additions & 0 deletions zebra-consensus/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum TransactionError {
#[error("coinbase transaction MUST NOT have the EnableSpendsOrchard flag set")]
CoinbaseHasEnableSpendsOrchard,

#[error("coinbase inputs MUST NOT exist in mempool")]
CoinbaseInMempool,

#[error("coinbase transaction failed subsidy validation")]
Subsidy(#[from] SubsidyError),

Expand Down
2 changes: 1 addition & 1 deletion zebra-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod config;
mod parameters;
mod primitives;
mod script;
mod transaction;
pub mod transaction;

pub mod chain;
#[allow(missing_docs)]
Expand Down
Loading