Skip to content

Commit 7a773d0

Browse files
committed
fix: use correct state for eth_getCode and eth_getStorageAt
1 parent a68b350 commit 7a773d0

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/rpc/methods/eth.rs

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

2125+
let (state, _) = ctx.state_manager.tipset_state(&ts).await?;
21252126
let api_invoc_result = 'invoc: {
21262127
for ts in ts.chain_arc(ctx.store()) {
2127-
match ctx.state_manager.call(&message, Some(ts)) {
2128+
match ctx.state_manager.call_on_state(state, &message, Some(ts)) {
21282129
Ok(res) => {
21292130
break 'invoc res;
21302131
}
@@ -2173,10 +2174,8 @@ impl RpcMethod<3> for EthGetStorageAt {
21732174
ResolveNullTipset::TakeOlder,
21742175
)?;
21752176
let to_address = FilecoinAddress::try_from(&eth_address)?;
2176-
let Some(actor) = ctx
2177-
.state_manager
2178-
.get_actor(&to_address, *ts.parent_state())?
2179-
else {
2177+
let (state, _) = ctx.state_manager.tipset_state(&ts).await?;
2178+
let Some(actor) = ctx.state_manager.get_actor(&to_address, state)? else {
21802179
return Ok(make_empty_result());
21812180
};
21822181

@@ -2195,7 +2194,7 @@ impl RpcMethod<3> for EthGetStorageAt {
21952194
};
21962195
let api_invoc_result = 'invoc: {
21972196
for ts in ts.chain_arc(ctx.store()) {
2198-
match ctx.state_manager.call(&message, Some(ts)) {
2197+
match ctx.state_manager.call_on_state(state, &message, Some(ts)) {
21992198
Ok(res) => {
22002199
break 'invoc res;
22012200
}

src/state_manager/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,14 @@ where
521521
#[instrument(skip(self, rand))]
522522
fn call_raw(
523523
self: &Arc<Self>,
524+
state_cid: Option<Cid>,
524525
msg: &Message,
525526
rand: ChainRand<DB>,
526527
tipset: &Arc<Tipset>,
527528
) -> Result<ApiInvocResult, Error> {
528529
let mut msg = msg.clone();
529530

530-
let state_cid = tipset.parent_state();
531+
let state_cid = state_cid.unwrap_or(*tipset.parent_state());
531532

532533
let tipset_messages = self
533534
.chain_store()
@@ -545,14 +546,14 @@ where
545546
let mut vm = VM::new(
546547
ExecutionContext {
547548
heaviest_tipset: Arc::clone(tipset),
548-
state_tree_root: *state_cid,
549+
state_tree_root: state_cid,
549550
epoch: height,
550551
rand: Box::new(rand),
551552
base_fee: tipset.block_headers().first().parent_base_fee.clone(),
552553
circ_supply: genesis_info.get_vm_circulating_supply(
553554
height,
554555
&self.blockstore_owned(),
555-
state_cid,
556+
&state_cid,
556557
)?,
557558
chain_config: self.chain_config().clone(),
558559
chain_index: self.chain_index().clone(),
@@ -603,7 +604,20 @@ where
603604
) -> Result<ApiInvocResult, Error> {
604605
let ts = tipset.unwrap_or_else(|| self.cs.heaviest_tipset());
605606
let chain_rand = self.chain_rand(Arc::clone(&ts));
606-
self.call_raw(message, chain_rand, &ts)
607+
self.call_raw(None, message, chain_rand, &ts)
608+
}
609+
610+
/// Same as [StateManager::call] but runs the message on the given state and not
611+
/// on the parent state of the tipset.
612+
pub fn call_on_state(
613+
self: &Arc<Self>,
614+
state_cid: Cid,
615+
message: &Message,
616+
tipset: Option<Arc<Tipset>>,
617+
) -> Result<ApiInvocResult, Error> {
618+
let ts = tipset.unwrap_or_else(|| self.cs.heaviest_tipset());
619+
let chain_rand = self.chain_rand(Arc::clone(&ts));
620+
self.call_raw(Some(state_cid), message, chain_rand, &ts)
607621
}
608622

609623
pub async fn apply_on_state_with_gas(

0 commit comments

Comments
 (0)