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

Forbid changing aggregation job parameters #758

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mendess
Copy link
Collaborator

@mendess mendess commented Jan 9, 2025

This is important for implementing the async draft later

Copy link
Contributor

@cjpatton cjpatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, just one blocking comment: Is it feasible to hash the AggregationJobInitReq before decoding?

crates/daphne-server/src/roles/helper.rs Outdated Show resolved Hide resolved
crates/daphne-worker/src/aggregator/roles/helper.rs Outdated Show resolved Hide resolved
crates/daphne-worker/src/durable/aggregation_job_store.rs Outdated Show resolved Hide resolved
crates/daphne/src/roles/helper/mod.rs Outdated Show resolved Hide resolved
crates/daphne/src/testing/mod.rs Outdated Show resolved Hide resolved
@mendess mendess force-pushed the mendess/agg-job-counting branch 2 times, most recently from cd3effe to 895900a Compare January 9, 2025 18:05
@mendess mendess force-pushed the mendess/agg-job-counting branch from 895900a to 0447fd6 Compare January 9, 2025 18:10
Copy link
Contributor

@cjpatton cjpatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the decode-then-hash issue, I think this is good to go. I have one more suggestion there.

Comment on lines +63 to +72
impl DecodeFromDapHttpBody for HashedAggregationJobReq {
fn decode_from_http_body(bytes: Bytes, meta: &DapRequestMeta) -> Result<Self, DapAbort> {
let mut cursor = Cursor::new(bytes.as_ref());
// Check that media type matches.
meta.get_checked_media_type(DapMediaType::AggregationJobInitReq)?;
// Decode the body
HashedAggregationJobReq::decode_with_param(&meta.version, &mut cursor)
.map_err(|e| DapAbort::from_codec_error(e, meta.task_id))
}
}
Copy link
Contributor

@cjpatton cjpatton Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hashing with HashedAggregationJobReq::decode_with_param() is a little awkward because you have to keep track of the start and end of the message in the cursor. Also, and this is very nit picky: HashedAggregationJobReq is not a DAP protocol message, so arguably doesn't belong in the messages module.

I think I would have done this differently:

impl DecodeFromDapHttpBody for HashedAggregationJobReq {
    fn decode_from_http_body(bytes: Bytes, meta: &DapRequestMeta) -> Result<Self, DapAbort> {
        // Check that media type matches.
        meta.get_checked_media_type(DapMediaType::AggregationJobInitReq)?;
        // Decode the body
        let agg_job_req = AggregationJobReq::get_decoded_with_param(&meta.version, bytes.as_ref())
            .map_err(|e| DapAbort::from_codec_error(e, meta.task_id))?;
        Ok(Self{
             agg_job_req:
             hash: sha256(bytes.as_ref()),
        })
    }
}

Note that this also enforces that there is nothing left to read in bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants