--- Log opened Thu May 13 00:00:53 2021 02:43 -!- belcher_ is now known as belcher 06:03 <+JoinMarketRelay> [hackint/mojo_] Hi. I have been finally able to make the example coinswap automated. Hitting one final road block. The maker server once started do not terminate on its own. As a result the test is also not terminating in rust. I can terminate the server manually by ctrl+c, but how can I terminate programatically? Any idea? 06:06 < belcher> can you send a SIGINT to it? 06:07 < belcher> when its used the maker would run forever until the user does ctrl+c, thats how joinmarket makers work too 06:07 < belcher> if not, there could be a hidden startup option added to shut down the maker after one transaction, that would be used for testing 06:10 < belcher> mojo_ btw you should consider writing a weekly work diary like i do here https://gist.github.com/chris-belcher/ca5051285c6f8d38693fd127575be44d 06:11 < belcher> i got the idea based on this blog post about remote work and async communication https://blog.doist.com/asynchronous-communication/ to me it seems a good way of organizing a way of working together 06:15 <+JoinMarketRelay> [hackint/mojo_] JoinMarketRelay, nice suggestion. Yes I should maintain a diary from now. Will read up on the post. Let me try first with the SIGINT, it should work. 06:24 <+JoinMarketRelay> [hackint/mojo_] Hmm, there is a way to send SIGINT to the process using `nix` crate. https://stackoverflow.com/questions/43788943/send-sigint-to-a-process-by-sending-ctrl-c-to-stdin 06:25 <+JoinMarketRelay> [hackint/mojo_] the other way is to have test specific code to terminate maker (that wont require new dependency) what do you think is best? 06:25 < belcher> having test specific code without the new dependency is best i reckon 06:26 < belcher> right now it can be another command line option, and one day later when we add config files it can be an option there (and then tests will have their own config files) 06:30 <+JoinMarketRelay> [hackint/mojo_] Makes sense. Will go the test specific route. Thanks for the help. 06:41 <+JoinMarketRelay> [hackint/mojo_] One more thing, it seems tokio::TcpSocket and std::TcpSocket do not talk with each other? Is that the case? 06:43 < belcher> i think so yes, tokio:TcpSocket is async while std::TcpSocket is single-threaded and blocking 08:31 <+JoinMarketRelay> [hackint/mojo_] Ugh.. Seems like no easy way to stop a tokio::spawn within itself. Getting hardpressed to go for the SIGINT option. 08:32 < belcher> mojo_ what happens if you try having each loop iteration check a mutable boolean variable and break if true 08:33 < belcher> i assume here https://github.com/bitcoin-teleport/teleport-transactions/blob/master/src/maker_protocol.rs#L72 08:34 < belcher> actually 08:35 <+JoinMarketRelay> [hackint/mojo_] Doing exactly that. The variable gets changed but not in the first iteration because it takes time for the spawn process to change the variable. So it doesn't do anything instead. 08:35 < belcher> what it could do is increment a counter, then break when the counter reaches 1 loop (1 accepted client) 08:35 < belcher> then theres no need for inter-thread communication 08:36 < belcher> and the "1 loop" number can be the parameter passed as an option, so it could be set to break after any number of listener.accept()s 08:36 <+JoinMarketRelay> [hackint/mojo_] sharing my code as of now in a gist. Maybe you can see try there.. 08:37 < belcher> ok 08:43 <+JoinMarketRelay> [hackint/mojo_] https://gist.github.com/mojoX911/ea55c4172dbb1049db2a29a5a00830d9 08:44 < belcher> the inner spawn() (starting line 23) just ends when the client ends 08:45 < belcher> you dont need to end that in a different way i think, just have the taker disconnect (which it does anyway when its finished) 08:45 < belcher> the problem i thought was ending the outer loop, starting line 12 (?) is that right? 08:51 <+JoinMarketRelay> [hackint/mojo_] Yes that seems to be correct. 08:52 <+JoinMarketRelay> [hackint/mojo_] I need to somehow let the outer loop know to exit. 08:55 < belcher> i wrote this https://pastebin.com/xPRY6nwj 08:55 < belcher> which is how i imagined it 08:56 <+JoinMarketRelay> [hackint/mojo_] Also in debugger, even when the client exit, the outerloop doesn't seem to run again. the spawn just seem to get paused. So even if i set the killswitch outside the loop, it still doesn't exit because the next iteration doesn't run. 08:57 < belcher> killswitch is a bad idea i think, having this counter might be better 09:00 <+JoinMarketRelay> [hackint/mojo_] Ya it seems to be the same thing as having a bool do it. Can you confirm that the `if` hits when the client disconnects? i.e the loop iterates after spawning returns? 09:00 < belcher> when the if becomes true the client wont disconnect 09:00 < belcher> because the thread handling the client socket is different to the thread handling the server socket 09:01 < belcher> the thread handling the client socket already ends when the client socket reaches EOF 09:51 <+JoinMarketRelay> [hackint/mojo_] Yes this counter way works. Thanks.. 10:18 <+JoinMarketRelay> [hackint/mojo_] Now it seems to close the maker prematurely. 10:26 <+JoinMarketRelay> [hackint/mojo_] Seems like the outer loop is going into next iteration even when taker isn't disconnected. 10:36 < belcher> mojo_ yes thats right, the inner loop is in a different thread 10:36 < belcher> are you saying the application closes even though the inner loop is still running? :\ 10:40 < belcher> if so, try searching for a way to make the application not halt until all threads are done, in other threading interfaces its called "daemon thread" 10:53 <+JoinMarketRelay> [hackint/mojo_] here the output https://pastebin.com/R7zua6JK 10:53 <+JoinMarketRelay> [hackint/mojo_] One maker is stoping prematurely even when taker isn't finished. 10:53 <+JoinMarketRelay> [hackint/mojo_] Might be because taker is trying to connect to the maker multiple time? 10:54 < belcher> oooh 10:54 < belcher> yeah thats it 10:54 < belcher> the taker disconnects 10:54 < belcher> if so then you need to set max_clients to 5 or 6, try a few numbers 10:55 <+JoinMarketRelay> [hackint/mojo_] Hmm ok.. 10:56 < belcher> for a full coinswap run you need to tell regtest to generate blocks 11:33 <+JoinMarketRelay> [hackint/mojo_] Yeah, I have made that part working automated already.. 11:34 <+JoinMarketRelay> [hackint/mojo_] Hmm.. This counting thing doesn't seem to be working. AT max count 4 the loop stops but taker fails to submit hashpreimage to one maker, but succeeds for another maker. 11:34 <+JoinMarketRelay> [hackint/mojo_] at max count 5 the loop doesnt end. 11:35 < belcher> oh thats because different makers require different messages depending on where they are in the route... 11:36 < belcher> thats a bit sucky then.. hold on we'll think of something 11:36 < belcher> how about in the server socket loop checking the wallet 11:37 <+JoinMarketRelay> [hackint/mojo_] can you point? 11:37 < belcher> because in the final maker message `handle_private_key_handover()` it updates the wallet to add those private keys, if you check for that in the loop then it can tell you when the coinswap is done 11:37 < belcher> https://github.com/bitcoin-teleport/teleport-transactions/blob/master/src/maker_protocol.rs#L554-L577 11:37 < belcher> and the wallet is wrapped into Arc here https://github.com/bitcoin-teleport/teleport-transactions/blob/master/src/maker_protocol.rs#L76 so the outer loop already has access to it 11:41 <+JoinMarketRelay> [hackint/mojo_] Yes but the problem was getting that signal out from the spawn to outer loop. Or are you saying putting it inside the wallet somehow, that the outerloop can read? 11:42 < belcher> maybe the best way is before the loop starts to count the number of swapcoin privkeys in the wallet and save into a variable, then break the outer loop when the number of private key of the wallet increases 11:42 < belcher> the signal can be the number of swapcoin privkeys in the wallet, and because the wallet is already stored in Arc then there already is inter-thread communication 11:42 <+JoinMarketRelay> [hackint/mojo_] hmm.. that might work.. 15:05 -!- belcher [~belcher@unaffiliated/belcher] has quit [Ping timeout: 240 seconds] 15:41 -!- belcher [~belcher@unaffiliated/belcher] has joined ##coinswap 22:56 <+JoinMarketRelay> [hackint/mojo_] Tried the swapcoin count way. Its still not working. The reason is, the swapcoin count is increasing before taker can make the final communication. So as soon as it increases the maker drops connection and the taker is left hanging. 23:03 <+JoinMarketRelay> [hackint/mojo_] Heres the output showing its happening https://pastebin.com/9uuqCuf2 23:10 <+JoinMarketRelay> [hackint/mojo_] It seems there is no internal signal maker has to know that swap is done. The last message taker sends to maker is `PrivateKeyHandover`. So once maker receives this, that should be the right time to drop it. But this signal arrives in the inner loop and thats in a different thread than the outer loop. So i guess the question is how to get this 23:10 <+JoinMarketRelay> signal out. 23:11 <+JoinMarketRelay> [hackint/mojo_] Also note, if we can get that signal out to outerloop, we can also get a kill signal out in the outer loop too. So that will remove all the extra logic and make things simple. 23:15 <+JoinMarketRelay> [hackint/mojo_] We can have the kill signal handling only for test config, so it will not be there in the compiled binary. So usual maker behavior can remain intact. --- Log closed Fri May 14 00:00:54 2021