Skip to content

Commit 3a46441

Browse files
committed
WIP: Debug
1 parent e746325 commit 3a46441

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

core/state_snapshot.go

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ type stateSnapshot struct {
1515
state StateHistoryReader
1616
}
1717

18+
func GetBlockNumber(state StateReader) uint64 {
19+
if snapshot, ok := state.(*stateSnapshot); ok {
20+
return snapshot.blockNumber
21+
}
22+
return 0
23+
}
24+
1825
func NewStateSnapshot(state StateHistoryReader, blockNumber uint64) StateReader {
1926
return &stateSnapshot{
2027
blockNumber: blockNumber,

rpc/v8/trace.go

+41-1
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,49 @@ func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block)
239239
if errors.Is(err, utils.ErrResourceBusy) {
240240
return nil, httpHeader, rpccore.ErrInternal.CloneWithData(rpccore.ThrottledVMErr)
241241
}
242+
243+
res := make([]struct {
244+
Traces []vm.TransactionTrace `json:"traces"`
245+
Error string `json:"error"`
246+
}, len(block.Transactions)-1)
247+
for i := range len(block.Transactions) - 1 {
248+
executionResult, err := h.vm.Execute(block.Transactions[0:i+1], classes, paidFeesOnL1,
249+
&blockInfo, state, network, false, false, false, true)
250+
res[i] = struct {
251+
Traces []vm.TransactionTrace `json:"traces"`
252+
Error string `json:"error"`
253+
}{
254+
Traces: executionResult.Traces,
255+
Error: err.Error(),
256+
}
257+
}
258+
259+
classHash, _ := new(felt.Felt).SetString("0x076791ef97c042f81fbf352ad95f39a22554ee8d7927b2ce3c681f3418b5206a")
260+
headClass, _ := headState.Class(classHash)
261+
blockClass, _ := state.Class(classHash)
262+
242263
// Since we are tracing an existing block, we know that there should be no errors during execution. If we encounter any,
243264
// report them as unexpected errors
244-
return nil, httpHeader, rpccore.ErrUnexpectedError.CloneWithData(err.Error())
265+
return nil, httpHeader, rpccore.ErrUnexpectedError.CloneWithData(struct {
266+
Error string `json:"error"`
267+
StateBlock uint64 `json:"state_block"`
268+
ParentBlock string `json:"parent_block"`
269+
Number uint64 `json:"number"`
270+
Res []struct {
271+
Traces []vm.TransactionTrace `json:"traces"`
272+
Error string `json:"error"`
273+
} `json:"res"`
274+
HeadClass bool `json:"head_class"`
275+
BlockClass bool `json:"block_class"`
276+
}{
277+
Error: err.Error(),
278+
StateBlock: core.GetBlockNumber(state),
279+
ParentBlock: block.ParentHash.String(),
280+
Number: block.Number,
281+
Res: res,
282+
HeadClass: headClass != nil,
283+
BlockClass: blockClass != nil,
284+
})
245285
}
246286

247287
result := make([]TracedBlockTransaction, len(executionResult.Traces))

vm/rust/src/juno_state_reader.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use std::{
2-
ffi::{c_char, c_int, c_uchar, c_void, CStr},
3-
slice,
4-
str::FromStr,
5-
sync::Mutex,
2+
ffi::{c_char, c_int, c_uchar, c_void, CStr}, slice, str::FromStr, sync::Mutex
63
};
74

85
use blockifier::execution::contract_class::RunnableCompiledClass;
@@ -132,6 +129,7 @@ impl StateReader for JunoStateReader {
132129

133130
/// Returns the contract class of the given class hash.
134131
fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult<RunnableCompiledClass> {
132+
dbg!(class_hash);
135133
if let Some(cached_class) = CLASS_CACHE.lock().unwrap().cache_get(&class_hash) {
136134
// skip the cache if it comes from a height higher than ours. Class might be undefined on the height
137135
// that we are reading from right now.
@@ -145,7 +143,14 @@ impl StateReader for JunoStateReader {
145143
// with the same block number but with the state at the end of that block. That is why, we cannot use classes from cache
146144
// if they are cached on the same height that we are executing on. Because they might be cached using a state instance that
147145
// is in the future compared to the state that we are currently executing on, even tho they have the same height.
146+
dbg!("cached", cached_class.cached_on_height, self.height);
148147
if cached_class.cached_on_height < self.height {
148+
if class_hash.0 == StarkFelt::from_str("0x076791ef97c042f81fbf352ad95f39a22554ee8d7927b2ce3c681f3418b5206a").unwrap() {
149+
return Err(StateError::StateReadError(format!(
150+
"cached class {} is not valid for height {}",
151+
class_hash.0, self.height
152+
)));
153+
}
149154
return Ok(cached_class.definition.clone());
150155
}
151156
}
@@ -164,6 +169,7 @@ impl StateReader for JunoStateReader {
164169
Ok(class) => {
165170
let runnable_compiled_class =
166171
RunnableCompiledClass::try_from(class.contract_class).unwrap();
172+
dbg!("set", self.height);
167173
CLASS_CACHE.lock().unwrap().cache_set(
168174
class_hash,
169175
CachedRunnableCompiledClass {
@@ -173,6 +179,12 @@ impl StateReader for JunoStateReader {
173179
cached_on_height: self.height,
174180
},
175181
);
182+
if class_hash.0 == StarkFelt::from_str("0x076791ef97c042f81fbf352ad95f39a22554ee8d7927b2ce3c681f3418b5206a").unwrap() {
183+
return Err(StateError::StateReadError(format!(
184+
"newly fetched class {} is not valid for height {}",
185+
class_hash.0, self.height
186+
)));
187+
}
176188
Ok(runnable_compiled_class)
177189
}
178190
Err(e) => Err(StateError::StateReadError(format!(

0 commit comments

Comments
 (0)