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

Adding geths mempool #1639

Merged
merged 9 commits into from
Nov 15, 2023
Merged

Adding geths mempool #1639

merged 9 commits into from
Nov 15, 2023

Conversation

otherview
Copy link
Contributor

Why this change is needed

Adding geths mempool.

What changes were made as part of this PR

  • Remove the mempool manager
  • Created a blockchain and tx pool wrappers
  • Minor pipelining changes

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 Nov 10, 2023

Walkthrough

The changes involve a significant refactor of the transaction pool (txpool) and blockchain (ethblockchain and ethchainadapter) handling within an Ethereum-like enclave environment. New wrapper types for the transaction pool and blockchain have been introduced, with associated initialization and interaction logic. The sequencer's logic has been updated to interact with these new types, and the transaction issuance process has been optimized. Additionally, tests have been added or updated to reflect these changes, and some configuration values have been adjusted.

Changes

File Path Change Summary
.../gethencoding/geth_encoding.go Added imports and functions for Ethereum block creation; updated GasUsed handling.
.../enclave/enclave.go Multiple changes: added txpool import, updated chainConfig initialization, removed zeroTimestamp, updated storage and debug initialization, replaced mempool with txpool.NewTxPool, and added blockchain initialization.
.../ethblockchain/eth_blockchain.go Introduced EthBlockchain type with methods for chain interaction and block ingestion; added new imports and fields.
.../ethblockchain/eth_chainparams.go Added ChainParams function to return params.ChainConfig based on obscuroChainID.
.../nodetype/sequencer.go Replaced mempool.Manager with *txpool.TxPool, added blockchain *ethblockchain.EthBlockchain, updated function signatures, and refactored batch creation logic.
.../txpool/txpool.go Introduced TxPool type with methods for pool management and transaction handling; added new fields and methods.
.../txpool/txpool_mock_test.go Added new mock implementations for testing BatchRegistry and Storage interfaces.
.../txpool/txpool_test.go Added TestTxPool_AddTransaction_Pending function and applyGenesisState helper function for testing transaction pool behavior.
integration/common/utils.go Increased _awaitReceiptPollingInterval value.
integration/obscuroscan/obscuroscan_test.go Changed transaction issuance process to optimize nonce handling.
integration/simulation/network/network_utils.go Increased GasLimit value in createInMemObscuroNode function.
integration/simulation/simulation.go Updated bridgeFundingToObscuro function to use EthClient() directly and increased sleep duration; added GasTipCap in deployObscuroERC20s function.
.../evm/ethchainadapter/eth_chainadapter.go Created EthChainAdapter type with chain interaction methods and block ingestion function; added new imports and type definition.
.../evm/ethchainadapter/eth_chainparams.go Introduced ChainParams function in new ethchainadapter package to initialize params.ChainConfig.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

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: 12

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 991a2d6 and 7b33b86.
Files selected for processing (10)
  • go/common/gethencoding/geth_encoding.go (3 hunks)
  • go/enclave/enclave.go (7 hunks)
  • go/enclave/ethblockchain/eth_blockchain.go (1 hunks)
  • go/enclave/ethblockchain/eth_chainparams.go (1 hunks)
  • go/enclave/nodetype/sequencer.go (11 hunks)
  • go/enclave/txpool/txpool.go (1 hunks)
  • integration/common/utils.go (1 hunks)
  • integration/obscuroscan/obscuroscan_test.go (1 hunks)
  • integration/simulation/network/network_utils.go (1 hunks)
  • integration/simulation/simulation.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • integration/common/utils.go
  • integration/simulation/simulation.go
Additional comments: 20
go/enclave/ethblockchain/eth_chainparams.go (1)
  • 1-36: The ChainParams function is well implemented. It correctly initializes the params.ChainConfig structure with the provided obscuroChainID and sets all fork blocks to gethcommon.Big0. This implies that all Ethereum protocol upgrades are immediately available from the genesis block. The timestamp fields are also correctly set to zero. Ensure that this configuration aligns with the intended behavior of the Obscuro network.
integration/simulation/network/network_utils.go (1)
  • 94-98: The GasLimit value has been significantly increased. Ensure that this change is compatible with the rest of the system and won't cause any issues such as out-of-memory errors or transaction failures due to exceeding gas limits.
go/common/gethencoding/geth_encoding.go (3)
  • 7-15: New import statements have been added. Ensure that these packages are included in your dependencies.

  • 245-251: The CreateEthHeaderForBatch function has been updated to use the GasUsed value from the input parameter. Ensure that the GasUsed value is being correctly calculated and passed in all calls to this function.

  • 257-263: A new function CreateEthBlockFromBatch has been added. This function creates an Ethereum block from a batch. Ensure that this function is being correctly used and the batch passed to it is properly formed.

func CreateEthBlockFromBatch(b *core.Batch) (*types.Block, error) {
	blockHeader, err := CreateEthHeaderForBatch(b.Header, nil)
	if err != nil {
		return nil, fmt.Errorf("unable to create eth block from batch - %w", err)
	}

	return types.NewBlock(blockHeader, b.Transactions, nil, nil, trie.NewStackTrie(nil)), nil
}
go/enclave/nodetype/sequencer.go (8)
  • 12-18: The new packages ethblockchain and txpool are imported. Ensure that these packages are correctly implemented and tested.

  • 53-62: The sequencer struct has been updated to include mempool and blockchain. Ensure that these fields are correctly used throughout the struct methods.

  • 68-83: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [64-81]

The NewSequencer function has been updated to accept mempool and blockchain as arguments. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 138-140: The initGenesis function now includes logic for signing the batch. Ensure that the signing process is secure and correctly implemented.

  • 146-163: The initGenesis function now includes logic for ingesting the blockchain and starting the mempool. Ensure that these operations are correctly implemented and that error handling is robust.

  • 186-204: The createNewHeadBatch function has been updated to use pending transactions from the mempool. Ensure that the transactions are correctly retrieved and processed.

  • 252-262: The produceBatch function now includes logic for ingesting the blockchain. Ensure that this operation is correctly implemented and that error handling is robust.

  • 363-365: The SubmitTransaction function has been modified to use the txpool.TxPool for adding transactions. Ensure that the transaction is correctly added to the pool.

go/enclave/ethblockchain/eth_blockchain.go (1)
  • 1-153: The new EthBlockchain type and its methods are well-structured and seem to follow good practices. However, there are a few areas that could be improved.
go/enclave/enclave.go (6)
  • 14-17: The new import statements for ethblockchain and txpool are correct and necessary for the changes in this PR.

  • 131-132: The initialization of chainConfig and storage using ethblockchain.ChainParams and storage.NewStorageFromConfig respectively is correct. Ensure that the NewStorageFromConfig function is updated to accept chainConfig as an argument.

  • 220-222: The usage of mempool in the NewSequencer function is correct.

  • 233-234: The usage of blockchain in the NewSequencer function is correct.

  • 239-241: The usage of chainConfig in the NewChain function is correct.

  • 254-254: The usage of chainConfig in the New function of debugger is correct.

integration/obscuroscan/obscuroscan_test.go Show resolved Hide resolved
go/enclave/ethblockchain/eth_blockchain.go Outdated Show resolved Hide resolved
go/enclave/ethblockchain/eth_blockchain.go Outdated Show resolved Hide resolved
go/enclave/ethblockchain/eth_blockchain.go Outdated Show resolved Hide resolved
go/enclave/ethblockchain/eth_blockchain.go Outdated Show resolved Hide resolved
go/enclave/ethblockchain/eth_blockchain.go Outdated Show resolved Hide resolved
go/enclave/txpool/txpool.go Outdated Show resolved Hide resolved
go/enclave/txpool/txpool.go Outdated Show resolved Hide resolved
go/enclave/enclave.go Outdated Show resolved Hide resolved
go/enclave/txpool/txpool.go Show resolved Hide resolved
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 7b33b86 and 2902b42.
Files selected for processing (4)
  • go/enclave/enclave.go (7 hunks)
  • go/enclave/ethblockchain/eth_blockchain.go (1 hunks)
  • go/enclave/nodetype/sequencer.go (11 hunks)
  • go/enclave/txpool/txpool.go (1 hunks)
Additional comments: 24
go/enclave/enclave.go (5)
  • 14-17: The new import statements are correctly added for the new packages.

  • 130-132: The initialization of chainConfig and storage is correct. Ensure that ethblockchain.ChainParams function is correctly implemented and that it returns the expected value.

  • 217-219: The initialization of service is correct. Ensure that the nodetype.NewSequencer function has been updated to accept the new mempool parameter.

  • 230-238: The initialization of service and chain is correct. Ensure that the nodetype.NewValidator and l2chain.NewChain functions have been updated to accept the new parameters.

  • 251-251: The initialization of debug is correct. Ensure that the debugger.New function has been updated to accept the new chainConfig parameter.

go/enclave/txpool/txpool.go (5)
  • 1-14: The import statements are well organized and separated by functionality. Good job.

  • 16-22: The TxPool struct is well defined with clear field names. Good job.

  • 24-34: The NewTxPool function is well implemented. It initializes a new TxPool instance with the necessary fields.

  • 36-50: The Start function is well implemented. It checks if the pool is already started before initializing a new one. This prevents overwriting an existing pool.

  • 52-55: The PendingTransactions function is well implemented. It retrieves all pending transactions from the pool.

go/enclave/ethblockchain/eth_blockchain.go (6)
  • 24-30: The previous comment about using an interface for the logger is still valid. This would make the code more testable and flexible.

  • 33-41: The previous comment about validating function parameters before using them is still valid. This would prevent potential nil pointer dereferences.

  • 50-65: The previous comment about returning an error from the CurrentBlock function instead of nil is still valid. This would make error handling more explicit.

  • 67-82: The previous comment about refactoring the anonymous function in SubscribeChainHeadEvent into a separate function is still valid. This would make the code easier to test and reason about.

  • 120-131: The previous comment about adding a way to stop the goroutine in IngestNewBlock and handling potential panics is still valid. This would make the code more robust and prevent potential issues.

  • 149-153: The previous comment about handling the error returned by storage.FetchSecret() is still valid. Ignoring errors can lead to unexpected behavior and hard-to-debug issues.

go/enclave/nodetype/sequencer.go (8)
  • 53-62: The sequencer struct has been updated to replace mempool.Manager with *txpool.TxPool and add blockchain *ethblockchain.EthBlockchain. Ensure that all instances of sequencer are updated accordingly.

  • 68-83: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [64-81]

The NewSequencer function signature has been updated to include blockchain *ethblockchain.EthBlockchain. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 138-140: The signBatch function is called here. Ensure that the function is implemented correctly and that the private key used for signing is securely stored and managed.

  • 147-156: The blockchain.IngestNewBlock and mempool.Start functions are called here. Ensure that these functions are implemented correctly and handle errors properly.

  • 161-163: The mempool.Add function is called here. Ensure that this function is implemented correctly and handles errors properly.

  • 188-204: The mempool.PendingTransactions function is called here and the transactions are processed. Ensure that this function is implemented correctly and handles errors properly.

  • 252-262: The blockchain.IngestNewBlock function is called here. Ensure that this function is implemented correctly and handles errors properly.

  • 364-365: The mempool.Add function is called here. Ensure that this function is implemented correctly and handles errors properly.

go/enclave/enclave.go Outdated Show resolved Hide resolved
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: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2902b42 and bc3c43f.
Files selected for processing (5)
  • go/enclave/enclave.go (7 hunks)
  • go/enclave/nodetype/sequencer.go (11 hunks)
  • go/enclave/txpool/txpool.go (1 hunks)
  • go/enclave/txpool/txpool_mock_test.go (1 hunks)
  • go/enclave/txpool/txpool_test.go (1 hunks)
Additional comments: 15
go/enclave/txpool/txpool_test.go (1)
  • 91-91: The TODO comment indicates that there is an incomplete test case. It's important to either implement the test case for minting a block and checking the transaction pool or create a task to track this work for future implementation.
go/enclave/txpool/txpool_mock_test.go (1)
  • 3-20: The import list is extensive, which is common in Go files, especially for testing. Ensure that all imported packages are used within the file to avoid unnecessary dependencies.
go/enclave/enclave.go (5)
  • 13-17: The addition of the txpool import statement is correct and aligns with the changes described in the summary. This import is necessary for initializing the new transaction pool.

  • 130-131: The replacement of the previous chainConfig initialization with ethblockchain.ChainParams is a significant change. It is important to ensure that the ChainParams function correctly sets up the chain configuration and that all references to chainConfig throughout the codebase are updated to work with the new configuration structure.

  • 200-201: The initialization of mempool using txpool.NewTxPool replaces the previous mempool manager. It is crucial to verify that the new transaction pool is initialized with the correct parameters and that it integrates seamlessly with the rest of the system, especially with the EthBlockchain type.

  • 217-219: The usage of chainConfig without the address-of operator (&) suggests that the function signatures for nodetype.NewSequencer and potentially other functions have been updated to accept a value instead of a pointer. This change should be verified across the codebase to ensure consistency and to prevent potential runtime errors due to type mismatches.

  • 251-251: The creation of a new debugger instance is tied to the chain and chainConfig, which indicates that debugging capabilities may have been enhanced or modified to work with the new chain structure. It is important to ensure that the debugger functions as expected and that any new debugging features are documented and tested.

go/enclave/nodetype/sequencer.go (8)
  • 9-18: Reorganization of import statements is a common practice to keep the code clean and maintainable. Ensure that all new imports are used and that there are no conflicts with existing code.

  • 28-33: The constant RollupDelay is introduced. Verify that this constant is being used consistently throughout the codebase and that its value is appropriate for the intended behavior.

  • 53-61: The sequencer struct has been updated to include a blockchain field of type *ethblockchain.EthBlockchain and a mempool field of type *txpool.TxPool. Ensure that these new fields are properly initialized and used wherever necessary.

  • 68-83: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [64-81]

The NewSequencer function signature has been updated to include the new blockchain and mempool parameters. Ensure that all invocations of this function are updated accordingly.

  • 143-166: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [138-164]

The initGenesis function has been refactored to include blockchain ingestion and mempool start. Ensure that the error messages are clear and that the blockchain and mempool are correctly initialized and started.

  • 183-207: The createNewHeadBatch function now uses pending transactions from the mempool. Ensure that the transaction selection logic is correct and that the limiter is functioning as expected. Also, verify that the error handling is appropriate and that the transactions are being processed correctly.

  • 253-262: The produceBatch function has been modified to include blockchain ingestion. Ensure that the batch is correctly added to the blockchain and that the pending transactions are removed from the mempool as expected.

  • 364-366: The SubmitTransaction function has been simplified to directly add the transaction to the mempool. Ensure that the mempool's Add method is robust and handles all necessary validation and error checking.

Overall, the changes to sequencer.go seem to be focused on integrating the new EthBlockchain and TxPool types into the sequencer logic. It is important to ensure that these changes are thoroughly tested, especially since they involve critical components like transaction handling and blockchain ingestion. Additionally, ensure that all error messages provide enough context to be useful for debugging and that the new code follows the existing coding standards and practices of the Obscuro network's codebase.

go/enclave/txpool/txpool_test.go Outdated Show resolved Hide resolved
go/enclave/txpool/txpool_mock_test.go Show resolved Hide resolved
go/enclave/txpool/txpool_mock_test.go Show resolved Hide resolved
go/enclave/txpool/txpool_mock_test.go Show resolved Hide resolved
go/enclave/nodetype/sequencer.go Show resolved Hide resolved
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 bc3c43f and fd1394b.
Files selected for processing (1)
  • go/enclave/txpool/txpool_test.go (1 hunks)
Additional comments: 1
go/enclave/txpool/txpool_test.go (1)
  • 91-91: This TODO comment indicates that there is additional test coverage needed to ensure that transactions are cleared from the pool after a block is minted. It's important to implement this to verify the full lifecycle of a transaction in the pool.

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 fd1394b and 8091925.
Files selected for processing (1)
  • integration/obscuroscan/obscuroscan_test.go (2 hunks)
Additional comments: 2
integration/obscuroscan/obscuroscan_test.go (2)
  • 86-89: The test assertion for the transaction count has been updated to expect 5 transactions. Ensure that this change aligns with the intended number of transactions to be issued in the test setup. If the number of transactions issued is dynamic or can vary, consider parameterizing this assertion to avoid brittle tests.

  • 238-251: The nonce is being set outside the loop, which is good for performance. However, the issuerWallet.GetNonceAndIncrement() method is still being used inside the loop. This could lead to incorrect nonce values if the issuerWallet does not internally track the nonce correctly. It's important to ensure that the nonce is being managed correctly to avoid transaction failures due to nonce mismatch.

Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

Looks good. Had a quick pass through it, and left a few comments

go/enclave/ethblockchain/eth_blockchain.go Outdated Show resolved Hide resolved
go/enclave/ethblockchain/eth_blockchain.go Outdated Show resolved Hide resolved
go/enclave/nodetype/sequencer.go Show resolved Hide resolved
transactions, err := s.mempool.CurrentTxs(stateDB, limiter)
if err != nil {
return err
pendingTransactions := s.mempool.PendingTransactions()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this logic belong in the txpool as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the same thing, but I didn't want to pass the limiter to the tx pool. Do you think the limiter should be in the txpool ? So that we can lazily build the batch ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

how do they do it in geth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very similar..! Cycle through each lazy tx, resolve it, and then add it to the block until there's it hits the block gas.

for {
		// Check interruption signal and abort building if it's fired.
		if interrupt != nil {
			if signal := interrupt.Load(); signal != commitInterruptNone {
				return signalToErr(signal)
			}
		}
		// If we don't have enough gas for any further transactions then we're done.
		if env.gasPool.Gas() < params.TxGas {
			log.Trace("Not enough gas for further transactions", "have", env.gasPool, "want", params.TxGas)
			break
		}
		// Retrieve the next transaction and abort if all done.
		ltx := txs.Peek()
		if ltx == nil {
			break
		}
		tx := ltx.Resolve()
		if tx == nil {
			log.Warn("Ignoring evicted transaction")

			txs.Pop()
			continue
		}
		...
		case errors.Is(err, nil):
			// Everything ok, collect the logs and shift in the next transaction from the same account
			coalescedLogs = append(coalescedLogs, logs...)
			env.tcount++
			txs.Shift()
		```

integration/common/utils.go Show resolved Hide resolved
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: 13

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8091925 and d86801d.
Files selected for processing (7)
  • go/enclave/enclave.go (7 hunks)
  • go/enclave/evm/ethchainadapter/eth_chainadapter.go (1 hunks)
  • go/enclave/evm/ethchainadapter/eth_chainparams.go (1 hunks)
  • go/enclave/nodetype/sequencer.go (13 hunks)
  • go/enclave/txpool/txpool.go (1 hunks)
  • go/enclave/txpool/txpool_test.go (1 hunks)
  • integration/simulation/simulation.go (3 hunks)
Additional comments: 31
go/enclave/txpool/txpool.go (3)
  • 3-13: The import statements are well-organized and follow the convention of grouping standard library imports separately from third-party packages. This is a good practice for readability and maintainability.

  • 15-22: The TxPool struct is well-defined with clear field names indicating their purpose. However, ensure that the running field is accessed in a thread-safe manner if TxPool methods are called concurrently.

  • 75-77: The Running method provides a simple way to check the running status of the pool. Ensure that this method is thread-safe if TxPool can be accessed concurrently.

go/enclave/txpool/txpool_test.go (3)
  • 91-91: This TODO comment indicates that there is an intention to extend the test to include block minting and checking the transaction pool's state afterward. It's important to ensure that this test is completed to verify the full lifecycle of a transaction within the pool.

  • 20-92: The test function TestTxPool_AddTransaction_Pending is well-structured and covers the initialization of the transaction pool, adding a transaction, and checking its pending status. However, it relies on a sleep function to wait for the transaction to be processed, which is not ideal for test reliability and performance. It would be beneficial to replace this with a more deterministic synchronization mechanism.

  • 94-110: The applyGenesisState function is a new addition that sets up the initial state for the test blockchain. It's important to ensure that this function is called appropriately and that the genesis state is correctly applied to the mock storage. The error handling within this function is done well, with errors being wrapped to provide more context.

integration/simulation/simulation.go (1)
  • 230-234: The gas limit set here is extremely high (1025_000_000). This seems like an error, as Ethereum gas limits are typically much lower. Verify that this value is correct and adjust it if necessary. If this is a simulation-specific parameter, consider documenting why such a high value is used.
- Gas:       1025_000_000,
+ Gas:       10_000_000, // Adjusted to a more typical gas limit
go/enclave/enclave.go (6)
  • 10-23: The addition of new imports for ethchainadapter and txpool is appropriate given the context of integrating Ethereum's mempool into the Obscuro network. These imports are necessary for the new functionality being introduced.

  • 51-56: The addition of new imports for debugger and events is consistent with the changes described in the summary, such as the introduction of a new debug component and the update to the subscriptionManager.

  • 198-202: The creation of blockchain using ethchainadapter.NewEthChainAdapter and the initialization of mempool with txpool.NewTxPool are key changes that align with the pull request's goal of integrating Ethereum's mempool. It is important to ensure that error handling is robust here, as the initialization of these components is critical to the system's operation.

  • 212-220: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [204-231]

The conditional initialization of service as either a Sequencer or a Validator based on the config.NodeType is a logical change that reflects the system's need to differentiate node behavior. It is important to ensure that all necessary dependencies are correctly passed to the constructors of Sequencer and Validator.

  • 234-239: The initialization of chain with the NewChain function, passing in the storage, chainConfig, genesis, and logger, is a straightforward instantiation that seems to follow the established patterns in the codebase.

  • 248-252: The creation of a new debugger instance and its inclusion in the enclaveImpl struct is consistent with the summary's mention of a new debug component. It is important to ensure that the debug component is properly configured and that its use is gated by appropriate configuration flags or permissions to prevent unauthorized access.

go/enclave/evm/ethchainadapter/eth_chainadapter.go (10)
  • 3-21: The import section is well-organized and follows the convention of grouping standard library imports separately from third-party packages. However, it's important to ensure that all imported packages are used within the file to avoid unnecessary dependencies.

  • 23-30: The EthChainAdapter struct is well-defined and encapsulates the necessary components for the adapter's functionality. It's important to ensure that all fields are used effectively within the adapter's methods.

  • 32-41: The constructor function NewEthChainAdapter is correctly returning a pointer to a new EthChainAdapter instance. It's good practice to ensure that all parameters passed to the constructor are validated before use.

  • 43-46: The Config method correctly delegates to the ChainParams function to retrieve the chain configuration. It's important to ensure that ChainParams is robust and handles all possible chain IDs correctly.

  • 48-64: The CurrentBlock method retrieves the current head of the chain from the batch registry and storage. Error handling is present, but it logs a warning and returns nil in case of an error. Consider if this is the desired behavior or if the error should be propagated to the caller.

  • 67-81: The SubscribeChainHeadEvent method sets up a subscription to chain head events. It's important to ensure that the quit channel is appropriately handled in all calling contexts to avoid potential goroutine leaks.

  • 84-98: The GetBlock method retrieves a specific block by height. Error handling is consistent with the CurrentBlock method, logging the error and returning nil. Again, consider if this is the desired behavior or if the error should be propagated.

  • 101-118: The StateAt method returns a state database for a given root hash. The method checks for an empty root hash and returns nil without an error. Ensure that this behavior is consistent with the expectations of the callers. Also, the nilnil lint exception is used; verify that this is intentional and justified.

  • 120-130: The IngestNewBlock method ingests a new block into the adapter. It converts the batch to an Ethereum block and sends a chain head event. The use of a goroutine for sending the event is appropriate, but ensure that the newHeadChan channel has sufficient buffer or that the receiver is always ready to prevent blocking the goroutine.

  • 133-146: The NewLegacyPoolConfig function creates a default legacy pool configuration. Ensure that the hardcoded values are appropriate for the application's requirements and that they are documented if they deviate from standard geth configurations.

go/enclave/nodetype/sequencer.go (8)
  • 5-21: Reordering of import statements is generally fine as long as it follows the convention of grouping standard library imports separately from third-party packages. However, it's important to ensure that no imports were removed that are still needed by the code.

  • 28-31: The addition of new imports suggests that new dependencies have been introduced. Verify that these new dependencies are properly managed (e.g., vendored if necessary) and that their licenses are compatible with the project's license.

  • 53-61: The sequencer struct has been updated to include new fields such as blockchain and mempool. Ensure that all usages of the sequencer struct throughout the codebase have been updated to handle these new fields appropriately.

  • 95-100: The initialization of the sequencer struct within the NewSequencer function is correct and follows the Go convention of listing fields explicitly. This is good for readability and maintainability.

  • 153-176: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [132-175]

The createGenesisBatch function has been refactored and now includes logic to start the mempool and ingest a new block into the blockchain. Ensure that this logic is correct and that the mempool is indeed supposed to be started at this point in the code. Also, verify that the sleep on line 169 is necessary and that there isn't a more deterministic way to ensure the mempool queuing system is initialized.

  • 193-217: The transaction selection logic in createNewHeadBatch has been updated to use a limiter. Ensure that the limiter's behavior is well-tested, especially in edge cases where the batch size is close to the limit. Also, verify that the error handling is correct and that the batch creation process is aborted if an unexpected error occurs.

  • 263-273: The logging in produceBatch is good for monitoring and debugging purposes. Ensure that the log levels are appropriate and that sensitive information is not being logged.

  • 372-377: The SubmitTransaction function has been updated to use the new mempool field of the sequencer struct. Ensure that this change is reflected everywhere in the codebase where transactions are submitted to the sequencer.

go/enclave/txpool/txpool_test.go Show resolved Hide resolved
go/enclave/evm/ethchainadapter/eth_chainparams.go Outdated Show resolved Hide resolved
go/enclave/txpool/txpool.go Show resolved Hide resolved
go/enclave/txpool/txpool.go Show resolved Hide resolved
go/enclave/txpool/txpool.go Show resolved Hide resolved
go/enclave/enclave.go Show resolved Hide resolved
go/enclave/evm/ethchainadapter/eth_chainadapter.go Outdated Show resolved Hide resolved
go/enclave/nodetype/sequencer.go Show resolved Hide resolved
go/enclave/nodetype/sequencer.go Show resolved Hide resolved
go/enclave/nodetype/sequencer.go Show resolved Hide resolved
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 d86801d and 0c34a12.
Files selected for processing (1)
  • go/enclave/nodetype/sequencer.go (13 hunks)
Additional comments: 7
go/enclave/nodetype/sequencer.go (7)
  • 9-20: The import order has been changed to group Obscuro imports separately from Ethereum imports, which is a common practice for readability and organization. This change is purely stylistic and has no impact on functionality.

  • 52-60: The sequencer struct has been updated to include a new field blockchain of type *ethchainadapter.EthChainAdapter. This change aligns with the pull request's goal to integrate Geth's mempool functionality. Ensure that all instances and usages of the sequencer struct are updated to handle this new field.

  • 67-80: The NewSequencer function signature has been updated to include new parameters such as rollupProducer, rollupConsumer, rollupCompression, and blockchain. This is a breaking change and all calls to this function must be updated accordingly. Additionally, ensure that the new parameters are properly documented in the function's comments to explain their purpose and usage.

  • 110-127: The error handling in CreateBatch has been updated to provide more context, which is good for debugging. However, ensure that the error messages are consistent and follow a similar format throughout the codebase.

  • 192-216: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [192-233]

The createNewHeadBatch function now includes logic to limit the size of the batch using a BatchSizeLimiter. Ensure that the limiter is correctly configured and that the error handling is robust. The error message on line 209 should be more descriptive to aid in debugging. Consider including additional context such as the transaction details or the current batch size.

  • 262-271: The produceBatch function now adds the batch to the chain after it is produced. Ensure that the IngestNewBlock method of the blockchain correctly handles the new batch and that any transactions in the batch are properly removed from the mempool. The error message on line 268 should be more descriptive to aid in debugging. Consider including additional context such as the batch number or the transaction details.

  • 371-377: The SubmitTransaction function has been modified to use mempool.Add instead of AddMempoolTx. Ensure that the mempool.Add method is compatible with the expected behavior of SubmitTransaction and that any necessary error handling is in place.

go/enclave/nodetype/sequencer.go Show resolved Hide resolved
Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

lgtm

@otherview otherview merged commit ef01370 into main Nov 15, 2023
2 checks passed
@otherview otherview deleted the pedro/add_mempool branch November 15, 2023 13:41
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