Skip to content

Commit 7317ca3

Browse files
committed
fix: use correct state for eth_getCode and eth_getStorageAt
1 parent a317adf commit 7317ca3

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
- [#6327](https://github.com/ChainSafe/forest/pull/6327) Fixed: Forest returns 404 for all invalid api paths.
3939

40+
- [#6140](https://github.com/ChainSafe/forest/pull/6140) Fixed the `eth_getLogs` RPC method to accept `None` as the `address` parameter.
41+
4042
## Forest v0.30.5 "Dulce de Leche"
4143

4244
Non-mandatory release supporting new API methods and addressing a critical panic issue.
@@ -119,7 +121,6 @@ The release includes new CLI commands for snapshot management and state inspecti
119121

120122
- [#6103](https://github.com/ChainSafe/forest/pull/6103) Fixed `eth_getTransactionCount` to return the nonce of the requested tipset and not its parent.
121123

122-
- [#6140](https://github.com/ChainSafe/forest/pull/6140) Fixed the `eth_getLogs` RPC method to accept `None` as the `address` parameter.
123124

124125
## Forest v0.30.1 "Laurelin"
125126

src/rpc/methods/eth.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,9 +2157,10 @@ impl RpcMethod<2> for EthGetCode {
21572157
..Default::default()
21582158
};
21592159

2160+
let (state, _) = ctx.state_manager.tipset_state(&ts).await?;
21602161
let api_invoc_result = 'invoc: {
21612162
for ts in ts.chain(ctx.store()) {
2162-
match ctx.state_manager.call(&message, Some(ts)) {
2163+
match ctx.state_manager.call_on_state(state, &message, Some(ts)) {
21632164
Ok(res) => {
21642165
break 'invoc res;
21652166
}
@@ -2208,10 +2209,8 @@ impl RpcMethod<3> for EthGetStorageAt {
22082209
ResolveNullTipset::TakeOlder,
22092210
)?;
22102211
let to_address = FilecoinAddress::try_from(&eth_address)?;
2211-
let Some(actor) = ctx
2212-
.state_manager
2213-
.get_actor(&to_address, *ts.parent_state())?
2214-
else {
2212+
let (state, _) = ctx.state_manager.tipset_state(&ts).await?;
2213+
let Some(actor) = ctx.state_manager.get_actor(&to_address, state)? else {
22152214
return Ok(make_empty_result());
22162215
};
22172216

@@ -2230,7 +2229,7 @@ impl RpcMethod<3> for EthGetStorageAt {
22302229
};
22312230
let api_invoc_result = 'invoc: {
22322231
for ts in ts.chain(ctx.store()) {
2233-
match ctx.state_manager.call(&message, Some(ts)) {
2232+
match ctx.state_manager.call_on_state(state, &message, Some(ts)) {
22342233
Ok(res) => {
22352234
break 'invoc res;
22362235
}

src/state_manager/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,14 @@ where
582582
#[instrument(skip(self, rand))]
583583
fn call_raw(
584584
&self,
585+
state_cid: Option<Cid>,
585586
msg: &Message,
586587
rand: ChainRand<DB>,
587588
tipset: &Tipset,
588589
) -> Result<ApiInvocResult, Error> {
589590
let mut msg = msg.clone();
590591

591-
let state_cid = tipset.parent_state();
592+
let state_cid = state_cid.unwrap_or(*tipset.parent_state());
592593

593594
let tipset_messages = self
594595
.chain_store()
@@ -606,14 +607,14 @@ where
606607
let mut vm = VM::new(
607608
ExecutionContext {
608609
heaviest_tipset: tipset.clone(),
609-
state_tree_root: *state_cid,
610+
state_tree_root: state_cid,
610611
epoch: height,
611612
rand: Box::new(rand),
612613
base_fee: tipset.block_headers().first().parent_base_fee.clone(),
613614
circ_supply: genesis_info.get_vm_circulating_supply(
614615
height,
615616
self.blockstore(),
616-
state_cid,
617+
&state_cid,
617618
)?,
618619
chain_config: self.chain_config().clone(),
619620
chain_index: self.chain_index().clone(),
@@ -660,7 +661,20 @@ where
660661
pub fn call(&self, message: &Message, tipset: Option<Tipset>) -> Result<ApiInvocResult, Error> {
661662
let ts = tipset.unwrap_or_else(|| self.heaviest_tipset());
662663
let chain_rand = self.chain_rand(ts.clone());
663-
self.call_raw(message, chain_rand, &ts)
664+
self.call_raw(None, message, chain_rand, &ts)
665+
}
666+
667+
/// Same as [`StateManager::call`] but runs the message on the given state and not
668+
/// on the parent state of the tipset.
669+
pub fn call_on_state(
670+
&self,
671+
state_cid: Cid,
672+
message: &Message,
673+
tipset: Option<Tipset>,
674+
) -> Result<ApiInvocResult, Error> {
675+
let ts = tipset.unwrap_or_else(|| self.cs.heaviest_tipset());
676+
let chain_rand = self.chain_rand(ts.clone());
677+
self.call_raw(Some(state_cid), message, chain_rand, &ts)
664678
}
665679

666680
pub async fn apply_on_state_with_gas(

0 commit comments

Comments
 (0)