-
Notifications
You must be signed in to change notification settings - Fork 189
Revive the previous Filecoin.EthSubscribe PR
#5749
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
Changes from all commits
0cb4a4e
cba87c3
b6ceae6
44b4cca
222bc9e
86240dc
a543037
57aef9d
693a6d6
65c61a4
fe0417b
a5e0982
55225b0
562a63c
0cd8d86
aa7a4f4
09c09c0
a1caba8
f19f808
12e458a
09b8871
5d0ed6c
e41cfa1
28f7a94
1910206
7464d10
de8213c
cc3dbe1
3ad7f33
4d5f1cd
0fe9ce5
b986e48
2e994b8
5377199
1e02435
d569eb4
065b89f
76e130d
dcb8576
a25d9a7
0e68b0f
c1f4969
6a7de37
16f06fe
e3811e8
290b5c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ use crate::lotus_json::{HasLotusJson, LotusJson, lotus_json_with_self}; | |
| #[cfg(test)] | ||
| use crate::lotus_json::{assert_all_snapshots, assert_unchanged_via_json}; | ||
| use crate::message::{ChainMessage, SignedMessage}; | ||
| use crate::rpc::eth::{EthLog, eth_logs_with_filter, types::ApiHeaders, types::EthFilterSpec}; | ||
| use crate::rpc::types::{ApiTipsetKey, Event}; | ||
| use crate::rpc::{ApiPaths, Ctx, EthEventHandler, Permission, RpcMethod, ServerError}; | ||
| use crate::shim::clock::ChainEpoch; | ||
|
|
@@ -45,6 +46,82 @@ use tokio::sync::{ | |
| Mutex, | ||
| broadcast::{self, Receiver as Subscriber}, | ||
| }; | ||
| use tokio::task::JoinHandle; | ||
|
|
||
| const HEAD_CHANNEL_CAPACITY: usize = 10; | ||
|
|
||
| /// Subscribes to head changes from the chain store and broadcasts new blocks. | ||
| /// | ||
| /// # Notes | ||
| /// | ||
| /// Spawns an internal `tokio` task that can be aborted anytime via the returned `JoinHandle`, | ||
| /// allowing manual cleanup if needed. | ||
| pub(crate) fn new_heads<DB: Blockstore>( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some docs would be helpful.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| data: &crate::rpc::RPCState<DB>, | ||
| ) -> (Subscriber<ApiHeaders>, JoinHandle<()>) { | ||
| let (sender, receiver) = broadcast::channel(HEAD_CHANNEL_CAPACITY); | ||
|
|
||
| let mut subscriber = data.chain_store().publisher().subscribe(); | ||
|
|
||
| let handle = tokio::spawn(async move { | ||
| while let Ok(v) = subscriber.recv().await { | ||
| let headers = match v { | ||
| HeadChange::Apply(ts) => ApiHeaders(ts.block_headers().clone().into()), | ||
| }; | ||
| if let Err(e) = sender.send(headers) { | ||
| tracing::error!("Failed to send headers: {}", e); | ||
| break; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| (receiver, handle) | ||
| } | ||
|
|
||
| /// Subscribes to head changes from the chain store and broadcasts new `Ethereum` logs. | ||
| /// | ||
| /// # Notes | ||
| /// | ||
| /// Spawns an internal `tokio` task that can be aborted anytime via the returned `JoinHandle`, | ||
| /// allowing manual cleanup if needed. | ||
| pub(crate) fn logs<DB: Blockstore + Sync + Send + 'static>( | ||
| ctx: &Ctx<DB>, | ||
| filter: Option<EthFilterSpec>, | ||
| ) -> (Subscriber<Vec<EthLog>>, JoinHandle<()>) { | ||
| let (sender, receiver) = broadcast::channel(HEAD_CHANNEL_CAPACITY); | ||
|
|
||
| let mut subscriber = ctx.chain_store().publisher().subscribe(); | ||
|
|
||
| let ctx = ctx.clone(); | ||
|
|
||
| let handle = tokio::spawn(async move { | ||
| while let Ok(v) = subscriber.recv().await { | ||
| match v { | ||
| HeadChange::Apply(ts) => { | ||
| match eth_logs_with_filter(&ctx, &ts, filter.clone(), None).await { | ||
| Ok(logs) => { | ||
| if !logs.is_empty() { | ||
| if let Err(e) = sender.send(logs) { | ||
| tracing::error!( | ||
| "Failed to send logs for tipset {}: {}", | ||
| ts.key(), | ||
| e | ||
| ); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| Err(e) => { | ||
| tracing::error!("Failed to fetch logs for tipset {}: {}", ts.key(), e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| (receiver, handle) | ||
| } | ||
|
|
||
| pub enum ChainGetMessage {} | ||
| impl RpcMethod<1> for ChainGetMessage { | ||
|
|
@@ -721,7 +798,7 @@ pub(crate) fn chain_notify<DB: Blockstore>( | |
| _params: Params<'_>, | ||
| data: &crate::rpc::RPCState<DB>, | ||
| ) -> Subscriber<Vec<ApiHeadChange>> { | ||
| let (sender, receiver) = broadcast::channel(100); | ||
| let (sender, receiver) = broadcast::channel(HEAD_CHANNEL_CAPACITY); | ||
|
|
||
| // As soon as the channel is created, send the current tipset | ||
| let current = data.chain_store().heaviest_tipset(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should claim we added support for
EthUnsubscribe. As the AI reviewer noted, it's a placeholder implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the
EthSubscribeseems also empty?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some comments to explain why we need them.