Conversation
f80134e to
a91e3e0
Compare
payjoin-directory/src/lib.rs
Outdated
| async fn wait_for_v2_payload( | ||
| &self, | ||
| id: &ShortId, | ||
| ) -> Result<Arc<Vec<u8>>, DbError<Self::OperationalError>> { | ||
| let receiver = { | ||
| let mut state = self.state.lock().await; | ||
| if let Some(payload) = state.v2_payloads.get(id) { | ||
| return Ok(payload.clone()); | ||
| } | ||
| if let Some((ref mut payload, _response_tx)) = state.v1_pending.get_mut(id) { | ||
| if let Some(p) = payload.take() { | ||
| return Ok(p); | ||
| } | ||
| } | ||
| let (tx, rx) = oneshot::channel(); | ||
| state.v2_waiters.insert(*id, tx); | ||
| rx | ||
| }; | ||
| match tokio::time::timeout(self.timeout, receiver).await { | ||
| Ok(Ok(payload)) => Ok(payload), | ||
| Ok(Err(_)) => Err(DbError::Operational(std::io::Error::new( | ||
| std::io::ErrorKind::ConnectionReset, | ||
| "closed", | ||
| ))), | ||
| Err(elapsed) => Err(DbError::Timeout(elapsed)), | ||
| } | ||
| } |
There was a problem hiding this comment.
In this function we just return an error on a Sender error or timeout but the TestDbState keeps a v2_waiters with this ShortId. Is there some value in mimicing the behavior in the FilesDb where the v2_waiter is cleared no matter what?
I ask this only if others see value in a long running mailroom test, say to demonstrate an overfilling mailroom.
payjoin-directory/src/lib.rs
Outdated
| match tokio::time::timeout(self.timeout, receiver).await { | ||
| Ok(Ok(payload)) => Ok(Arc::new(payload)), | ||
| Ok(Err(_)) => Err(DbError::V1SenderUnavailable), | ||
| Err(elapsed) => Err(DbError::Timeout(elapsed)), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Same here where the v1_pending is not cleared on an error
spacebear21
left a comment
There was a problem hiding this comment.
This is looking promising! I left some high-level feedback while this is still in draft. Another question I had: do you expect this do be backwards-compatible with an existing DB? Say I started running a payjoin-mailroom yesterday and have active sessions, and upgrade to this, will it keep existing sessions around?
There was a problem hiding this comment.
We can kill the standalone directory binary entirely
payjoin-mailroom/src/db/files.rs
Outdated
| pub(crate) capacity: usize, | ||
| persistent_storage: DiskStorage, | ||
| pending_v1: HashMap<ShortId, V1WaitMapEntry>, | ||
| pub(crate) pending_v1: HashMap<ShortId, V1WaitMapEntry>, | ||
| pending_v2: HashMap<ShortId, V2WaitMapEntry>, | ||
| insert_order: VecDeque<(SystemTime, ShortId)>, | ||
| read_order: VecDeque<(SystemTime, ShortId)>, | ||
| pub(crate) insert_order: VecDeque<(SystemTime, ShortId)>, | ||
| pub(crate) read_order: VecDeque<(SystemTime, ShortId)>, | ||
| read_mailbox_ids: HashSet<ShortId>, | ||
| unread_ttl_below_capacity: Duration, | ||
| unread_ttl_at_capacity: Duration, | ||
| read_ttl: Duration, | ||
| pub(crate) unread_ttl_below_capacity: Duration, | ||
| pub(crate) unread_ttl_at_capacity: Duration, | ||
| pub(crate) read_ttl: Duration, |
There was a problem hiding this comment.
Why did these change to pub(crate)? I don't see where they are being used.
There was a problem hiding this comment.
oops!, when i started writting this , i was importing types i needed from the payjoin-directory crate, made them pub crate there and copied them over here.
will change it
There was a problem hiding this comment.
looks like this is still unresolved in the latest push? there are a few other pub(crate) additions throughout this file which also seem unnecessary.
payjoin-directory/src/db/mod.rs
Outdated
There was a problem hiding this comment.
is there a reason to keep the payjoin-directory db mod?
payjoin-directory/src/lib.rs
Outdated
| let db = FilesDb::init(Duration::from_millis(100), dir.keep()).await.expect("db init"); | ||
| /// In-memory Db implementation for directory service tests. | ||
| #[derive(Clone)] | ||
| struct TestDb { |
There was a problem hiding this comment.
Similarly, would it be more appropriate to have these tests live in payjoin-mailroom's db mod?
Pull Request Test Coverage Report for Build 22786494612Details
💛 - Coveralls |
fde034f to
f9b75aa
Compare
spacebear21
left a comment
There was a problem hiding this comment.
Epic net deletion!
cACK on deleting the payjoin-directory crate and moving it to a service with axum routing.
It looks like the LLM was a bit overzealous in deleting docstrings and comments, tests, and random line breaks. The latter is fine, but the tests and comments need to be restored where applicable.
Lastly, can you please clean up the commit message per the contributing guidelines?
Thanks for taking on this big refactor.
payjoin-mailroom/src/db/files.rs
Outdated
| pub(crate) capacity: usize, | ||
| persistent_storage: DiskStorage, | ||
| pending_v1: HashMap<ShortId, V1WaitMapEntry>, | ||
| pub(crate) pending_v1: HashMap<ShortId, V1WaitMapEntry>, | ||
| pending_v2: HashMap<ShortId, V2WaitMapEntry>, | ||
| insert_order: VecDeque<(SystemTime, ShortId)>, | ||
| read_order: VecDeque<(SystemTime, ShortId)>, | ||
| pub(crate) insert_order: VecDeque<(SystemTime, ShortId)>, | ||
| pub(crate) read_order: VecDeque<(SystemTime, ShortId)>, | ||
| read_mailbox_ids: HashSet<ShortId>, | ||
| unread_ttl_below_capacity: Duration, | ||
| unread_ttl_at_capacity: Duration, | ||
| read_ttl: Duration, | ||
| pub(crate) unread_ttl_below_capacity: Duration, | ||
| pub(crate) unread_ttl_at_capacity: Duration, | ||
| pub(crate) read_ttl: Duration, |
There was a problem hiding this comment.
looks like this is still unresolved in the latest push? there are a few other pub(crate) additions throughout this file which also seem unnecessary.
|
Also I just realized we reference payjoin-directory in various links through the codebase, for example in the README. We should grep the whole codebase for |
35ad2c2 to
44fda1e
Compare
This pr addresses a part of payjoin#941 consigned with making Db a tower service. It also removes the payjoin-directory crate and moves all directory functionality into the payjoin-mailroom crate as a tower service.
There was a problem hiding this comment.
ACK f2d07db
I took the liberty to force push to fix a few minor things:
- added back more comments that had been inadvertently removed
- changed the
payjoindependency in payjoin-mailroom to rc.2 instead of rc.1 - cleaned up the commit message a bit for typos/grammar
We'll need an ACK from someone else to merge this because I was the last to push on the PR so my approval doesn't count per github rules.
This PR addresses part of #941 by making Db a tower service. Since payjoin-directory will eventually be deprecated, this PR moves the db implementation to payjoin-mailroom while still allowing the directory binary to be built if needed. The PR also ensures directory::Service remains compatible via the Db trait adapter.
Some parts of these PR was bootstrapped using chatgpt web
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.