-
Notifications
You must be signed in to change notification settings - Fork 159
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
Rpc state implementation #618
Merged
Merged
Changes from all commits
Commits
Show all changes
109 commits
Select commit
Hold shift + click to select a range
c1d83d8
implemented state calls
StaticallyTypedAnxiety 5b658e8
code complete
StaticallyTypedAnxiety 46f0370
Merge branch 'master' into ashanti/state_api_rpc_methods
StaticallyTypedAnxiety c1a0310
state changes and fixes
StaticallyTypedAnxiety 2ddf7c6
added test changes
StaticallyTypedAnxiety 9f63d27
Merge branch 'main' into ashanti/state_api_rpc_methods
StaticallyTypedAnxiety 78276f2
removed unused imports
StaticallyTypedAnxiety 36d8d6d
fixed merge conflicts
StaticallyTypedAnxiety 7c641ce
state manager changes
StaticallyTypedAnxiety fe9dd6e
Merge branch 'main' into ashanti/state_api_rpc_methods
StaticallyTypedAnxiety c0bbf33
added licenses
StaticallyTypedAnxiety 06ea6fe
Merge branch 'ashanti/state_api_rpc_methods' of https://github.com/ch…
StaticallyTypedAnxiety 9b8d656
applied cargo update
StaticallyTypedAnxiety ae87f0c
removed halt
StaticallyTypedAnxiety e9ae665
clean ups
StaticallyTypedAnxiety 1bf85dc
comment added
StaticallyTypedAnxiety aca7b55
upgrade submodule
StaticallyTypedAnxiety 049b0c7
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety cec57e2
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety a71bcdd
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety c56d74c
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety e4b0327
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety 0d1eec0
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety 9f9396b
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety a79ef24
changes to pr
StaticallyTypedAnxiety f2db9d5
fixed merge conflicts
StaticallyTypedAnxiety 884958f
applied cargo fmt
StaticallyTypedAnxiety 4305f23
added more rustdoc comments
StaticallyTypedAnxiety b9b826d
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety 7698dea
Update node/state_api/src/lib.rs
StaticallyTypedAnxiety 43c874a
Update blockchain/state_manager/src/call.rs
StaticallyTypedAnxiety 7e73b95
json changes
StaticallyTypedAnxiety 16f9481
pr changes
StaticallyTypedAnxiety 60af581
Merge branch 'ashanti/state_api_rpc_methods' of https://github.com/Ch…
StaticallyTypedAnxiety 75964b0
applied merge conflict changes
StaticallyTypedAnxiety dcc900a
cargo fmt
StaticallyTypedAnxiety 36d0f80
fixed tests
StaticallyTypedAnxiety 035b354
removed unneeded import
StaticallyTypedAnxiety 4573c3d
Merge branch 'main' into ashanti/state_api_rpc_methods
StaticallyTypedAnxiety 61e60b7
Merge branch 'main' into ashanti/state_api_rpc_methods
StaticallyTypedAnxiety 251a820
Update blockchain/state_manager/src/lib.rs
StaticallyTypedAnxiety e746b7a
Update blockchain/state_manager/src/lib.rs
StaticallyTypedAnxiety 8f6b963
Update blockchain/state_manager/src/lib.rs
StaticallyTypedAnxiety ed2f69e
Update blockchain/chain/src/store/chain_store.rs
StaticallyTypedAnxiety 28fbfef
changes based on PR
StaticallyTypedAnxiety 17d56fa
Merge branch 'ashanti/state_api_rpc_methods' of https://github.com/Ch…
StaticallyTypedAnxiety f7fbcba
changes to invoc_result
StaticallyTypedAnxiety d87ddef
state_api changes
StaticallyTypedAnxiety 3890f03
removed for loop
StaticallyTypedAnxiety 639829e
fixed merge confict
StaticallyTypedAnxiety f106d23
Merge branch 'ashanti/state_api_rpc_methods' into rpc_state_implement…
StaticallyTypedAnxiety 91b36c4
Merge branch 'main' into ashanti/state_api_rpc_methods
StaticallyTypedAnxiety dc50d23
Update vm/message/src/lib.rs
StaticallyTypedAnxiety c4ea7a0
Update blockchain/state_manager/src/lib.rs
StaticallyTypedAnxiety 76dd011
Update vm/message/src/lib.rs
StaticallyTypedAnxiety de424cd
Added fixes and types
StaticallyTypedAnxiety fd6a0d3
Update blockchain/state_manager/src/lib.rs
StaticallyTypedAnxiety 5dd6269
chain message introduced
StaticallyTypedAnxiety 61741b0
added comment
StaticallyTypedAnxiety cdbc29a
Merge branch 'ashanti/state_api_rpc_methods' of https://github.com/Ch…
StaticallyTypedAnxiety 00021c5
cargo fmt
StaticallyTypedAnxiety 708b012
moved some comments
StaticallyTypedAnxiety d25df74
added license
StaticallyTypedAnxiety 3dba797
changed error messages
StaticallyTypedAnxiety 9dcb457
changed wait_for_msg algorithmn
StaticallyTypedAnxiety ee0bcdc
merge conflict fixed
StaticallyTypedAnxiety 8186b29
Merge branch 'ashanti/state_api_rpc_methods' into rpc_state_implement…
StaticallyTypedAnxiety 8b2eb89
refactor in progress
StaticallyTypedAnxiety f69db09
refactored to use block_store instead
StaticallyTypedAnxiety 864bc3b
removed fluff
StaticallyTypedAnxiety 1b6fe24
fixed error
StaticallyTypedAnxiety 4f8053a
Merge branch 'ashanti/state_api_rpc_methods' into rpc_state_implement…
StaticallyTypedAnxiety e15074b
refactor in progress
StaticallyTypedAnxiety 79090ab
Merge branch 'main' into rpc_state_implementation
StaticallyTypedAnxiety a78015a
more changes
StaticallyTypedAnxiety 55981aa
changes made
StaticallyTypedAnxiety 290c173
changed to take in statemanager
StaticallyTypedAnxiety adc8be1
cargo fmt
StaticallyTypedAnxiety 18f7b91
serialization changes
StaticallyTypedAnxiety cc00bde
Merged main and cargo fmt
StaticallyTypedAnxiety d515522
Delete randomness.rs.orig
StaticallyTypedAnxiety 7b6fd9b
minor fixes
StaticallyTypedAnxiety 3edeae5
Merge branch 'rpc_state_implementation' of https://github.com/ChainSa…
StaticallyTypedAnxiety d11938d
deleted files
StaticallyTypedAnxiety af92d39
Delete chain_store.rs.orig
StaticallyTypedAnxiety 52dc280
add license headers
StaticallyTypedAnxiety 02c1e89
removed type file
StaticallyTypedAnxiety f5f2762
Merge branch 'rpc_state_implementation' of https://github.com/ChainSa…
StaticallyTypedAnxiety 2395f9d
Merge branch 'main' into rpc_state_implementation
StaticallyTypedAnxiety c0e2f35
clippy fixes
StaticallyTypedAnxiety daa894a
Merge branch 'rpc_state_implementation' of https://github.com/ChainSa…
StaticallyTypedAnxiety d860bdf
fixed tests
StaticallyTypedAnxiety 06be1e2
Update node/rpc/Cargo.toml
StaticallyTypedAnxiety 9c92a15
Update node/rpc/src/lib.rs
StaticallyTypedAnxiety 2b6ea70
Update vm/address/Cargo.toml
StaticallyTypedAnxiety ee93ca5
made changes to name and serialization
StaticallyTypedAnxiety 2d96eef
Merge branch 'rpc_state_implementation' of https://github.com/ChainSa…
StaticallyTypedAnxiety 90064eb
changes to use tipset_from_keys function
StaticallyTypedAnxiety 6a206ce
BitField Serialization Fixed
StaticallyTypedAnxiety 85f3e52
changes to PR
StaticallyTypedAnxiety 8d8977d
bumped address version
StaticallyTypedAnxiety 6eb1408
Update vm/address/Cargo.toml
StaticallyTypedAnxiety 0b99184
pascal case serialize/deserialize
StaticallyTypedAnxiety fbce258
Merge branch 'rpc_state_implementation' of https://github.com/ChainSa…
StaticallyTypedAnxiety a7c7cc3
Update utils/bitfield/src/lib.rs
StaticallyTypedAnxiety 8d913ea
Update utils/bitfield/src/lib.rs
StaticallyTypedAnxiety 6899663
Update utils/bitfield/src/lib.rs
StaticallyTypedAnxiety 94dd2d6
Made cleanups on PR
StaticallyTypedAnxiety 9452c8b
Merge branch 'main' into rpc_state_implementation
StaticallyTypedAnxiety File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ use interpreter::{resolve_to_key_addr, ApplyRet, ChainRand, DefaultSyscalls, VM} | |
use ipld_amt::Amt; | ||
use log::{trace, warn}; | ||
use message::{Message, MessageReceipt, UnsignedMessage}; | ||
use num_bigint::BigInt; | ||
use num_bigint::{bigint_ser, BigInt}; | ||
use serde::{Deserialize, Serialize}; | ||
use state_tree::StateTree; | ||
use std::collections::HashMap; | ||
use std::error::Error as StdError; | ||
|
@@ -37,22 +38,23 @@ use std::sync::Arc; | |
pub type CidPair = (Cid, Cid); | ||
|
||
/// Type to represent invocation of state call results | ||
pub struct InvocResult<Msg> | ||
where | ||
Msg: Message, | ||
{ | ||
pub msg: Msg, | ||
#[derive(Serialize, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct InvocResult { | ||
pub msg: UnsignedMessage, | ||
pub msg_rct: Option<MessageReceipt>, | ||
pub actor_error: Option<String>, | ||
pub error: Option<String>, | ||
} | ||
|
||
// An alias Result that represents an InvocResult and an Error | ||
pub type StateCallResult<T> = Result<InvocResult<T>, Error>; | ||
pub type StateCallResult = Result<InvocResult, Error>; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Default)] | ||
#[derive(Default, Serialize, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct MarketBalance { | ||
#[serde(with = "bigint_ser")] | ||
escrow: BigInt, | ||
#[serde(with = "bigint_ser")] | ||
locked: BigInt, | ||
} | ||
|
||
|
@@ -233,7 +235,7 @@ where | |
bstate: &Cid, | ||
rand: &ChainRand, | ||
bheight: &ChainEpoch, | ||
) -> StateCallResult<UnsignedMessage> | ||
) -> StateCallResult | ||
where | ||
DB: BlockStore, | ||
{ | ||
|
@@ -270,17 +272,13 @@ where | |
Ok(InvocResult { | ||
msg: msg.clone(), | ||
msg_rct: Some(apply_ret.msg_receipt.clone()), | ||
actor_error: apply_ret.act_error.map(|e| e.to_string()), | ||
error: apply_ret.act_error.map(|e| e.to_string()), | ||
}) | ||
}) | ||
} | ||
|
||
/// runs the given message and returns its result without any persisted changes. | ||
pub fn call( | ||
&self, | ||
message: &mut UnsignedMessage, | ||
tipset: Option<Tipset>, | ||
) -> StateCallResult<UnsignedMessage> | ||
pub fn call(&self, message: &mut UnsignedMessage, tipset: Option<Tipset>) -> StateCallResult | ||
where | ||
DB: BlockStore, | ||
{ | ||
|
@@ -375,6 +373,53 @@ where | |
}) | ||
} | ||
|
||
fn tipset_executed_message( | ||
block_store: &DB, | ||
tipset: &Tipset, | ||
cid: &Cid, | ||
(message_from_address, message_sequence): (&Address, &u64), | ||
ec2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> Result<Option<MessageReceipt>, Error> | ||
where | ||
DB: BlockStore, | ||
{ | ||
if tipset.epoch() == 0 { | ||
return Ok(None); | ||
} | ||
let tipset = chain::tipset_from_keys(block_store, tipset.parents()) | ||
.map_err(|err| Error::Other(err.to_string()))?; | ||
let messages = chain::messages_for_tipset(block_store, &tipset) | ||
.map_err(|err| Error::Other(err.to_string()))?; | ||
messages | ||
.iter() | ||
.enumerate() | ||
.rev() | ||
austinabell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.filter(|(_, s)| s.from() == message_from_address) | ||
.filter_map(|(index,s)| { | ||
if s.sequence() == *message_sequence { | ||
if s.cid().map(|s| &s == cid).unwrap_or_default() { | ||
return Some( | ||
chain::get_parent_reciept( | ||
block_store, | ||
tipset.blocks().first().unwrap(), | ||
index as u64, | ||
) | ||
.map_err(|err| { | ||
Error::Other(err.to_string()) | ||
}), | ||
); | ||
} | ||
let error_msg = format!("found message with equal nonce as the one we are looking for (F:{:} n {:}, TS: `Error Converting message to Cid` n{:})", cid, message_sequence, s.sequence()); | ||
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. can break this up with adding a |
||
return Some(Err(Error::Other(error_msg))) | ||
} | ||
if s.sequence() < *message_sequence { | ||
return Some(Ok(None)); | ||
} | ||
|
||
None | ||
}) | ||
.next() | ||
.unwrap_or_else(|| Ok(None)) | ||
austinabell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
fn search_back_for_message( | ||
block_store: Arc<DB>, | ||
current: &Tipset, | ||
|
@@ -445,54 +490,6 @@ where | |
Ok(message_receipt) | ||
} | ||
|
||
fn tipset_executed_message( | ||
block_store: &DB, | ||
tipset: &Tipset, | ||
cid: &Cid, | ||
(message_from_address, message_sequence): (&Address, &u64), | ||
) -> Result<Option<MessageReceipt>, Error> | ||
where | ||
DB: BlockStore, | ||
{ | ||
if tipset.epoch() == 0 { | ||
return Ok(None); | ||
} | ||
let tipset = chain::tipset_from_keys(block_store, tipset.parents()) | ||
.map_err(|err| Error::Other(err.to_string()))?; | ||
let messages = chain::messages_for_tipset(block_store, &tipset) | ||
.map_err(|err| Error::Other(err.to_string()))?; | ||
messages | ||
.iter() | ||
.enumerate() | ||
.rev() | ||
.filter(|(_, s)| s.from() == message_from_address) | ||
.filter_map(|(index,s)| { | ||
if s.sequence() == *message_sequence { | ||
if s.cid().map(|s| &s == cid).unwrap_or_default() { | ||
return Some( | ||
chain::get_parent_reciept( | ||
block_store, | ||
tipset.blocks().first().unwrap(), | ||
index as u64, | ||
) | ||
.map_err(|err| { | ||
Error::Other(err.to_string()) | ||
}), | ||
); | ||
} | ||
let error_msg = format!("found message with equal nonce as the one we are looking for (F:{:} n {:}, TS: `Error Converting message to Cid` n{:})", cid, message_sequence, s.sequence()); | ||
return Some(Err(Error::Other(error_msg))) | ||
} | ||
if s.sequence() < *message_sequence { | ||
return Some(Ok(None)); | ||
} | ||
|
||
None | ||
}) | ||
.next() | ||
.unwrap_or_else(|| Ok(None)) | ||
} | ||
|
||
/// WaitForMessage blocks until a message appears on chain. It looks backwards in the chain to see if this has already | ||
/// happened. It guarantees that the message has been on chain for at least confidence epochs without being reverted | ||
/// before returning. | ||
|
@@ -679,7 +676,7 @@ where | |
state_tree.lookup_id(addr).map_err(Error::State) | ||
} | ||
|
||
pub fn market_balance(&mut self, addr: &Address, ts: &Tipset) -> Result<MarketBalance, Error> { | ||
pub fn market_balance(&self, addr: &Address, ts: &Tipset) -> Result<MarketBalance, Error> { | ||
let market_state: market::State = | ||
self.load_actor_state(&*STORAGE_MARKET_ACTOR_ADDR, ts.parent_state())?; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You didn't have to change this one, but doesn't matter
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.
Made sense if wanted to be consistent with lotus