rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

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

Open feliciss opened 10 months ago

feliciss commented 10 months ago

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[bot] commented 10 months ago

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

A member of the Team first needs to authorize it.

jolestar commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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

feliciss commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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.