Skip to content

Commit 0d0b94b

Browse files
committed
feat: add instrumentation feature
This feature adds `tracing::instrument` to various functions in snarkVM.
1 parent 0f001be commit 0d0b94b

File tree

14 files changed

+204
-178
lines changed

14 files changed

+204
-178
lines changed

Cargo.lock

Lines changed: 104 additions & 159 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ locktick = [
143143
"snarkvm-parameters?/locktick",
144144
"snarkvm-synthesizer?/locktick"
145145
]
146+
instrumentation = [ "snarkvm-ledger/instrumentation" ]
146147
noconfig = [ ]
147148
rocks = [ "snarkvm-ledger/rocks", "snarkvm-synthesizer/rocks" ]
148149
test = [ "snarkvm-ledger/test" ]

README.md

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
## Table of Contents
1414

1515
* [1. Overview](#1-overview)
16-
* [2. Build Guide](#2-build-guide)
17-
* [3. Contributors](#3-contributors)
18-
* [4. License](#4-license)
16+
* [2. Usage Guide](#2-usage-guide)
17+
* [3. Build Guide](#3-build-guide)
18+
* [4. Contributors](#4-contributors)
19+
* [5. License](#5-license)
1920

2021
## 1. Overview
2122

@@ -35,9 +36,51 @@
3536

3637
For more information, visit [Welcome to Aleo](https://github.com/AleoNet/welcome) to get started.
3738

38-
## 2. Build Guide
39+
## 2. Usage Guide
3940

40-
### 2.1 Install Rust
41+
snarkVM is primarily designed to be used as a library in Rust projects. Add it to your `Cargo.toml` with your favourite published version:
42+
43+
```toml
44+
[dependencies]
45+
snarkvm = "<major>.<minor>.<patch>"
46+
```
47+
48+
### 2.1 Feature Flags
49+
50+
The following is an (incomplete) list of features flags in the snarkVM crate.
51+
52+
* **cuda** -
53+
Allows some operations to run on the (NVidia) GPU, instead of on the CPU.
54+
* **cli** -
55+
Enables the command-line interface. Needed when installing the `snarkvm` binary.
56+
* **locktick** -
57+
This feature turns on code for detecting deadlocks.
58+
* **test_targets** -
59+
This feature allows the lowering of coinbase and proof targets for testing.
60+
* **instrumentation** -
61+
Adds `tracing::instrument` statements to (some) functions. This is useful for profiling, but should not be used in production.
62+
* **serial** -
63+
*Disables* paralle processing using `rayon`.
64+
* **algorithms** -
65+
Adds the `algorithms` crate to `snarkvm` (as `snarkvm::algorithms`)
66+
* **circuit** -
67+
Adds the `circuit` crate to `snarkvm` (as `snarkvm::circuit`)
68+
* **fields** -
69+
Adds the `fields` crate to `snarkvm` (as `snarkvm::fields`)
70+
* **ledger** -
71+
Adds the `ledger` crate to `snarkvm` (as `snarkvm::ledger`)
72+
* **synthesizer** -
73+
Adds the `synthesizer` crate to `snarkvm` (as `snarkvm::synthesizer`)
74+
* **parameters** -
75+
Adds the `parameters` crate to `snarkvm` (as `snarkvm::parameters`)
76+
* **wasm** -
77+
Enables behavior specific for WebAssembly. This feature should only be enabled when compiling to the `wasm32` architecture.
78+
79+
### 3. Building Guide
80+
81+
You can also build snarkVM from source. Because snarkVM is a library, this follwing guide is only useful if you plan to make modifications to its source code.
82+
83+
### 3.1 Install Rust
4184

4285
We recommend installing Rust using [rustup](https://www.rustup.rs/). You can install `rustup` as follows:
4386

@@ -49,30 +92,34 @@ We recommend installing Rust using [rustup](https://www.rustup.rs/). You can ins
4992
- Windows (64-bit):
5093

5194
Download the [Windows 64-bit executable](https://win.rustup.rs/x86_64) or
52-
[Windows 32-bit executable](https://win.rustup.rs/i686) and follow the on-screen instructions.
95+
[Windows 32-bit executable](https://win.rustup.rs/i686) and follow the on-screen instructions.i
5396

54-
### 2.2 Using snarkVM as a Library
97+
### 3.2 Additional Dependencies
5598

56-
snarkVM is primarily designed to be used as a library in Rust projects. Add it to your `Cargo.toml` with your favourite published version:
99+
On Linux, you also need the `lld` linker. For example, on a Debian system you would run the following to install it.
57100

58-
```toml
59-
[dependencies]
60-
snarkvm = "<major>.<minor>.<patch>"
101+
```
102+
sudo apt install lld
61103
```
62104

63-
### 2.3 Build from Source Code
105+
### 3.3 Fetch Source Code
64106

65-
You can also build snarkVM from source:
107+
The following snippet clones the `staging` branch of snarkVM.
66108

67109
```bash
68-
# Fetch the repository's development (staging) branch
69110
git clone --branch staging --single-branch https://github.com/ProvableHQ/snarkVM.git
70111
cd snarkVM
71-
# Build the library
112+
```
113+
114+
### 3.4 Compiling snarkVM
115+
116+
The following compiles the snarkVM crate.
117+
118+
```
72119
cargo build --release
73120
```
74121

75-
## 3. Contributors
122+
## 4. Contributors
76123

77124
Thank you for helping make snarkVM better!
78125
[🧐 What do the emojis mean?](https://allcontributors.org/docs/en/emoji-key)
@@ -154,6 +201,6 @@ Thank you for helping make snarkVM better!
154201

155202
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
156203

157-
## 4. License
204+
## 5. License
158205

159206
[![License: GPL v3](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE.md)

ledger/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ serial = [
5757
"snarkvm-ledger-store/serial",
5858
"snarkvm-synthesizer/serial"
5959
]
60+
instrumentation = [
61+
"snarkvm-synthesizer/instrumentation",
62+
"snarkvm-ledger-block/instrumentation",
63+
"snarkvm-ledger-store/instrumentation"
64+
]
6065
test = [
6166
"snarkvm-console/test",
6267
"snarkvm-ledger-block/test",

ledger/block/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ wasm = [
3434
"snarkvm-synthesizer-program/wasm",
3535
"snarkvm-synthesizer-snark/wasm"
3636
]
37+
instrumentation = [ "dep:tracing" ]
3738
test = [ "snarkvm-synthesizer-process/test" ]
3839

3940
[dependencies.snarkvm-console]
@@ -76,6 +77,10 @@ version = "1"
7677
workspace = true
7778
features = [ "serde" ]
7879

80+
[dependencies.tracing]
81+
workspace = true
82+
optional = true
83+
7984
[dependencies.rayon]
8085
workspace = true
8186

ledger/block/src/verify.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rayon::prelude::*;
2727

2828
impl<N: Network> Block<N> {
2929
/// Ensures the block is correct.
30+
#[cfg_attr(feature = "instrumentation", tracing::instrument(skip_all))]
3031
pub fn verify(
3132
&self,
3233
previous_block: &Block<N>,

ledger/src/advance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
9292
}
9393

9494
/// Adds the given block as the next block in the ledger.
95+
#[cfg_attr(feature = "instrumentation", tracing::instrument(skip_all))]
9596
pub fn advance_to_next_block(&self, block: &Block<N>) -> Result<()> {
9697
// Acquire the write lock on the current block.
9798
let mut current_block = self.current_block.write();

ledger/src/check_next_block.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::narwhal::BatchHeader;
1919

2020
impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
2121
/// Checks the given block is valid next block.
22+
#[cfg_attr(feature = "instrumentation", tracing::instrument(skip(self, block, pending_blocks)))]
2223
pub fn check_next_block<R: CryptoRng + Rng>(&self, block: &Block<N>, rng: &mut R) -> Result<()> {
2324
let height = block.height();
2425
let latest_block = self.latest_block();
@@ -154,6 +155,7 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
154155
///
155156
/// This does not verify that the batches are signed correctly or that the edges are valid
156157
/// (only point to the previous round), as those checks already happened when the node received the batch.
158+
#[cfg_attr(feature = "instrumentation", tracing::instrument(skip(self, block, previous_blocks)))]
157159
fn check_block_subdag_leaves(&self, block: &Block<N>) -> Result<()> {
158160
// Check if the block has a subdag.
159161
let Authority::Quorum(subdag) = block.authority() else {
@@ -193,6 +195,9 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
193195
}
194196

195197
/// Check that the certificates in the block subdag have met quorum requirements.
198+
///
199+
/// Called by [`Self::check_block_subdag`]
200+
#[cfg_attr(feature = "instrumentation", tracing::instrument(skip(self, block)))]
196201
fn check_block_subdag_quorum(&self, block: &Block<N>) -> Result<()> {
197202
// Check if the block has a subdag.
198203
let subdag = match block.authority() {

ledger/src/get.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
5050
}
5151

5252
/// Returns the committee lookback for the given round.
53+
#[cfg_attr(feature = "instrumentation", tracing::instrument(skip(self)))]
5354
pub fn get_committee_lookback_for_round(&self, round: u64) -> Result<Option<Committee<N>>> {
5455
// Get the round number for the previous committee. Note, we subtract 2 from odd rounds,
5556
// because committees are updated in even rounds.

ledger/store/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ edition = "2024"
1919
[features]
2020
default = [ "indexmap/rayon" ]
2121
locktick = [ "dep:locktick", "snarkvm-ledger-puzzle/locktick" ]
22-
rocks = [ "rocksdb", "smallvec", "tracing" ]
22+
rocks = [ "dep:rocksdb", "dep:smallvec", "dep:tracing" ]
2323
serial = [
2424
"snarkvm-console/serial",
2525
"snarkvm-ledger-block/serial",
@@ -39,6 +39,7 @@ wasm = [
3939
"snarkvm-synthesizer-snark/wasm"
4040
]
4141
test = [ ]
42+
instrumentation = [ "dep:tracing" ]
4243

4344
[dependencies.snarkvm-console]
4445
workspace = true

0 commit comments

Comments
 (0)