Skip to content

Commit 68bc54d

Browse files
committed
Merge remote-tracking branch 'origin/staging' into feat/tracing-instrument
2 parents 1d3147e + ea28380 commit 68bc54d

File tree

21 files changed

+336
-78
lines changed

21 files changed

+336
-78
lines changed

.circleci/config.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,21 +684,21 @@ jobs:
684684

685685
ledger-with-rocksdb-partition1:
686686
executor: rust-docker
687-
resource_class: << pipeline.parameters.large >>
687+
resource_class: << pipeline.parameters.xlarge >>
688688
steps:
689689
- run_test:
690690
workspace_member: snarkvm-ledger
691-
flags: --release --features=rocks --partition count:1/2 -- --test-threads=8
691+
flags: --release --features=rocks --partition count:1/2 -- --test-threads=10
692692
no_output_timeout: 20m
693693
timeout: 30m
694694

695695
ledger-with-rocksdb-partition2:
696696
executor: rust-docker
697-
resource_class: << pipeline.parameters.large >>
697+
resource_class: << pipeline.parameters.xlarge >>
698698
steps:
699699
- run_test:
700700
workspace_member: snarkvm-ledger
701-
flags: --release --features=rocks --partition count:2/2 -- --test-threads=8
701+
flags: --release --features=rocks --partition count:2/2 -- --test-threads=10
702702
no_output_timeout: 20m
703703
timeout: 30m
704704

@@ -1063,7 +1063,10 @@ jobs:
10631063
name: Check for unused dependencies
10641064
no_output_timeout: 10m
10651065
command: |
1066-
cargo install cargo-machete@0.7.0
1066+
set -euo pipefail
1067+
if ! command -v cargo-machete >/dev/null 2>&1; then
1068+
cargo install cargo-machete@0.7.0 --locked
1069+
fi
10671070
cargo machete
10681071
- clear_environment:
10691072
cache_key: v4.2.0-rust-1.88.0-machete-cache
@@ -1088,7 +1091,8 @@ jobs:
10881091
executor: rust-docker
10891092
resource_class: << pipeline.parameters.twoxlarge >>
10901093
steps:
1091-
- checkout
1094+
- checkout:
1095+
method: full
10921096
- setup_environment:
10931097
cache_key: v4.2.0-rust-1.88.0-cargo-semver-checks-cache
10941098
- run:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

algorithms/src/polycommit/sonic_pc/data_structures.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,11 @@ impl<E: PairingEngine> FromBytes for BatchLCProof<E> {
686686
CanonicalDeserialize::deserialize_compressed(&mut reader)
687687
.map_err(|err| into_io_error(anyhow::Error::from(err).context("could not deserialize struct")))
688688
}
689+
690+
fn read_le_unchecked<R: Read>(mut reader: R) -> io::Result<Self> {
691+
CanonicalDeserialize::deserialize_compressed_unchecked(&mut reader)
692+
.map_err(|err| into_io_error(anyhow::Error::from(err).context("could not deserialize struct")))
693+
}
689694
}
690695

691696
impl<E: PairingEngine> ToBytes for BatchLCProof<E> {

algorithms/src/snark/varuna/data_structures/certificate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ impl<E: PairingEngine> FromBytes for Certificate<E> {
4444
Self::deserialize_compressed(&mut r)
4545
.map_err(|err| into_io_error(anyhow::Error::from(err).context("Failed to deserialize certificate")))
4646
}
47+
48+
fn read_le_unchecked<R: Read>(mut r: R) -> io::Result<Self> {
49+
Self::deserialize_compressed_unchecked(&mut r)
50+
.map_err(|err| into_io_error(anyhow::Error::from(err).context("Failed to deserialize certificate")))
51+
}
4752
}

algorithms/src/snark/varuna/data_structures/circuit_verifying_key.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ impl<E: PairingEngine> FromBytes for CircuitVerifyingKey<E> {
4343
Self::deserialize_compressed(r)
4444
.map_err(|err| into_io_error(anyhow::Error::from(err).context("could not deserialize CircuitVerifyingKey")))
4545
}
46+
47+
fn read_le_unchecked<R: Read>(r: R) -> io::Result<Self> {
48+
Self::deserialize_compressed_unchecked(r)
49+
.map_err(|err| into_io_error(anyhow::Error::from(err).context("could not deserialize CircuitVerifyingKey")))
50+
}
4651
}
4752

4853
impl<E: PairingEngine> ToBytes for CircuitVerifyingKey<E> {

algorithms/src/snark/varuna/data_structures/proof.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ impl<E: PairingEngine> FromBytes for Proof<E> {
379379
Self::deserialize_compressed(&mut r)
380380
.map_err(|err| into_io_error(anyhow::Error::from(err).context("could not deserialize Proof")))
381381
}
382+
383+
fn read_le_unchecked<R: Read>(mut r: R) -> io::Result<Self> {
384+
Self::deserialize_compressed_unchecked(&mut r)
385+
.map_err(|err| into_io_error(anyhow::Error::from(err).context("could not deserialize Proof")))
386+
}
382387
}
383388

384389
/// Computes the size in bytes of a Varuna proof as produced by

ledger/authority/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use console::{
3434
Error,
3535
Formatter,
3636
FromBytes,
37-
FromBytesDeserializer,
37+
FromBytesUncheckedDeserializer,
3838
FromStr,
3939
IoResult,
4040
Read,

ledger/authority/src/serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'de, N: Network> Deserialize<'de> for Authority<N> {
5959
_ => Err(de::Error::custom(error("Invalid authority type"))),
6060
}
6161
}
62-
false => FromBytesDeserializer::<Self>::deserialize_with_size_encoding(deserializer, "authority"),
62+
false => FromBytesUncheckedDeserializer::<Self>::deserialize_with_size_encoding(deserializer, "authority"),
6363
}
6464
}
6565
}

ledger/query/src/query/rest.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<N: Network> RestQuery<N> {
224224
.with_context(|| format!("Failed to fetch from {endpoint}"))?;
225225

226226
if response.status().is_success() {
227-
response.body_mut().read_json().with_context(|| "Failed to parse JSON response")
227+
response.body_mut().read_json().with_context(|| format!("Failed to parse JSON response from {endpoint}"))
228228
} else {
229229
let content_type = response
230230
.headers()
@@ -236,11 +236,16 @@ impl<N: Network> RestQuery<N> {
236236
// Convert returned error into an `anyhow::Error`.
237237
// Depending on the API version, the error is either encoded as a string or as a JSON.
238238
if content_type.contains("json") {
239-
let error: RestError =
240-
response.body_mut().read_json().with_context(|| "Failed to parse JSON error response")?;
239+
let error: RestError = response
240+
.body_mut()
241+
.read_json()
242+
.with_context(|| format!("Failed to parse JSON error response from {endpoint}"))?;
241243
Err(error.parse().context(format!("Failed to fetch from {endpoint}")))
242244
} else {
243-
let error = response.body_mut().read_to_string().with_context(|| "Failed to read error message")?;
245+
let error = response
246+
.body_mut()
247+
.read_to_string()
248+
.with_context(|| format!("Failed to read error message {endpoint}"))?;
244249
Err(anyhow!(error).context(format!("Failed to fetch from {endpoint}")))
245250
}
246251
}
@@ -256,10 +261,13 @@ impl<N: Network> RestQuery<N> {
256261
let response = reqwest::get(&endpoint).await.with_context(|| format!("Failed to fetch from {endpoint}"))?;
257262

258263
if response.status().is_success() {
259-
response.json().await.with_context(|| "Failed to parse JSON response")
264+
response.json().await.with_context(|| format!("Failed to parse JSON response from {endpoint}"))
260265
} else {
261266
// Convert returned error into an `anyhow::Error`.
262-
let error: RestError = response.json().await.with_context(|| "Failed to parse JSON error response")?;
267+
let error: RestError = response
268+
.json()
269+
.await
270+
.with_context(|| format!("Failed to parse JSON error response from {endpoint}"))?;
263271
Err(error.parse().context(format!("Failed to fetch from {endpoint}")))
264272
}
265273
}

ledger/src/test_helpers/chain_builder.rs

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,31 @@ pub struct TestChainBuilder<N: Network> {
6868
}
6969

7070
/// Additional options you can pass to the builder when generating a set of blocks.
71-
#[derive(Clone, Default)]
72-
pub struct GenerateBlocksOptions {
71+
#[derive(Clone)]
72+
pub struct GenerateBlocksOptions<N: Network> {
7373
/// Do not include votes to the previous leader certificate
7474
pub skip_votes: bool,
7575
/// Do not generate certificates for the specific node indices (to simulate a partition).
7676
pub skip_nodes: Vec<usize>,
77+
/// A flag indicating that a number of initial "placeholder blocks" should be baked
78+
/// wthout transactions in order to skip to the latest version of consensus.
79+
pub skip_to_current_version: bool,
80+
/// The number of validators.
81+
pub num_validators: usize,
82+
/// Preloaded transactions to populate the blocks with.
83+
pub transactions: Vec<Transaction<N>>,
84+
}
85+
86+
impl<N: Network> Default for GenerateBlocksOptions<N> {
87+
fn default() -> Self {
88+
Self {
89+
skip_votes: false,
90+
skip_nodes: Default::default(),
91+
skip_to_current_version: false,
92+
num_validators: 0,
93+
transactions: Default::default(),
94+
}
95+
}
7796
}
7897

7998
/// Additional options you can pass to the builder when generating a single block.
@@ -178,7 +197,6 @@ impl<N: Network> TestChainBuilder<N> {
178197
Ok(Self {
179198
private_keys,
180199
ledger,
181-
182200
genesis_block,
183201
last_batch_round: Default::default(),
184202
last_committed_batch_round: Default::default(),
@@ -190,7 +208,9 @@ impl<N: Network> TestChainBuilder<N> {
190208

191209
/// Create multiple blocks, with fully-connected DAGs.
192210
pub fn generate_blocks(&mut self, num_blocks: usize, rng: &mut TestRng) -> Result<Vec<Block<N>>> {
193-
self.generate_blocks_with_opts(num_blocks, GenerateBlocksOptions::default(), rng)
211+
let num_validators = self.private_keys.len();
212+
213+
self.generate_blocks_with_opts(num_blocks, GenerateBlocksOptions { num_validators, ..Default::default() }, rng)
194214
}
195215

196216
/// Create multiple blocks, with additional parameters.
@@ -200,20 +220,53 @@ impl<N: Network> TestChainBuilder<N> {
200220
pub fn generate_blocks_with_opts(
201221
&mut self,
202222
num_blocks: usize,
203-
options: GenerateBlocksOptions,
223+
mut options: GenerateBlocksOptions<N>,
204224
rng: &mut TestRng,
205225
) -> Result<Vec<Block<N>>> {
206226
assert!(num_blocks > 0, "Need to build at least one block");
207227

208-
let options = GenerateBlockOptions {
209-
skip_votes: options.skip_votes,
210-
skip_nodes: options.skip_nodes,
211-
..Default::default()
212-
};
213-
214228
let mut result = vec![];
215-
for _ in 0..num_blocks {
216-
let block = self.generate_block_with_opts(options.clone(), rng)?;
229+
230+
// If configured, skip enough blocks to reach the current consensus version.
231+
if options.skip_to_current_version {
232+
let (version, target_height) = TEST_CONSENSUS_VERSION_HEIGHTS.last().unwrap();
233+
let mut current_height = self.ledger.latest_height();
234+
235+
let diff = target_height.saturating_sub(current_height);
236+
237+
if diff > 0 {
238+
println!("Skipping {diff} blocks to reach {version}");
239+
240+
while current_height < *target_height && result.len() < num_blocks {
241+
let options = GenerateBlockOptions {
242+
skip_votes: options.skip_votes,
243+
skip_nodes: options.skip_nodes.clone(),
244+
..Default::default()
245+
};
246+
247+
let block = self.generate_block_with_opts(options, rng)?;
248+
current_height = block.height();
249+
result.push(block);
250+
}
251+
252+
println!("Advanced to the current consensus version at height {target_height}");
253+
} else {
254+
debug!("Already at the current consensus version. No blocks to skip.");
255+
}
256+
}
257+
258+
while result.len() < num_blocks {
259+
let num_txs = (BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH * options.num_validators)
260+
.min(options.transactions.len());
261+
262+
let options = GenerateBlockOptions {
263+
skip_votes: options.skip_votes,
264+
skip_nodes: options.skip_nodes.clone(),
265+
transactions: options.transactions.drain(..num_txs).collect(),
266+
..Default::default()
267+
};
268+
269+
let block = self.generate_block_with_opts(options, rng)?;
217270
result.push(block);
218271
}
219272

@@ -262,8 +315,6 @@ impl<N: Network> TestChainBuilder<N> {
262315
transmissions.insert(transmission_id, transmission);
263316
}
264317

265-
let transmission_ids: IndexSet<_> = transmissions.keys().copied().collect();
266-
267318
// =======================================
268319
// Create certificates for the new block.
269320
// =======================================
@@ -303,6 +354,13 @@ impl<N: Network> TestChainBuilder<N> {
303354
continue;
304355
}
305356

357+
let transmission_ids: IndexSet<_> = transmissions
358+
.keys()
359+
.skip(key1_idx * BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH)
360+
.take(BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH)
361+
.copied()
362+
.collect();
363+
306364
let batch_header = BatchHeader::new(
307365
private_key_1,
308366
round,
@@ -404,6 +462,7 @@ impl<N: Network> TestChainBuilder<N> {
404462

405463
// Construct the block.
406464
let subdag = Subdag::from(subdag_map).unwrap();
465+
407466
let block = self.ledger.prepare_advance_to_next_quorum_block(subdag, transmissions, rng)?;
408467

409468
// Skip to increase performance.

0 commit comments

Comments
 (0)