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

State API - RPC methods #532

Merged
merged 68 commits into from
Jul 27, 2020
Merged

Conversation

StaticallyTypedAnxiety
Copy link
Contributor

Summary of changes
Changes introduced in this pull request:

  • This PR implements states functions needed for the RPC

Reference issue to close (if applicable)

Closes #476
Closes #487
Closes #489

Other information and links

blockchain/beacon/src/drand_api/api.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/call.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/call.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
@dutterbutter dutterbutter changed the title Ashanti/state api rpc methods State API - RPC methods Jul 6, 2020
blockchain/state_manager/src/call.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
@ec2
Copy link
Member

ec2 commented Jul 7, 2020

You mention this PR closes #476 but I don't see it getting hooked up to JSONRPC as done here https://github.com/ChainSafe/forest/blob/main/node/rpc/src/lib.rs#L30

blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@austinabell austinabell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review, I'll continue later

blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Show resolved Hide resolved
blockchain/state_manager/src/call.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@ec2 ec2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not finished yet, but leaving some comments for now. This PR is actually really hard to review hahaha thank god you broke down the other state mgr stuff haha

blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/call.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
}

while back_search_wait.next().await.is_some() {
if !reverts.get(back_tipset.key()).unwrap_or(&false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets called for all () put through this pubsub channel, but this back_tipset never changes, would this not just loop over and call the same code on the tipset when the back_tipset was initiated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought since it is in a loop structure the same thing would be happening at the lotus side? If multiple backsearchWait events are being called the same code will potentially be called as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, they are just calling that function asyncronously and only handling it once (and not recurring, they kinda use that channel as a oneshot. Seems like if you have this subscriber you could potentially be receiving events from another function call, unrelated to the logic of this.

I don't see why these events would need to be published in a pubsub way, seems pretty local (maybe clarification around why this needs to be emitted like this would be great, as I'm confused)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely! Wanted to use a oneshot but it looks like subheadchanges is the one that is sending these events externally? That is where the tsub starts to match in the case? I was also confused as to why they need to be externally called but following lotus seems like that might be the way they want it? I could also be very confused it is not as easy to parse haha

https://github.com/filecoin-project/lotus/blob/c4de2373fd13c909876cf459e59ead7749b9939d/chain/stmgr/stmgr.go#L494

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see they are using that and that is matched above, but this back search is completely distinct and you are using the same subscriber channel, this will just keep iterating over and never close, so this function will never end. Am I missing something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is my lack of go showing, I just recently knew that go func() is supposed to be an anoymous routine. Taking a look at this and fixing this right now, was trying to visualize as to what point the back_search_wait gets sent to and this makes more sense now

blockchain/state_manager/src/utils.rs Outdated Show resolved Hide resolved
vm/message/src/lib.rs Outdated Show resolved Hide resolved
vm/message/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 44 to 45
//turns message into cid
fn to_cid(&self) -> Result<Cid, String>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bumping this comment in case it was missed

blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
}

while back_search_wait.next().await.is_some() {
if !reverts.get(back_tipset.key()).unwrap_or(&false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see they are using that and that is matched above, but this back search is completely distinct and you are using the same subscriber channel, this will just keep iterating over and never close, so this function will never end. Am I missing something here?

Co-authored-by: Austin Abell <austinabell8@gmail.com>
Co-authored-by: Austin Abell <austinabell8@gmail.com>
Co-authored-by: Austin Abell <austinabell8@gmail.com>
node/state_api/src/lib.rs Outdated Show resolved Hide resolved
blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 524 to 541
async {
back_search_recieved =
Some(receiver.await.map_err(|e| {
Error::Other(format!("Could not receieve from channel {:?}", e))
})?);
Ok::<(), Error>(())
}
.await?;

while let Some(subscriber) = self
.subscriber
.clone()
.ok_or_else(|| {
Error::Other("State Manager not subscribed to tipset head changes".to_string())
})?
.next()
.await
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be polled at the same time as the subscriber (both the receiver channel and pubsub receiver are futures) as right now you are waiting for the function to complete, then awaiting on the subscriber events. These changes don't change anything I don't think (unless I'm reading wrong)

Comment on lines 333 to 342
pub fn get_power<DB>(
state_manager: &StateManager<DB>,
tipset: &Tipset,
address: Option<&Address>,
) -> Result<(Option<Claim>, Claim), Error>
where
DB: BlockStore,
{
get_power_raw(state_manager, tipset.parent_state(), address)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about why this is different from the one attached to the state manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was a mistake, shouldn't even be here.

Ok(miner_actor_state.info)
}

pub fn get_miner_deadlines<DB>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this function coming from? I'm having a hard time mapping some of these functions in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@austinabell austinabell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only the two small things and should be good

blockchain/state_manager/src/lib.rs Outdated Show resolved Hide resolved
@@ -284,7 +284,7 @@ dependencies = [
"ipld_blockstore",
"ipld_hamt",
"lazy_static",
"libp2p",
"libp2p 0.21.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for bumping versions? was there something that broke? (wondering if there is something to fix) I tried without the updates and things seemed fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure, I just did a cargo update and found this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, that's what I meant to ask, just wasn't sure why the cargo update was necessary

let unsigned_box = unsigned.into_iter().map(|s| Box::new(s) as BoxMessage);
let signed_box = signed.into_iter().map(|s| Box::new(s) as BoxMessage);

let mut messages = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump using capacity to avoid reallocations

Copy link
Contributor

@austinabell austinabell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM given it will be moved to be attached to RPC API in following PR

@StaticallyTypedAnxiety StaticallyTypedAnxiety merged commit 907eda8 into main Jul 27, 2020
@StaticallyTypedAnxiety StaticallyTypedAnxiety deleted the ashanti/state_api_rpc_methods branch July 27, 2020 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants