-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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
Add support for recording SHA3 preimages #3543
Conversation
@Arachnid, thanks for your PR! By analyzing the history of the files in this pull request, we identified @obscuren, @jimenezrick and @karalabe to be potential reviewers. |
@@ -595,6 +600,31 @@ func GetMipmapBloom(db ethdb.Database, number, level uint64) types.Bloom { | |||
return types.BytesToBloom(bloomDat) | |||
} | |||
|
|||
func GetPreimageTable(db ethdb.Database) ethdb.Database { | |||
return ethdb.NewDatabaseTable(db, preimagePrefix) | |||
} |
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.
naming suggestion: "PreimageTable" (without Get prefix)
}), | ||
new web3._extend.Method({ | ||
name: 'getPreimage', | ||
call: 'debug_getPreimage', |
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.
The new operation should be called debug_preimage
@@ -1003,6 +1005,10 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { | |||
if err := WriteMipmapBloom(self.chainDb, block.NumberU64(), receipts); err != nil { | |||
return i, err | |||
} | |||
// Write hash preimages | |||
if err := WritePreimages(self.chainDb, block.NumberU64(), self.stateCache.Preimages()); err != nil { |
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.
Please write preimages as part of the state commit.
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.
Doing this introduces an import cycle - state imports core (for database_util), which imports state. This could be solved by removing all the preimage stuff from database_util, but reducing duplication in the number of places where we specify table prefixes etc seems like a Good Thing. Thoughts?
|
||
func (self *StateDB) Preimages() map[common.Hash][]byte { | ||
return self.preimages | ||
} |
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 don't need this method if you write them during Commit here.
@@ -199,6 +204,19 @@ func (self *StateDB) Logs() []*types.Log { | |||
return logs | |||
} | |||
|
|||
func (self *StateDB) AddPreimage(hash common.Hash, preimage []byte) { |
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.
Please document this. It should say that the method is used for recording preimages seen by the VM.
6d122cf
to
08c1213
Compare
@@ -560,3 +560,8 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common. | |||
} | |||
return nil, errors.New("database inconsistency") | |||
} | |||
|
|||
func (api *PrivateDebugAPI) GetPreimage(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { |
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 needs to be renamed to Preimage
@@ -385,6 +385,12 @@ web3._extend({ | |||
call: 'debug_traceTransaction', | |||
params: 2, | |||
inputFormatter: [null, null] | |||
}), | |||
new web3._extend.Method({ | |||
name: 'getPreimage', |
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.
Please call it preimage
in JS to reduce confusion.
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
After running some stats on a full-synced node, there are about 2M EVM sha3 preimages, with ~370MB of values (plus ~40 bytes per key, plus overhead). Given the low-ish volume, I'm thinking it probably makes sense to dump the flag and just record these unconditionally like we do for trie preimages. For context, there are 21M trie preimages, totalling ~446M of values. Thoughts? |
@@ -97,8 +98,9 @@ type Config struct { | |||
GpobaseStepUp int | |||
GpobaseCorrectionFactor int | |||
|
|||
EnableJit bool | |||
ForceJit bool | |||
EnableJit bool |
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 one and ForceJit
may be deleted.
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
@@ -595,6 +600,31 @@ func GetMipmapBloom(db ethdb.Database, number, level uint64) types.Bloom { | |||
return types.BytesToBloom(bloomDat) | |||
} | |||
|
|||
func PreimageTable(db ethdb.Database) ethdb.Database { |
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.
Please document this function
return ethdb.NewTable(db, preimagePrefix) | ||
} | ||
|
||
func WritePreimages(db ethdb.Database, number uint64, preimages map[common.Hash][]byte) error { |
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.
Doc
@@ -560,3 +560,8 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common. | |||
} | |||
return nil, errors.New("database inconsistency") | |||
} | |||
|
|||
func (api *PrivateDebugAPI) Preimage(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) { |
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.
Doc
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
Please rebase on master to remove the ethdb commit. |
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
@Arachnid tests are broken |
Thank you for your contribution! Your commits seem to not adhere to the repository coding standards
Please check the contribution guidelines for more details. This message was auto-generated by https://gitcop.com |
No description provided.