Skip to content
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

Merged
merged 7 commits into from
Jan 17, 2017
Merged

Conversation

Arachnid
Copy link
Contributor

No description provided.

@mention-bot
Copy link

@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)
}
Copy link
Contributor

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',
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

@Arachnid Arachnid Jan 11, 2017

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
}
Copy link
Contributor

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) {
Copy link
Contributor

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.

@Arachnid Arachnid force-pushed the preimage branch 3 times, most recently from 6d122cf to 08c1213 Compare January 11, 2017 09:46
@@ -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) {
Copy link
Contributor

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',
Copy link
Contributor

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.

@GitCop
Copy link

GitCop commented Jan 11, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 82fb946a1835c35da3fae4d627e19825bfab1107
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@Arachnid
Copy link
Contributor Author

Arachnid commented Jan 11, 2017

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
Copy link
Contributor

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.

@GitCop
Copy link

GitCop commented Jan 11, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 82fb946a1835c35da3fae4d627e19825bfab1107
  • Commits must be prefixed with the package(s) they modify

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc

@GitCop
Copy link

GitCop commented Jan 12, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 82fb946a1835c35da3fae4d627e19825bfab1107
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@fjl
Copy link
Contributor

fjl commented Jan 12, 2017

Please rebase on master to remove the ethdb commit.

@GitCop
Copy link

GitCop commented Jan 12, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 303da33
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@fjl
Copy link
Contributor

fjl commented Jan 13, 2017

@Arachnid tests are broken

@GitCop
Copy link

GitCop commented Jan 13, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 303da33
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@karalabe karalabe modified the milestones: 1.5.8, 1.5.7 Jan 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants