Skip to content

sv1_api + stratum-translation: BIP323 adaptations #2195

Description

@plebhash

BIP320 0x1FFFE000 mask is hardcoded on a few places, it should be updated to BIP323 0x1FFFFFE0

ideally, one constant defined on sv1_api crate and used on stratum-translation too

impl VersionRollingParams {
pub fn new(
version_rolling_mask: HexU32Be,
version_rolling_min_bit_count: HexU32Be,
) -> Result<Self, Error<'static>> {
// 0x1FFFE000 should be configured
let negotiated_mask = HexU32Be(version_rolling_mask.clone() & 0x1FFFE000);
let version_head_ok = negotiated_mask.0 >> 29 == 0;
let version_tail_ok = negotiated_mask.0 << 19 == 0;
if version_head_ok && version_tail_ok {
Ok(VersionRollingParams {
version_rolling: true,
version_rolling_mask: negotiated_mask,
version_rolling_min_bit_count,
})
} else {
Err(Error::InvalidVersionMask(version_rolling_mask))
}
}
}

pub fn version_rolling_mask(&self) -> Option<HexU32Be> {
let mut res = None;
for ext in &self.extensions {
if let ConfigureExtension::VersionRolling(p) = ext {
res = Some(p.mask.clone().unwrap_or(HexU32Be(0x1FFFE000)));
};
}
res
}

#[test]
fn test_build_sv2_submit_from_sv1_submit_happy() {
let s = submit_template();
let res = build_sv2_submit_shares_extended_from_sv1_submit(
&s,
1,
100,
0x20000000,
Some(HexU32Be(0x1fffe000)),
);
assert!(res.is_ok());
let submit = res.unwrap();
assert_eq!(submit.channel_id, 1);
assert_eq!(submit.sequence_number, 100);
assert_eq!(submit.job_id, 1); // from job_id "1" in template
assert_eq!(submit.nonce, 0);
assert_eq!(submit.ntime, 0);
// Version should be computed from job_version and version rolling
assert_eq!(submit.version, 0x20000000); // (0x20000000 & !0x1fffe000) | (0 & 0x1fffe000)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Todo 📝
    Status
    Todo 📝

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions