-
Notifications
You must be signed in to change notification settings - Fork 3.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
Persistence Updates #56
Changes from 4 commits
0d8598b
dcba158
77b6d62
5711f7d
1be0b00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { DEFAULT_OPCODE_WHITELIST_MASK } from '@eth-optimism/ovm' | ||
|
||
/** | ||
* Class to contain all environment variables referenced by the rollup full node | ||
* to consolidate access / updates and default values. | ||
*/ | ||
export class Environment { | ||
// Local Node Config | ||
public static opcodeWhitelistMask( | ||
defaultValue: string = DEFAULT_OPCODE_WHITELIST_MASK | ||
): string { | ||
return process.env.OPCODE_WHITELIST_MASK || defaultValue | ||
} | ||
public static localL2NodePersistentDbPath(defaultValue?: string) { | ||
return process.env.LOCAL_L2_NODE_PERSISTENT_DB_PATH || defaultValue | ||
} | ||
public static l2ToL1MessageFinalityDelayInBlocks( | ||
defaultValue: number = 0 | ||
): number { | ||
return process.env.L2_TO_L1_MESSAGE_FINALITY_DELAY_IN_BLOCKS | ||
? parseInt(process.env.L2_TO_L1_MESSAGE_FINALITY_DELAY_IN_BLOCKS, 10) | ||
: defaultValue | ||
} | ||
public static localL1NodePersistentDbPath(defaultValue?: string): string { | ||
return process.env.LOCAL_L1_NODE_PERSISTENT_DB_PATH || defaultValue | ||
} | ||
|
||
// L2 Config | ||
public static l2RpcServerHost(defaultValue: string = '0.0.0.0'): string { | ||
return process.env.L2_RPC_SERVER_HOST || defaultValue | ||
} | ||
public static l2RpcServerPort(defaultValue: number = 8545): number { | ||
return process.env.L2_RPC_SERVER_PORT | ||
? parseInt(process.env.L2_RPC_SERVER_PORT, 10) | ||
: defaultValue | ||
} | ||
public static l2NodeWeb3Url(defaultValue?: string): string { | ||
return process.env.L2_NODE_WEB3_URL || defaultValue | ||
} | ||
public static l2WalletMnemonic(defaultValue?: string): string { | ||
return process.env.L2_WALLET_MNEMONIC || defaultValue | ||
} | ||
|
||
// L1 Config | ||
public static l1NodeWeb3Url(defaultValue?: string): string { | ||
return process.env.L1_NODE_WEB3_URL || defaultValue | ||
} | ||
public static localL1NodePort(defaultValue: number = 7545): number { | ||
return process.env.LOCAL_L1_NODE_PORT | ||
? parseInt(process.env.LOCAL_L1_NODE_PORT, 10) | ||
: defaultValue | ||
} | ||
public static sequencerMnemonic(defaultValue?: string): string { | ||
return process.env.L1_SEQUENCER_MNEMONIC || defaultValue | ||
} | ||
public static l2ToL1MessageReceiverAddress(defaultValue?: string): string { | ||
return process.env.L2_TO_L1_MESSAGE_RECEIVER_ADDRESS || defaultValue | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './environment' | ||
export * from './local-l1-node' | ||
export * from './l2-node' | ||
export * from './utils' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,31 +5,43 @@ import { Contract, ethers, providers, Wallet } from 'ethers' | |
import { createMockProvider, deployContract, getWallets } from 'ethereum-waffle' | ||
|
||
/* Internal Imports */ | ||
import { DEFAULT_ETHNODE_GAS_LIMIT } from '../index' | ||
import { DEFAULT_ETHNODE_GAS_LIMIT, Environment } from '../index' | ||
import { L1NodeContext } from '../../types' | ||
|
||
const finalityDelayInBlocks: string = | ||
process.env.FINALITY_DELAY_IN_BLOCKS || '0' | ||
const l1NodeLevelDBPath: string = process.env.L1_NODE_LEVELDB_PATH | ||
/** | ||
* Starts a local node on the provided port, using the provided mnemonic to | ||
* deploy the necessary contracts for bootstrapping. | ||
* | ||
* @param sequencerMnemonic The mnemonic to use for the Sequencer in contracts that need Sequencer ownership or reference. | ||
* @param port The port the node should be reachable at. | ||
* @returns The L1 node context with all info necessary to use the L1 node. | ||
*/ | ||
export const startLocalL1Node = async ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm the terminology here is a little confusing. Am I getting it right that "LocalL1Node" is what we send "InternalTransactions" to? It's just really confusing and I want to make sure we have all of the components mapped out with reasonable terminology. I just made a diagram which illustrates all of the components. So to be clear, Does that match up with the terminology being used here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that's it! The line in question is to specifically start an L1 node locally to fully exercise the end-to-end functionality of L2 <--> L1 messaging. This is completely different than the L2 Node. I went with L1 and L2 because nothing is actually "rolled up" in the L2 node, and instead, the rollup state sits in the L1 node. Wanted to avoid that confusion. Does L1 and L2 sound good? Happy to rename it to rollup if you think it makes more sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah great! So I think after staring at this for a while I see where my confusion was. The fact that inside the These L1 & L2 terms are a little confusing! Especially when you see L1ToL2 right next to L2ToL1 — my dyslexia goes crazy! That said, it’s not clear to me that I realize this could require some refactoring/renaming (and so I’m happy to not do it) but I wonder if instead of It’s a nitpick though & might be specific to my difficulty reading 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nvm I take it back. I’m now thinking about Unless y'all absolutely love my naming change (which might have been closer to what Ben did originally?) doesn’t feel worth the switching cost. |
||
mnemonic: string, | ||
port: number | ||
): Promise<providers.Web3Provider> => { | ||
): Promise<L1NodeContext> => { | ||
const opts = { | ||
gasLimit: DEFAULT_ETHNODE_GAS_LIMIT, | ||
allowUnlimitedContractSize: true, | ||
locked: false, | ||
port, | ||
mnemonic, | ||
} | ||
if (!!l1NodeLevelDBPath) { | ||
opts['db_path'] = l1NodeLevelDBPath | ||
if (!!Environment.localL1NodePersistentDbPath()) { | ||
opts['db_path'] = Environment.localL1NodePersistentDbPath() | ||
} | ||
const provider: providers.Web3Provider = createMockProvider(opts) | ||
|
||
const wallet = getWallets(provider)[0] | ||
await deployL2ToL1MessageReceiver(wallet) | ||
const sequencerWallet = getWallets(provider)[0] | ||
const l2ToL1MessageReceiver = await deployL2ToL1MessageReceiver( | ||
sequencerWallet | ||
) | ||
|
||
return provider | ||
return { | ||
provider, | ||
sequencerWallet, | ||
l2ToL1MessageReceiver, | ||
} | ||
} | ||
|
||
export const deployL2ToL1MessageReceiver = async ( | ||
|
@@ -38,7 +50,7 @@ export const deployL2ToL1MessageReceiver = async ( | |
const contract = await deployContract( | ||
wallet, | ||
L2ToL1MessageReceiverContractDefinition, | ||
[wallet.address, parseInt(finalityDelayInBlocks, 10)] | ||
[wallet.address, Environment.l2ToL1MessageFinalityDelayInBlocks()] | ||
) | ||
|
||
process.env.L2_TO_L1_MESSAGE_RECEIVER_ADDRESS = contract.address | ||
|
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.
Looks good! In the spirit of honing my code style intuitions, I have two observations: