stakwork / sphinx-rs

Rust crates for Sphinx Chat
0 stars 0 forks source link

signer: track sequence numbers #29

Closed irriden closed 11 months ago

irriden commented 11 months ago

restarts if signer is initialized, AND (broker restarts or broker skips sequence

Evanfeenstra commented 11 months ago
Evanfeenstra commented 11 months ago

ok, just to review:

if there wasn't an error than we know the sequence was incremented by one. So we dont need to return any new field from the tuple returned from .handle

irriden commented 11 months ago

@Evanfeenstra what should we do in the case where Option is None again?

Evanfeenstra commented 11 months ago

@Evanfeenstra what should we do in the case where Option is None again?

Simply not check the sequence. In case we make an SDK and someone doesnt care about multi-signer

irriden commented 11 months ago

Ok - but for the multi signer case, we need to somehow return the sequence received from the broker - and use that as the first reference point.

We could do a Option<&mut u16> ?

irriden commented 11 months ago

I thought we could use the info returned in BadSequence but that stops further execution.

Evanfeenstra commented 11 months ago

Ok - but for the multi signer case, we need to somehow return the sequence received from the broker - and use that as the first reference point.

We could do a Option<&mut u16> ?

Just u16. Always returning the sequence number from the broker

irriden commented 11 months ago

@Evanfeenstra the Error now looks like this.

My concern is that these #[from] conversions require std::error::Error to be implemented, and that's of course gated by std in our dependencies.

#[derive(Error, Debug)]
pub enum VlsHandlerError {
    #[error("vls protocol error: {0}")]
    VlsProtocol(#[from] vls_protocol::Error),
    #[error("vls signer error: {0}")]
    VlsSigner(#[from] vls_protocol_signer::handler::Error),
    #[error("failed lss_msg.to_vec: {0}")]
    LssWrite(#[from] anyhow::Error),
    #[error("invalid sequence: {0}, expected {1}")]
    BadSequence(u16, u16),
}
Evanfeenstra commented 11 months ago

@Evanfeenstra the Error now looks like this.

My concern is that these #[from] conversions require std::error::Error to be implemented, and that's of course gated by std in our dependencies.

#[derive(Error, Debug)]
pub enum VlsHandlerError {
    #[error("vls protocol error: {0}")]
    VlsProtocol(#[from] vls_protocol::Error),
    #[error("vls signer error: {0}")]
    VlsSigner(#[from] vls_protocol_signer::handler::Error),
    #[error("failed lss_msg.to_vec: {0}")]
    LssWrite(#[from] anyhow::Error),
    #[error("invalid sequence: {0}, expected {1}")]
    BadSequence(u16, u16),
}

Hmm ok i see. Well i guess we just need to use map_err then. Sorry for adding confusion

irriden commented 11 months ago

@Evanfeenstra the Error now looks like this. My concern is that these #[from] conversions require std::error::Error to be implemented, and that's of course gated by std in our dependencies.

#[derive(Error, Debug)]
pub enum VlsHandlerError {
    #[error("vls protocol error: {0}")]
    VlsProtocol(#[from] vls_protocol::Error),
    #[error("vls signer error: {0}")]
    VlsSigner(#[from] vls_protocol_signer::handler::Error),
    #[error("failed lss_msg.to_vec: {0}")]
    LssWrite(#[from] anyhow::Error),
    #[error("invalid sequence: {0}, expected {1}")]
    BadSequence(u16, u16),
}

Hmm ok i see. Well i guess we just need to use map_err then. Sorry for adding confusion

No problem at all - all good learning :)