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

[gh-407] add web socket relay for bitcoin and nostr protocols. #408

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

Conversation

feliciss
Copy link
Collaborator

@feliciss feliciss commented Jul 5, 2023

This PR drafts:

  1. Add ws config of relay under rooch-config directory. Referred to nostr-rs-relay: https://github.com/scsibug/nostr-rs-relay/blob/9e22776227d30039458b698fd0eca21b179b453a/src/config.rs#L285C13-L285C13

Resolves #407

@vercel
Copy link

vercel bot commented Jul 5, 2023

Someone is attempting to deploy a commit to the Rooch Team on Vercel.

A member of the Team first needs to authorize it.

@feliciss feliciss force-pushed the #407 branch 2 times, most recently from 7e67d6e to 686cd2a Compare July 5, 2023 07:57
@jolestar
Copy link
Contributor

jolestar commented Jul 5, 2023

Split this PR into two PRs.

  1. to_string to to_owned.
  2. relay_config. The relay config should be a draft PR, will merge it when the nostr relay PoC is finished.

@feliciss feliciss changed the title [config] add ws config, to_string to to_owned. [config] add ws config Jul 5, 2023
@feliciss feliciss marked this pull request as draft July 5, 2023 20:29
@feliciss feliciss changed the title [config] add ws config [config] add ws relay config Jul 5, 2023
@feliciss feliciss changed the title [config] add ws relay config [relay] add web socket relay for bitcoin and nostr protocols. Jul 6, 2023
@feliciss
Copy link
Collaborator Author

feliciss commented Jul 6, 2023

This PR is currently a mirror of nostr-rs-relay. The command line output of running a rooch relay start is as below:

RUST_LOG=warn,rooch_ws_relay=info rooch relay start &
[1] 45067
2023-07-06T19:16:22.260188Z  INFO rooch_ws_relay: listening on: 0.0.0.0:8080
2023-07-06T19:16:22.264771Z  INFO rooch_ws_relay::repo::sqlite: Built a connection pool "writer" (min=0, max=2)
2023-07-06T19:16:22.265047Z  INFO rooch_ws_relay::repo::sqlite: Built a connection pool "maintenance" (min=0, max=2)
2023-07-06T19:16:22.265510Z  INFO rooch_ws_relay::repo::sqlite: Built a connection pool "reader" (min=4, max=8)
2023-07-06T19:16:22.266309Z  INFO rooch_ws_relay::repo::sqlite_migration: DB version = 0
2023-07-06T19:16:22.268365Z  INFO rooch_ws_relay::repo::sqlite_migration: database pragma/schema initialized to v18, and ready
2023-07-06T19:16:22.268389Z  INFO rooch_ws_relay::repo::sqlite_migration: All migration scripts completed successfully.  Welcome to v18.
2023-07-06T19:16:22.268601Z  INFO rooch_ws_relay: db writer created
2023-07-06T19:16:22.268692Z  INFO rooch_ws_relay: control message listener started
2023-07-06T19:17:22.272455Z  INFO rooch_ws_relay::repo::sqlite: checkpoint ran in 203.583µs (result: Ok, WAL size: 0)
2023-07-06T19:18:22.276296Z  INFO rooch_ws_relay::repo::sqlite: checkpoint ran in 87.917µs (result: Ok, WAL size: 0)
2023-07-06T19:19:22.280120Z  INFO rooch_ws_relay::repo::sqlite: checkpoint ran in 133.333µs (result: Ok, WAL size: 0)
2023-07-06T19:20:22.284054Z  INFO rooch_ws_relay::repo::sqlite: checkpoint ran in 130.75µs (result: Ok, WAL size: 0)
2023-07-06T19:21:22.288332Z  INFO rooch_ws_relay::repo::sqlite: checkpoint ran in 147.167µs (result: Ok, WAL size: 0)

I will do further research to improve it, store in Rooch in-memory DB or Rooch embedded DBs.

Maybe we should rename it to rooch relay serve?

@jolestar
Copy link
Contributor

jolestar commented Jul 7, 2023

Is it possible to store the event in the Move contract state?

@feliciss
Copy link
Collaborator Author

feliciss commented Jul 7, 2023

Is it possible to store the event in the Move contract state?

I think it is, and it's only meaningful for payment chain events made with LNbits.com? Others have little incentive to do so with SMT state storage, expect it's made for proof of statement purposes, such as posts and messages.

I can try with replacing sqlite with StateDB with new_with_memory_store() to check if it's possible to store in contract state.

@feliciss
Copy link
Collaborator Author

feliciss commented Jul 7, 2023

Is it possible to store the event in the Move contract state?

It's perfectly to implement StateDB, EventStore and TransactionDB under moveos-store directory for state merkle trees and proofs through hypercore: https://docs.holepunch.to/building-blocks/hypercore.

Its Rust implementation is at https://docs.rs/hypercore/latest/hypercore/.

It can be used for sharing large datasets and streams of real-time data, as an example of nostr.

@jolestar
Copy link
Contributor

jolestar commented Jul 7, 2023

Is it possible to store the event in the Move contract state?

It's perfectly to implement StateDB, EventStore and TransactionDB under moveos-store directory for state merkle trees and proofs through hypercore: https://docs.holepunch.to/building-blocks/hypercore.

Its Rust implementation is at https://docs.rs/hypercore/latest/hypercore/.

It can be used for sharing large datasets and streams of real-time data, as an example of nostr.

It may be suited for syncing the transaction between sequencers and proposers when we build the p2p network layer2. @baichuan3 @templexxx

But in this PR, we try to reuse rooch infrastructure to implement the nostr protocol.

  1. Implement the nostr logic with Move.
  2. Store the state in Move's state.
  3. Proxy the nostr write API to rooch transaction.
  4. Proxy the nostr query API to rooch state query.

@feliciss feliciss changed the title [relay] add web socket relay for bitcoin and nostr protocols. [gh-407] add web socket relay for bitcoin and nostr protocols. Jul 12, 2023
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.

[cli] add rooch ws relay command and serve it as CLI tool
2 participants