-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: add network-specific pre-state execution in decoder #633
Conversation
trace_decoder/src/core.rs
Outdated
@@ -533,10 +547,147 @@ fn middle<StateTrieT: StateTrie + Clone>( | |||
Ok(out) | |||
} | |||
|
|||
#[allow(unused_variables)] |
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.
only because of the hanging ger_data
when not targeting cdk-erigon
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.
I think we could make this tighter, but I'd prefer a different approach
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.
Note that with the latest suggestion on your discuss
PR, the lint isn't triggered anymore because both conditional blocks would be living in the same binary
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.
This is a first pass (almost complete, but I'd like to check again quickly). It generally looks good, I just have a couple of questions
(block.block_number - 1).to_big_endian(&mut arr[0..32]); | ||
U256::from(STATE_ROOT_STORAGE_POS.1).to_big_endian(&mut arr[32..64]); |
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.
In the link, the slot number seems to be 1|blockNumber
. But this implementation seems to differ? Or am I missing something?
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.
Hmm I'm not sure. In cdk_erigon
, we call:
//save prev block hash
sdb.scalableSetBlockHash(blockNumber-1, prevBlockHash)
with function definition:
func (sdb *IntraBlockState) scalableSetBlockHash(blockNum uint64, blockHash *libcommon.Hash) {
// create mapping with keccak256(blockNum,position) -> smt root
d1 := common.LeftPadBytes(uint256.NewInt(blockNum).Bytes(), 32)
d2 := common.LeftPadBytes(STATE_ROOT_STORAGE_POS.Bytes(), 32)
mapKey := keccak256.Hash(d1, d2)
mkh := libcommon.BytesToHash(mapKey)
hashAsBigU := uint256.NewInt(0).SetBytes(blockHash.Bytes())
sdb.SetState(ADDRESS_SCALABLE_L2, &mkh, *hashAsBigU)
}
i.e. this line: mapKey := keccak256.Hash(d1, d2)
is hashing the concatenation blockNum || STATE_ROOT_STORAGE_POS
i.e. with initial inputs: blockNumber-1 || 0x01
.
Unless I am also missing something
@@ -533,10 +547,147 @@ fn middle<StateTrieT: StateTrie + Clone>( | |||
Ok(out) | |||
} | |||
|
|||
#[allow(unused_variables)] | |||
/// Performs all the pre-txn execution rules of the targeted network. | |||
fn do_pre_execution<StateTrieT: StateTrie + Clone>( |
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.
Are you also storing the BLOCK_INFO_ROOT
?
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.
I believe this is only during post_state_execution, not pre, and following discussions of this morning we may actually not need to write this BLOCK_INFO_ROOT
(pending design decisions)
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.
How do you feel about phrasing this as a runtime rather than compile time idea?
I've sketched this in #643
I'm dubious of any significant performance delta, and the code would be:
- easier to reason about
- get all the affordances of development with no feature gating (better IDE experience etc...)
OK from the |
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.
I don't think I should keep blocking this review on wider architectural decisions. The code is good as is, any arch refactors after the fact are trivial :)
@LindaGuiga let me know if you still need clarifications on the items above @0xaatif would you want me to apply the last suggestion of #643 here or should we keep exploring options? |
I think it's a great suggestion :) happy for it to be included |
What I haven't done:
closes #604