Skip to content

Commit 0f24e74

Browse files
authored
Merge branch 'main' into 1207_short_circuit_on_participant_network_partition
2 parents 5778f2e + 38d9984 commit 0f24e74

148 files changed

Lines changed: 726 additions & 884 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ See `docs/engineering-standards.md` for the full rationale and additional testin
120120
### Arithmetic in Tests
121121
Do not suggest using `checked_add`, `checked_mul`, `checked_sub`, `saturating_add`, or similar checked/saturating arithmetic in test code — this includes `#[cfg(test)]` modules, integration test crates, and e2e test crates. Raw arithmetic operators (`+`, `-`, `*`, `/`) are fine in tests — overflow will cause a panic, which is the desired behavior in tests.
122122

123+
### Trait Naming
124+
Traits should model a single capability, and be named after the action, not as an agent noun derived from it: `ReadContractState`, not `ContractStateReader`. This follows std-idiomatic patterns (`From*`/`Into*`/`To*` conversions). This applies to new traits and opportunistic renames, existing traits may deviate from this principle.
125+
126+
See `docs/engineering-standards.md` §Name capability traits after the action for the full rationale and a `Don't` / `Do` example.
127+
123128
### Code Comments
124129
Default to writing no comments. Add one only in case one of the following applies:
125130
- the *why* is non-obvious: an invariant, a constraint, a surprising behavior;
@@ -131,8 +136,12 @@ Avoid comments that are:
131136
- explaining common knowledge or terminology;
132137
- burdening the reader with non-relevant information;
133138

139+
AI-generated code tends to arrive with obvious comments: restating what the next line does, labeling steps (`// setup`, `// send the request`), or narrating the edit that produced the code. Strip these before submitting. Keep a comment only if it says something the code cannot; if a reader can reconstruct it from the names and types on the same screen, delete it. This applies doubly in tests, where the `// Given` / `// When` / `// Then` structure already tells the story.
140+
134141
Prefer concise comments, using correct terminology.
135142

143+
In doc comments, reference other items with rustdoc intra-doc links (`` [`Foo`] ``), not plain `` `Foo` `` backticks. CI rejects broken links in everything rustdoc documents (test code is outside its view), and only linked references are checked at all; a plain backtick reference rots silently when the item is renamed. A backticked word that merely looks like an item (an algorithm name, a type from a crate we do not depend on, a `cfg(test)` item invisible to rustdoc) stays a plain code span.
144+
136145
See `docs/engineering-standards.md` §Write helpful code comments for the full rationale and a `Don't` / `Do` example.
137146

138147
## Test Terminology

Cargo.lock

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

crates/attestation-cli/src/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn load_measurements(
127127
}
128128
}
129129

130-
/// Parse a `TcbInfo`-format JSON into `ExpectedMeasurements`, replicating
130+
/// Parse a [`TcbInfo`]-format JSON into [`ExpectedMeasurements`], replicating
131131
/// the same logic as the `include_measurements!()` proc macro at runtime.
132132
fn parse_measurements_from_json(json: &str) -> anyhow::Result<ExpectedMeasurements> {
133133
let tcb_info: TcbInfo = serde_json::from_str(json).context("invalid TcbInfo JSON")?;

crates/attestation/src/app_compose.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize, de::IgnoredAny};
1111
/// `deny_unknown_fields` makes verification fail closed: every key dstack can emit into
1212
/// `app-compose.json` must be modeled here, so a field added by a future dstack version is rejected
1313
/// until it is reviewed and modeled, rather than silently ignored. Fields are mirrored from
14-
/// dstack's `AppCompose` (`dstack-types/src/lib.rs`) plus the script keys read directly via `jq`
14+
/// dstack's [`AppCompose`] (`dstack-types/src/lib.rs`) plus the script keys read directly via `jq`
1515
/// during boot (`pre_launch_script`, `init_script`, `bash_script`). Fields without a security
1616
/// implication are modeled only to absorb their key; they are not validated.
1717
#[derive(Debug, Deserialize)]

crates/attestation/src/attestation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub struct AcceptedDstackAttestation {
4848
/// The accepted measurement set this attestation matched.
4949
pub measurements: ExpectedMeasurements,
5050
/// Informational advisory IDs (e.g. `INTEL-DOC-10000` post-ESU) surfaced by
51-
/// Intel's PCS alongside an `UpToDate` TCB status. They are not a security
52-
/// failure — `UpToDate` is the sole security gate; these advisories convey
51+
/// Intel's PCS alongside an [`UpToDate`](tee_verifier_interface::TcbStatus::UpToDate) TCB status. They are not a security
52+
/// failure — [`UpToDate`](tee_verifier_interface::TcbStatus::UpToDate) is the sole security gate; these advisories convey
5353
/// platform lifecycle information.
5454
pub advisory_ids: Vec<String>,
5555
}
@@ -156,7 +156,7 @@ impl DstackAttestation {
156156
})
157157
}
158158

159-
/// Full local verification: runs `dcap_qvl::verify::verify` and then the
159+
/// Full local verification: runs [`dcap_qvl::verify::verify`] and then the
160160
/// post-DCAP checks via [`Self::verify_with_report`].
161161
#[cfg(feature = "local-verify")]
162162
pub fn verify_locally(
@@ -169,7 +169,7 @@ impl DstackAttestation {
169169
self.verify_with_report(&report, expected_report_data, accepted_measurements)
170170
}
171171

172-
/// Runs only the DCAP step (`dcap_qvl::verify::verify`) and returns the
172+
/// Runs only the DCAP step ([`dcap_qvl::verify::verify`]) and returns the
173173
/// resulting report as the `tee-verifier-interface` mirror — the same value
174174
/// the `tee-verifier` contract returns on-chain.
175175
#[cfg(feature = "local-verify")]
@@ -261,7 +261,7 @@ impl DstackAttestation {
261261
/// check below.
262262
/// 2. `INTEL-DOC-NNNNN`: informational lifecycle markers (e.g. `INTEL-DOC-10000`
263263
/// after a product's Extended Servicing Updates date). These may appear with
264-
/// `UpToDate` and do not indicate a vulnerability; they are returned so the
264+
/// [`UpToDate`](tee_verifier_interface::TcbStatus::UpToDate) and do not indicate a vulnerability; they are returned so the
265265
/// caller can log/expose them.
266266
fn verify_tcb_status(report: &VerifiedReport) -> Result<Vec<String>, VerificationError> {
267267
(report.status == EXPECTED_QUOTE_STATUS)

crates/attestation/src/collateral.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Quote collateral (Intel certificates + TCB info) used to verify a quote.
22
//!
3-
//! `Collateral` is re-exported from `tee-verifier-interface`, not redefined,
3+
//! [`Collateral`] is re-exported from `tee-verifier-interface`, not redefined,
44
//! so it has a single canonical definition.
55
//!
66
//! The `test-utils` JSON parser below lives here, not in the wire crate:

crates/attestation/src/tcb_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ mod tests {
229229
use rstest::rstest;
230230
use serde_json;
231231

232-
/// `TcbInfo` holds both `HexBytes<48>` and `HexBytes<32>`; schema
232+
/// [`TcbInfo`] holds both `HexBytes<48>` and `HexBytes<32>`; schema
233233
/// generation panics if their declarations collide.
234234
#[cfg(feature = "borsh-schema")]
235235
#[test]

crates/backup-cli/src/adapters/contract_state_rpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ impl ReadContractState for RpcContractStateReader {
3737
#[error("contract state view call failed: {0}")]
3838
pub struct RpcError(String);
3939

40-
/// `reqwest` writes the request url, which is where an api key lives, into both the `Display` and
41-
/// the `Debug` of its errors, so its own text is dropped in favour of the causes below it, which do
40+
/// `reqwest` writes the request url, which is where an api key lives, into both the [`Display`](std::fmt::Display) and
41+
/// the [`Debug`] of its errors, so its own text is dropped in favour of the causes below it, which do
4242
/// not know the url. Every other variant carries text `near_kit` authored itself.
4343
fn describe(err: &NearKitError) -> String {
4444
match err {

crates/backup-cli/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn running_state_with_epoch(epoch_id: u64) -> ProtocolContractState {
1818
ProtocolContractState::Running(running)
1919
}
2020

21-
/// What contract initialization leaves behind: `Running`, but without any key yet.
21+
/// What contract initialization leaves behind: [`Running`], but without any key yet.
2222
pub fn running_state_without_domains() -> ProtocolContractState {
2323
let mut running = running_contract_state();
2424
running.keyset.epoch_id = EpochId::new(0);

crates/chain-gateway/src/event_subscriber/recent_blocks_tracker.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ use crate::event_subscriber::block_events::BlockContext;
88
use crate::event_subscriber::metrics::{MPC_BLOCKS_INDEXED, MPC_FINALIZED_BLOCKS_INDEXED};
99
use near_contract_transport::BlockHeight;
1010

11+
#[expect(rustdoc::private_intra_doc_links)]
1112
/// Tracks the topology of the recent blocks, using the blocks given by the indexer.
1213
///
1314
/// This class provides two important functionalities:
1415
/// - Converts a stream of optimistic blocks from the indexer into a stream of finalized
1516
/// blocks.
16-
/// - For each block added via `add_block`, it returns a `BlockStatusHandle` that can be
17-
/// used to observe that block's current `BlockStatus` (non-canonical, canonical or final).
17+
/// - For each block added via `add_block`, it returns a [`BlockStatusHandle`] that can be
18+
/// used to observe that block's current [`BlockStatus`] (non-canonical, canonical or final).
1819
///
1920
/// This class provides the following invariants (provided the requirements listed below are met):
2021
/// - A block that is final will never be reverted to non-final;
@@ -51,10 +52,10 @@ use near_contract_transport::BlockHeight;
5152
/// Despite the assumptions we make on the indexer's behavior, this class guarantees not to panic
5253
/// even if the indexer violates these assumptions in arbitrary ways.
5354
///
54-
/// Note that the `RecentBlocksTracker` is removing blocks aggressively. A block is removed if one
55+
/// Note that the [`RecentBlocksTracker`] is removing blocks aggressively. A block is removed if one
5556
/// of the following conditions is met:
5657
/// - The block sits on a dead fork and can't ever be finalized;
57-
/// - The block is outside of the recency window `RecentBlocksTracker::window_size`
58+
/// - The block is outside of the recency window [`RecentBlocksTracker::window_size`]
5859
///
5960
/// Cleanup takes place after every `add_block` in two methods:
6061
/// - `maybe_update_final_head` owns **dead-fork cleanup**. When a new final block is established,
@@ -120,10 +121,11 @@ pub struct RecentBlocksTracker {
120121
pub enum BlockStatus {
121122
/// The block is optimistically included in the chain, but it is not on the canonical chain.
122123
OptimisticButNotCanonical = 0,
124+
#[expect(rustdoc::private_intra_doc_links)]
123125
/// The block is optimistically included in the chain, and it is on the canonical chain,
124126
/// but it is not yet part of the final chain.
125127
/// Note that if two chains tie for canonical height, the first one seen is considered the
126-
/// canonical chain (c.f. `RecentBlocksTracker::update_canonical_head`).
128+
/// canonical chain (c.f. [`RecentBlocksTracker::update_canonical_head`]).
127129
OptimisticAndCanonical = 1,
128130
/// The block is finalized by the blockchain.
129131
/// It is an ancestor (including self) of the latest final block.
@@ -208,7 +210,7 @@ pub struct AddBlockResult {
208210
struct BlockNode {
209211
hash: CryptoHash,
210212
height: BlockHeight,
211-
/// Indicates the finality status of this block. Held as `Arc`.
213+
/// Indicates the finality status of this block. Held as [`Arc`].
212214
/// A [`BlockStatusHandle`] is handed out via [`AddBlockResult::block_status`] to consumers,
213215
/// allowing them to observe status changes and detect pruning.
214216
status: Arc<AtomicBlockStatus>,
@@ -369,7 +371,7 @@ impl RecentBlocksTracker {
369371

370372
/// Advance the final head, mark its ancestors as final, and drop every
371373
/// subtree that BFT-safety guarantees can no longer be on the final chain.
372-
/// See `RecentBlocksTracker` for the picture of which subtrees this catches.
374+
/// See [`RecentBlocksTracker`] for the picture of which subtrees this catches.
373375
///
374376
/// Returns the newly finalized blocks in ascending height order.
375377
fn maybe_update_final_head(&mut self, potential_final_head: CryptoHash) -> Vec<Arc<BlockNode>> {
@@ -511,7 +513,7 @@ impl RecentBlocksTracker {
511513

512514
/// Recency-window prune. Drops every node below `min_height_to_keep` and
513515
/// promotes the first in-window descendant on each branch to a new root.
514-
/// See `RecentBlocksTracker` for the picture; dead-fork cleanup happens in
516+
/// See [`RecentBlocksTracker`] for the picture; dead-fork cleanup happens in
515517
/// `maybe_update_final_head`, not here.
516518
fn prune_old_blocks(&mut self) {
517519
let Some(min_height_to_keep) = self.minimum_height_to_keep() else {

0 commit comments

Comments
 (0)