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

Fix issues with Geth L2 Node #62

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
- L2_TO_L1_MESSAGE_FINALITY_DELAY_IN_BLOCKS
- L2_RPC_SERVER_HOST
- L2_RPC_SERVER_PORT
- L2_WALLET_PRIVATE_KEY
- L2_WALLET_MNEMONIC
- L2_WALLET_PRIVATE_KEY_PATH=/mnt/l2-node/private_key.txt
- LOCAL_L1_NODE_PORT
Expand All @@ -42,6 +43,7 @@ services:
- HOSTNAME=geth_l2
- PORT=9545
- NETWORK_ID=108
- PRIVATE_KEY=0x29f3edee0ad3abf8e2699402e0e28cd6492c9be7eaab00d732a791c33552f797
- KEYSTORE_PATH_SUFFIX=/keystore
- SEALER_PRIVATE_KEY_PATH_SUFFIX=/sealer_private_key.txt
- PRIVATE_KEY_PATH_SUFFIX=/private_key.txt
Expand All @@ -52,6 +54,8 @@ services:
- SETUP_RUN_PATH_SUFFIX=/setup_run.txt
expose:
- "9545"
ports:
- 9545:9545
#
# geth_l1:
# volumes:
Expand Down
13 changes: 11 additions & 2 deletions docker/geth/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,19 @@ generate_geneisis()

## One-time configuration to be run only on first startup
if [[ ! -f $KEYSTORE_PATH && ! -f $SETUP_RUN_PATH ]]; then
generate_private_key > $SEALER_PRIVATE_KEY_PATH
generate_private_key > $SEALER_PRIVATE_KEY_PATH
import_private_key $SEALER_PRIVATE_KEY_PATH > $SEALER_ADDRESS_PATH
generate_private_key > $PRIVATE_KEY_PATH

if [ -z "$PRIVATE_KEY" ]; then
echo "\nGENERATING PRIVATE KEY!! We most likely don't want to do this.\n"
generate_private_key > $PRIVATE_KEY_PATH
else
echo "Reading private key from env"
echo "$PRIVATE_KEY" | sed 's/^0x//' > $PRIVATE_KEY_PATH
fi

import_private_key $PRIVATE_KEY_PATH > $ADDRESS_PATH

generate_geneisis `cat $SEALER_ADDRESS_PATH` `cat $ADDRESS_PATH`

geth --datadir $VOLUME_PATH --nousb --verbosity 0 init $GENISIS_PATH 2> /dev/null;
Expand Down
4 changes: 3 additions & 1 deletion packages/integration-test-utils/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

// Default Wallet PK: 0x29f3edee0ad3abf8e2699402e0e28cd6492c9be7eaab00d732a791c33552f797
// Default Wallet address: 0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff
// Default EM Address is 1st deployment from the above Wallet
export const EXECUTION_MANAGER_ADDRESS = process.env.EXECUTION_MANAGER_ADDRESS || '0xA193E42526F1FEA8C99AF609dcEabf30C1c29fAA'
8 changes: 8 additions & 0 deletions packages/ovm/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const l2ToL1MessagePasserInterface = new ethers.utils.Interface(
)

const logger = getLogger('utils')

export interface OvmTransactionMetadata {
ovmTxSucceeded: boolean
ovmTo: string
Expand All @@ -68,8 +69,15 @@ export const convertInternalLogsToOvmLogs = (logs: Log[]): Log[] => {
if (executionManagerLog) {
if (executionManagerLog.name === 'ActiveContract') {
activeContract = executionManagerLog.values['_activeContract']
} else {
logger.debug(
`${executionManagerLog.name}, values: ${JSON.stringify(
executionManagerLog.values
)}`
)
}
} else {
logger.debug(`Non-EM log: ${JSON.stringify(log)}`)
ovmLogs.push({ ...log, address: activeContract })
}
})
Expand Down
3 changes: 3 additions & 0 deletions packages/rollup-full-node/src/app/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export class Environment {
public static l2NodeWeb3Url(defaultValue?: string): string {
return process.env.L2_NODE_WEB3_URL || defaultValue
}
public static l2WalletPrivateKey(defaultValue?: string): string {
return process.env.L2_WALLET_PRIVATE_KEY || defaultValue
}
public static l2WalletMnemonic(defaultValue?: string): string {
return process.env.L2_WALLET_MNEMONIC || defaultValue
}
Expand Down
14 changes: 11 additions & 3 deletions packages/rollup-full-node/src/app/utils/l2-node.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Externals Import */
import {
add0x,
getDeployedContractAddress,
getLogger,
logError,
remove0x,
} from '@eth-optimism/core-utils'
import {
GAS_LIMIT,
Expand Down Expand Up @@ -95,15 +95,20 @@ function deployLocalL2Node(): JsonRpcProvider {
*/
function getL2Wallet(provider: JsonRpcProvider): Wallet {
let wallet: Wallet
if (!!Environment.l2WalletMnemonic()) {
if (!!Environment.l2WalletPrivateKey()) {
wallet = new Wallet(add0x(Environment.l2WalletPrivateKey()), provider)
log.info(`Initialized wallet from private key. Address: ${wallet.address}`)
} else if (!!Environment.l2WalletMnemonic()) {
wallet = Wallet.fromMnemonic(Environment.l2WalletMnemonic())
wallet.connect(provider)
log.info(`Initialized wallet from mnemonic. Address: ${wallet.address}`)
} else if (!!Environment.l2WalletPrivateKeyPath()) {
try {
const pk: string = fs.readFileSync(Environment.l2WalletPrivateKeyPath(), {
encoding: 'utf-8',
})
wallet = new Wallet(pk, provider)
wallet = new Wallet(add0x(pk.trim()), provider)
log.info(`Found wallet from PK file. Address: ${wallet.address}`)
} catch (e) {
logError(
log,
Expand All @@ -114,6 +119,9 @@ function getL2Wallet(provider: JsonRpcProvider): Wallet {
}
} else {
wallet = getWallets(provider)[0]
log.info(
`Getting wallet from provider. First wallet private key: [${wallet.privateKey}`
)
}

if (!wallet) {
Expand Down
16 changes: 14 additions & 2 deletions packages/rollup-full-node/src/app/web3-rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export class DefaultWeb3Handler implements Web3Handler, FullnodeHandler {
messageSubmitter: L2ToL1MessageSubmitter = new NoOpL2ToL1MessageSubmitter(),
web3Provider?: JsonRpcProvider
): Promise<DefaultWeb3Handler> {
log.info(
`Creating Web3 Handler with provider: ${
!!web3Provider
? web3Provider.connection.url
: 'undefined -- will create.'
}`
)

const timestamp = getCurrentTime()
const l2NodeContext: L2NodeContext = await initializeL2Node(web3Provider)

Expand Down Expand Up @@ -411,7 +419,9 @@ export class DefaultWeb3Handler implements Web3Handler, FullnodeHandler {
}

log.debug(
`Returning tx receipt for ovm tx hash [${ovmTxHash}]: [${internalTxReceipt}]`
`Returning tx receipt for ovm tx hash [${ovmTxHash}]: [${JSON.stringify(
internalTxReceipt
)}]`
)
return ovmTxReceipt
}
Expand Down Expand Up @@ -445,6 +455,8 @@ export class DefaultWeb3Handler implements Web3Handler, FullnodeHandler {
const ovmTxHash = await utils.keccak256(rawOvmTx)
const internalTxHash = await utils.keccak256(internalTx)

log.debug(`\n\n\nSIGNED INTERNAL TX: ${JSON.stringify(internalTx)}\n\n\n`)

// Make sure we have a way to look up our internal tx hash from the ovm tx hash.
await this.mapOvmTxHashToInternalTxHash(ovmTxHash, internalTxHash)

Expand All @@ -453,7 +465,7 @@ export class DefaultWeb3Handler implements Web3Handler, FullnodeHandler {
// Then apply our transaction
returnedInternalTxHash = await this.context.provider.send(
Web3RpcMethods.sendRawTransaction,
internalTx
[internalTx]
)
} catch (e) {
logError(
Expand Down