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

Mempool Perf fix #1752

Merged
merged 7 commits into from
Jan 22, 2024
Merged

Mempool Perf fix #1752

merged 7 commits into from
Jan 22, 2024

Conversation

tudor-malene
Copy link
Collaborator

@tudor-malene tudor-malene commented Jan 18, 2024

Why this change is needed

We noticed a performance issue with the mempool.
After investigation, it turned out that we weren't aligning the hashes of the converted geth blocks, so the mempool was always in "reorg" mode.

This PR aligns these hashes.

What changes were made as part of this PR

  • store the converted hash of each batch in the database, and create method to retrieve it
  • consolidate the conversion logic into a service because it became complicated
  • cache the shared secret
  • remove some expensive fmt.sprintf
  • add caching for the geth conversion
  • refactor the caching logic to make it reusable
  • replace bigcache with ristretto to avoid serialisation

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Jan 18, 2024

Walkthrough

The overarching changes involve integrating a new gethEncodingService across various components to handle Ethereum encoding operations. This service is now a key part of many structs and their methods, replacing direct calls and imports related to Ethereum header and block creation. Additionally, there is a notable database schema update with the introduction of a converted_hash column, and corresponding changes to the storage interfaces and implementations to handle this new data.

Changes

File(s) Summary
.../geth_encoding.go, .../batch_executor.go, .../rollup_compression.go, .../enclave.go, .../chain_context.go, .../eth_chainadapter.go, .../evm_facade.go, .../l2_chain.go, .../sequencer.go Introduced gethEncodingService across various components for Ethereum encoding operations and updated function signatures and structs to incorporate this new service.
.../batch.go, .../interfaces.go, .../storage.go Renamed SQL query, added convertedHash parameter to storage functions, and introduced a method to fetch the converted hash.
.../enclavedb/batch.go, .../init/edgelessdb/001_init.sql, .../init/sqlite/001_init.sql Database schema updates to include a new converted_hash column, with updates to SQL initialization scripts and storage interfaces.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 843d6cb and aa57c0c.
Files selected for processing (14)
  • go/common/gethencoding/geth_encoding.go (3 hunks)
  • go/enclave/components/batch_executor.go (5 hunks)
  • go/enclave/components/rollup_compression.go (7 hunks)
  • go/enclave/enclave.go (7 hunks)
  • go/enclave/evm/chain_context.go (2 hunks)
  • go/enclave/evm/ethchainadapter/eth_chainadapter.go (8 hunks)
  • go/enclave/evm/evm_facade.go (4 hunks)
  • go/enclave/l2chain/l2_chain.go (4 hunks)
  • go/enclave/nodetype/sequencer.go (4 hunks)
  • go/enclave/storage/enclavedb/batch.go (4 hunks)
  • go/enclave/storage/init/edgelessdb/001_init.sql (1 hunks)
  • go/enclave/storage/init/sqlite/001_init.sql (2 hunks)
  • go/enclave/storage/interfaces.go (1 hunks)
  • go/enclave/storage/storage.go (6 hunks)
Files skipped from review due to trivial changes (1)
  • go/enclave/storage/init/edgelessdb/001_init.sql
Additional comments: 53
go/enclave/evm/chain_context.go (3)
  • 19-21: The addition of gethEncodingService to the ObscuroChainContext struct is consistent with the PR's objective to integrate a new encoding service.
  • 25-29: The NewObscuroChainContext function has been correctly updated to accept and initialize the new gethEncodingService field.
  • 46-46: The GetHeader method now uses gethEncodingService to create an Ethereum header for a batch. Ensure that the FetchBatch method from storage handles errors correctly and that the CreateEthHeaderForBatch method from gethEncodingService is implemented correctly and tested.
go/enclave/storage/init/sqlite/001_init.sql (1)
  • 60-70: The addition of the converted_hash column to the batch table is consistent with the PR's objective to enhance the handling of Ethereum headers and batch processing. Ensure that all database operations that interact with the batch table are updated to handle the new converted_hash column correctly.
go/enclave/evm/ethchainadapter/eth_chainadapter.go (7)
  • 26-26: The addition of gethEncoding to the EthChainAdapter struct aligns with the PR's objective to use a new encoding service across various components.
  • 33-38: The NewEthChainAdapter function has been correctly updated to accept the new gethEncoding parameter and initialize the corresponding struct field.
  • 60-60: The CurrentBlock method now uses gethEncoding to convert a batch header to an Ethereum header. Ensure that the CreateEthHeaderForBatch method from gethEncoding is implemented correctly and tested.
  • 86-86: The GetBlock method's signature has been updated to use gethcommon.Hash instead of common.Hash. Ensure that all calls to this method are updated accordingly and that the method's implementation correctly handles the new type.
  • 111-111: The CreateEthBlockFromBatch method from gethEncoding is used here. Verify that this method is correctly implemented and tested.
  • 121-121: The StateAt method's signature has been updated to use gethcommon.Hash. Ensure that all calls to this method are updated accordingly and that the method's implementation correctly handles the new type.
  • 130-130: The IngestNewBlock method now uses gethEncoding to convert a batch to an Ethereum block. Verify that the CreateEthBlockFromBatch method is correctly implemented and tested.
go/enclave/storage/interfaces.go (2)
  • 58-58: The addition of the FetchConvertedHash method to the BatchResolver interface is consistent with the PR's objective to handle converted hashes in the system.
  • 67-67: The StoreBatch method signature has been correctly updated to include a convertedHash parameter. Ensure that all implementations of this method are updated to handle the new parameter correctly.
go/enclave/evm/evm_facade.go (5)
  • 37-37: The ExecuteTransactions function now requires an additional gethEncodingService parameter. Ensure that all calls to this function are updated to pass the new parameter.
  • 50-50: The CreateEthHeaderForBatch function is called from the gethEncodingService interface. Verify that this function is correctly implemented and tested.
  • 161-161: The initParams function's signature has been modified to include the gethEncodingService parameter. Ensure that all calls to this function are updated to pass the new parameter.
  • 177-177: The CreateEthHeaderForBatch function is called from the gethEncodingService interface within the ExecuteObsCall function. Verify that this function is correctly implemented and tested.
  • 212-212: The initParams function has been updated to create a new ObscuroChainContext with the gethEncodingService. Ensure that the NewObscuroChainContext function is correctly implemented and tested.
go/enclave/l2chain/l2_chain.go (4)
  • 32-34: The obscuroChain struct has been updated to include the gethEncodingService field, which is consistent with the PR's objectives.
  • 44-58: The NewChain function has been updated to accept and initialize the gethEncodingService field. Ensure that all calls to this function are updated to pass the new parameter.
  • 153-153: The ObsCallAtBlock function now uses gethEncodingService to execute an Ethereum call. Verify that the ExecuteObsCall function from evm is correctly implemented and tested.
  • 197-199: The GetChainStateAtTransaction function now uses gethEncodingService to create an Ethereum header for a batch. Verify that the CreateEthHeaderForBatch function is correctly implemented and tested.
go/common/gethencoding/geth_encoding.go (5)
  • 49-52: The EncodingService interface has been correctly defined with the methods CreateEthHeaderForBatch and CreateEthBlockFromBatch.
  • 54-60: The gethEncodingServiceImpl struct has been introduced with a cache for converted values and is correctly initialized in the NewGethEncodingService function.
  • 62-80: The NewGethEncodingService function has been updated to include a context parameter and initialize a cache. Ensure that the cache is correctly configured and that the context is handled appropriately throughout the service's methods.
  • 277-346: The CreateEthHeaderForBatch method has been updated to use a cache for storing and retrieving values. Ensure that the caching mechanism is correctly implemented and that the method correctly handles cache misses and errors.
  • 366-384: The CreateEthBlockFromBatch method has been updated to create a local block and assign values to its fields. Ensure that the method correctly initializes all necessary fields of the types.Block and that the conversion from localBlock to types.Block is safe and correct.
go/enclave/nodetype/sequencer.go (3)
  • 51-51: The addition of gethEncoding to the sequencer struct is consistent with the PR's objective to integrate gethEncodingService across various components.
  • 66-74: The NewSequencer function signature has been correctly updated to include the gethEncodingService parameter. Ensure that all calls to this constructor are updated accordingly.
Verification successful

The search with rg has identified a call to NewSequencer in the file go/enclave/enclave.go. However, the output does not show the parameters passed to the function, which are necessary to verify if the gethEncodingService parameter is included in the call. To confirm this, we need to inspect the parameters of the NewSequencer function call in go/enclave/enclave.go.


The extracted parameters from the NewSequencer function call in go/enclave/enclave.go include gethEncodingService. This confirms that the call has been updated to include the new gethEncodingService parameter as required by the updated function signature.

Based on the information gathered, the review comment has been verified, and the necessary updates to the NewSequencer function calls have been made to include the gethEncodingService parameter.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for NewSequencer function calls to ensure they include the new parameter.
ast-grep --lang go --pattern $'NewSequencer($$$)' | grep -v 'gethEncodingService'

Length of output: 80



Script:

#!/bin/bash
# Search for calls to NewSequencer and display the parameters to verify the inclusion of gethEncodingService.
ast-grep --lang go --pattern $'NewSequencer($$$)'

Length of output: 50



Script:

#!/bin/bash
# Use ripgrep to search for the string "NewSequencer" to find any potential calls.
rg 'NewSequencer'

Length of output: 792



Script:

#!/bin/bash
# Extract the parameters passed to the NewSequencer function call in go/enclave/enclave.go
rg 'NewSequencer\(' go/enclave/enclave.go -A 10

Length of output: 253

* 302-307: The `StoreExecutedBatch` method now uses `gethEncoding` to create an Ethereum header for the batch and stores it with the batch in the storage. This change aligns with the PR's objectives and appears to be correctly implemented.
go/enclave/components/batch_executor.go (3)
  • 39-39: The gethEncodingService field has been added to the batchExecutor struct. This change is consistent with the PR's objectives.
  • 51-57: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [54-64]

The NewBatchExecutor function signature has been updated to include the gethEncodingService parameter. This is a necessary change for the integration of the new service.

  • 425-425: The processTransactions method has been updated to pass executor.gethEncodingService to the evm.ExecuteTransactions function. This change is in line with the PR's objectives to use the new encoding service.
go/enclave/storage/enclavedb/batch.go (3)
  • 28-28: The SQL query string bInsert has been renamed to batchInsert. This is a minor change and does not affect functionality.
  • 52-52: The WriteBatchAndTransactions function now includes a convertedHash parameter. This change is consistent with the PR's objectives to store the converted hash in the database.
  • 550-563: A new function FetchConvertedBatchHash has been introduced to retrieve the converted batch hash from the database. This function is necessary for the new functionality introduced in the PR.
go/enclave/components/rollup_compression.go (5)
  • 54-54: The gethEncodingService field has been added to the RollupCompression struct.
  • 63-69: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [66-76]

The NewRollupCompression function now initializes the gethEncodingService field.

  • 430-438: The executeAndSaveIncompleteBatches method now uses gethEncodingService to create Ethereum headers for batches and store them. Ensure that the CreateEthHeaderForBatch method handles errors correctly and that the StoreBatch method is correctly updated to handle the new convertedHash parameter.
  • 460-465: The executeAndSaveIncompleteBatches method also uses gethEncodingService for the genesis batch. Verify that the CreateEthHeaderForBatch and StoreBatch methods are correctly implemented and handle errors appropriately.
  • 502-507: Again in the executeAndSaveIncompleteBatches method, gethEncodingService is used for computing the batch. Ensure that the CreateEthHeaderForBatch and StoreBatch methods are correctly implemented and handle errors appropriately.
go/enclave/storage/storage.go (4)
  • 60-61: The cachedSharedSecret field remains unchanged.
  • 147-161: The FetchConvertedHash method has been added to fetch the converted hash of a batch. Ensure that the method correctly retrieves the converted hash from the database and handles errors appropriately.
  • 239-249: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [243-258]

The FetchSecret method now caches the shared secret. Verify that the caching mechanism works correctly and that the shared secret is properly encoded and decoded.

  • 400-407: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [386-404]

The StoreBatch method signature has been updated to include a convertedHash parameter. Ensure that the WriteBatchAndTransactions method is updated to handle this new parameter and that the method correctly stores the batch and its converted hash in the database.

go/enclave/enclave.go (8)
  • 185-185: The NewBatchExecutor function now includes gethEncodingService as a parameter.

This change is consistent with the integration of gethEncodingService across the system.

  • 192-192: The NewRollupCompression function now includes gethEncodingService as a parameter.

This change is consistent with the integration of gethEncodingService across the system.

  • 196-196: The NewEthChainAdapter function now includes gethEncodingService as a parameter.

This change is consistent with the integration of gethEncodingService across the system.

  • 211-211: The nodetype.NewSequencer function now includes gethEncodingService as a parameter.

This change is consistent with the integration of gethEncodingService across the system.

  • 235-235: The l2chain.NewChain function now includes gethEncodingService as a parameter.

This change is consistent with the integration of gethEncodingService across the system.

  • 270-270: The gethEncodingService field is set in the enclaveImpl struct within the NewEnclave function.

This change is consistent with the integration of gethEncodingService across the system.

  • 547-550: The SubmitBatch function now uses gethEncodingService to create an Ethereum header for the batch.

This change is consistent with the integration of gethEncodingService across the system.

  • 553-553: The StoreBatch method in the storage interface now includes a convertedHash parameter.

This change is consistent with the addition of the converted_hash column in the database schema and the integration of gethEncodingService.

@@ -89,6 +89,7 @@ type enclaveImpl struct {

dataEncryptionService crypto.DataEncryptionService
dataCompressionService compression.DataCompressionService
gethEncodingService gethencoding.EncodingService
Copy link

Choose a reason for hiding this comment

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

The gethEncodingService field is added to the enclaveImpl struct without any comments or documentation.

Consider adding comments to explain the purpose and usage of gethEncodingService within the enclaveImpl struct for better maintainability and clarity for future developers.

@@ -171,6 +172,7 @@
obscuroKey := crypto.GetObscuroKey(logger)
rpcEncryptionManager := rpc.NewEncryptionManager(ecies.ImportECDSA(obscuroKey))

gethEncodingService := gethencoding.NewGethEncodingService(storage, logger)
Copy link

Choose a reason for hiding this comment

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

The instantiation of gethEncodingService is done within the NewEnclave function without error handling.

- gethEncodingService := gethencoding.NewGethEncodingService(storage, logger)
+ gethEncodingService, err := gethencoding.NewGethEncodingService(storage, logger)
+ if err != nil {
+     logger.Crit("Failed to create gethEncodingService", log.ErrKey, err)
+     return nil
+ }

Ensure that errors are handled appropriately when creating new instances of services.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
gethEncodingService := gethencoding.NewGethEncodingService(storage, logger)
gethEncodingService, err := gethencoding.NewGethEncodingService(storage, logger)
if err != nil {
logger.Crit("Failed to create gethEncodingService", log.ErrKey, err)
return nil
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between aa57c0c and 0098052.
Files ignored due to path filters (2)
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
Files selected for processing (7)
  • go/common/cache_util.go (1 hunks)
  • go/common/gethencoding/geth_encoding.go (3 hunks)
  • go/enclave/crosschain/block_message_extractor.go (2 hunks)
  • go/enclave/crosschain/common.go (2 hunks)
  • go/enclave/events/subscription_manager.go (4 hunks)
  • go/enclave/storage/storage.go (11 hunks)
  • integration/simulation/utils.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • go/enclave/crosschain/block_message_extractor.go
Files skipped from review as they are similar to previous changes (2)
  • go/common/gethencoding/geth_encoding.go
  • go/enclave/storage/storage.go
Additional comments: 7
go/common/cache_util.go (1)
  • 11-23: The GetCachedValue function retrieves a value from the cache or uses the onFailed callback if the value is not present. The error handling and caching logic seem appropriate.
integration/simulation/utils.go (2)
  • 34-34: The setupSimTestLog function has been modified to change the log level. This change will reduce the verbosity of logs, which could impact debugging. Ensure this change aligns with the desired logging policy.

Verify that the reduced log verbosity is acceptable for simulation tests.

  • 132-132: The sleepRndBtw function now divides the sleep duration by 5. This change affects the timing behavior of simulations and could have downstream effects on test outcomes.

Confirm that the change in sleep duration calculation is intended and does not negatively impact the simulation tests.

go/enclave/crosschain/common.go (2)
  • 8-8: The new import of the log package is consistent with the changes in the file.
  • 28-29: The lazilyLogReceiptChecksum function's parameter type has been changed. Ensure that all calls to this function have been updated to pass a pointer to common.L1Block instead of a string.
Verification successful

The search within block_message_extractor.go has provided several instances where the block variable is used. Notably, the function signatures for StoreCrossChainValueTransfers, StoreCrossChainMessages, and getCrossChainMessages indicate that block is a pointer to common.L1Block. This confirms that the block variable passed to lazilyLogReceiptChecksum is of the correct type as per the updated function signature.

Based on this information, we can conclude that the call to lazilyLogReceiptChecksum in block_message_extractor.go is using the correct parameter type, which is a pointer to common.L1Block.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for calls to lazilyLogReceiptChecksum to ensure they pass the correct parameter type.
ast-grep --lang go --pattern $'lazilyLogReceiptChecksum($_, $_, $_)'

Length of output: 176



Script:

#!/bin/bash
# Extract the specific line where lazilyLogReceiptChecksum is called to verify the parameter type.
rg --context 0 'lazilyLogReceiptChecksum\(.*\)' ./go/enclave/crosschain/block_message_extractor.go

Length of output: 153



Script:

#!/bin/bash
# Find the declaration or assignment of the 'block' variable to verify its type.
ast-grep --lang go --pattern $'var block *common.L1Block = $_'

Length of output: 63



Script:

#!/bin/bash
# Search for any assignment to the 'block' variable or its usage that would indicate its type.
rg 'block :=' ./go/enclave/crosschain/block_message_extractor.go

Length of output: 66



Script:

#!/bin/bash
# Search for any usage of the 'block' variable within the block_message_extractor.go file to infer its type.
rg 'block' ./go/enclave/crosschain/block_message_extractor.go

Length of output: 2213

go/enclave/events/subscription_manager.go (2)
  • 158-158: The change in the logging statement within the GetSubscribedLogsForBatch function uses structured logging instead of formatted strings, which is a good practice for consistency and readability.
  • 244-244: The changes to the logging statements in the filterLogs function also switch to structured logging. This is a positive change for the reasons mentioned above.

Also applies to: 248-248, 253-253, 258-258, 270-270

Comment on lines +26 to +31
func CacheValue[V any](cache *cache.Cache[V], logger gethlog.Logger, key any, v V) {
err := cache.Set(context.Background(), key, v)
if err != nil {
logger.Error("Could not store value in cache", log.ErrKey, err)
}
}
Copy link

Choose a reason for hiding this comment

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

The CacheValue function stores a value in the cache and logs an error if it fails. The error handling is correct, but it might be beneficial to consider whether the error should be returned to the caller instead of just logged.

Consider returning the error from CacheValue to allow the caller to handle it as needed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0098052 and 352ffba.
Files selected for processing (1)
  • go/enclave/vkhandler/vk_handler.go (2 hunks)

Comment on lines 66 to 74
type customRnd struct {
}

func (rnd *customRnd) Read(p []byte) (n int, err error) {
for i := range p {
p[i] = 1
}
return len(p), nil
}
Copy link

Choose a reason for hiding this comment

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

The customRnd type and its Read method have been introduced to replace the standard random number generator with a non-random one that fills the byte slice with 1s. This is a significant change in behavior and could have security implications, as it replaces secure random number generation with a predictable pattern. This should only be used for testing purposes and not in production code.

}

// used for checking the source of slowness
var nonRandomTestReader = &customRnd{}
Copy link

Choose a reason for hiding this comment

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

The global variable nonRandomTestReader is used for checking the source of slowness. Using a global variable for this purpose is not thread-safe and could lead to unpredictable behavior if used in a concurrent context. Additionally, this should be clearly documented as for testing purposes only and should not be present in production code.

// Encrypt returns the payload encrypted with the viewingKey
func (m *VKHandler) Encrypt(bytes []byte) ([]byte, error) {
if len(bytes) == 0 {
bytes = placeholderResult
}

encryptedBytes, err := ecies.Encrypt(rand.Reader, m.publicViewingKey, bytes, nil, nil)
encryptedBytes, err := ecies.Encrypt(nonRandomTestReader, m.publicViewingKey, bytes, nil, nil)
Copy link

Choose a reason for hiding this comment

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

The Encrypt method has been modified to use nonRandomTestReader instead of rand.Reader. This change should be carefully reviewed to ensure that it is only for testing purposes, as it would make the encryption deterministic and insecure. If this is for testing, it should be wrapped in a conditional compilation flag or a configuration option to prevent it from being used in a production environment.

@@ -82,7 +82,7 @@ func (m *blockMessageExtractor) StoreCrossChainMessages(block *common.L1Block, r
return nil
}

lazilyLogReceiptChecksum(fmt.Sprintf("Processing block: %s receipts: %d", block.Hash(), len(receipts)), receipts, m.logger)
lazilyLogReceiptChecksum(block, receipts, m.logger)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

avoid the sprintf when the log level does not need it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 352ffba and 5538ec5.
Files selected for processing (5)
  • go/common/cache_util.go (1 hunks)
  • go/common/gethencoding/geth_encoding.go (3 hunks)
  • go/common/types.go (1 hunks)
  • go/enclave/enclave.go (7 hunks)
  • go/enclave/storage/storage.go (11 hunks)
Files skipped from review due to trivial changes (1)
  • go/common/types.go
Files skipped from review as they are similar to previous changes (4)
  • go/common/cache_util.go
  • go/common/gethencoding/geth_encoding.go
  • go/enclave/enclave.go
  • go/enclave/storage/storage.go

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

Nice, this looks super fiddly but think it makes sense and is just a fiddly problem. Couple minor comments but LGTM

func NewGethEncodingService(storage storage.Storage, logger gethlog.Logger) EncodingService {
// todo (tudor) figure out the best values
ristrettoCache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: 1000, // number of keys to track frequency of 100.
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: comment says 100 but value says 1000

transactions: b.Transactions,
withdrawals: nil,
}
block := *(*types.Block)(unsafe.Pointer(&lb))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe worth a comment on this line to say something like "these operations force casting of the localBlock to the geth Block type. This was necessary because we can't access the header directly on geth Block"

which I think is what's going on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I literally have this comment on the localBlock type

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh yeah sorry, I guess maybe worth a // cast to Block here but up to you, it slowed down my scanning because it looked like such a scary line lol.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5538ec5 and 94e603c.
Files selected for processing (1)
  • go/common/gethencoding/geth_encoding.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • go/common/gethencoding/geth_encoding.go

@tudor-malene tudor-malene merged commit 0fe01b4 into main Jan 22, 2024
2 checks passed
@tudor-malene tudor-malene deleted the tudor/mempool_perf branch January 22, 2024 12:03
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.

2 participants