Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
70ff6476
Unverified
Commit
70ff6476
authored
Oct 25, 2021
by
kf
Committed by
Kelvin Fichter
Nov 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: move surgery solc cache to disk
Signed-off-by:
kf
<
kelvin@optimism.io
>
parent
fc97fb87
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
8 deletions
+61
-8
.eslintrc.js
packages/regenesis-surgery/.eslintrc.js
+1
-1
.gitignore
packages/regenesis-surgery/.gitignore
+1
-0
constants.ts
packages/regenesis-surgery/scripts/constants.ts
+12
-0
solc.ts
packages/regenesis-surgery/scripts/solc.ts
+47
-7
No files found.
packages/regenesis-surgery/.eslintrc.js
View file @
70ff6476
module
.
exports
=
{
module
.
exports
=
{
extends
:
'
../../.eslintrc.js
'
,
extends
:
'
../../.eslintrc.js
'
,
ignorePatterns
:
[
'
/data
'
,
'
/solc-bin
'
],
ignorePatterns
:
[
'
/data
'
,
'
/solc-bin
'
,
'
/solc-cache
'
],
}
}
packages/regenesis-surgery/.gitignore
View file @
70ff6476
...
@@ -5,3 +5,4 @@ outputs/
...
@@ -5,3 +5,4 @@ outputs/
etherscan/
etherscan/
state-dumps/
state-dumps/
data/
data/
solc-cache/
packages/regenesis-surgery/scripts/constants.ts
View file @
70ff6476
...
@@ -146,3 +146,15 @@ export const SOLC_BIN_PATH = 'https://binaries.soliditylang.org'
...
@@ -146,3 +146,15 @@ export const SOLC_BIN_PATH = 'https://binaries.soliditylang.org'
export
const
EMSCRIPTEN_BUILD_PATH
=
`
${
SOLC_BIN_PATH
}
/emscripten-wasm32`
export
const
EMSCRIPTEN_BUILD_PATH
=
`
${
SOLC_BIN_PATH
}
/emscripten-wasm32`
export
const
EMSCRIPTEN_BUILD_LIST
=
`
${
EMSCRIPTEN_BUILD_PATH
}
/list.json`
export
const
EMSCRIPTEN_BUILD_LIST
=
`
${
EMSCRIPTEN_BUILD_PATH
}
/list.json`
export
const
LOCAL_SOLC_DIR
=
path
.
join
(
__dirname
,
'
..
'
,
'
solc-bin
'
)
export
const
LOCAL_SOLC_DIR
=
path
.
join
(
__dirname
,
'
..
'
,
'
solc-bin
'
)
export
const
EVM_SOLC_CACHE_DIR
=
path
.
join
(
__dirname
,
'
..
'
,
'
solc-cache
'
,
'
evm
'
)
export
const
OVM_SOLC_CACHE_DIR
=
path
.
join
(
__dirname
,
'
..
'
,
'
solc-cache
'
,
'
ovm
'
)
packages/regenesis-surgery/scripts/solc.ts
View file @
70ff6476
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
{
access
,
mkdir
}
from
'
fs/promises
'
import
{
access
,
mkdir
}
from
'
fs/promises
'
import
fetch
from
'
node-fetch
'
import
fetch
from
'
node-fetch
'
import
path
from
'
path
'
import
path
from
'
path
'
import
fs
from
'
fs
'
import
fs
,
{
mkdirSync
}
from
'
fs
'
import
solc
from
'
solc
'
import
solc
from
'
solc
'
import
{
ethers
}
from
'
ethers
'
import
{
ethers
}
from
'
ethers
'
import
{
clone
}
from
'
@eth-optimism/core-utils
'
import
{
clone
}
from
'
@eth-optimism/core-utils
'
...
@@ -11,6 +11,8 @@ import {
...
@@ -11,6 +11,8 @@ import {
EMSCRIPTEN_BUILD_LIST
,
EMSCRIPTEN_BUILD_LIST
,
EMSCRIPTEN_BUILD_PATH
,
EMSCRIPTEN_BUILD_PATH
,
LOCAL_SOLC_DIR
,
LOCAL_SOLC_DIR
,
EVM_SOLC_CACHE_DIR
,
OVM_SOLC_CACHE_DIR
,
}
from
'
./constants
'
}
from
'
./constants
'
import
{
EtherscanContract
}
from
'
./types
'
import
{
EtherscanContract
}
from
'
./types
'
...
@@ -181,10 +183,50 @@ const compilerCache: {
...
@@ -181,10 +183,50 @@ const compilerCache: {
[
'
EVM
'
]:
{},
[
'
EVM
'
]:
{},
}
}
const
readCompilerCache
=
(
target
:
'
evm
'
|
'
ovm
'
,
hash
:
string
):
any
|
undefined
=>
{
try
{
const
cacheDir
=
target
===
'
evm
'
?
EVM_SOLC_CACHE_DIR
:
OVM_SOLC_CACHE_DIR
return
JSON
.
parse
(
fs
.
readFileSync
(
path
.
join
(
cacheDir
,
hash
),
{
encoding
:
'
utf-8
'
,
})
)
}
catch
(
err
)
{
return
undefined
}
}
const
writeCompilerCache
=
(
target
:
'
evm
'
|
'
ovm
'
,
hash
:
string
,
content
:
any
)
=>
{
const
cacheDir
=
target
===
'
evm
'
?
EVM_SOLC_CACHE_DIR
:
OVM_SOLC_CACHE_DIR
fs
.
writeFileSync
(
path
.
join
(
cacheDir
,
hash
),
JSON
.
stringify
(
content
))
}
export
const
compile
=
(
opts
:
{
export
const
compile
=
(
opts
:
{
contract
:
EtherscanContract
contract
:
EtherscanContract
ovm
:
boolean
ovm
:
boolean
}):
any
=>
{
}):
any
=>
{
try
{
mkdirSync
(
EVM_SOLC_CACHE_DIR
,
{
recursive
:
true
,
})
}
catch
(
e
)
{
// directory already exists
}
try
{
mkdirSync
(
OVM_SOLC_CACHE_DIR
,
{
recursive
:
true
,
})
}
catch
(
e
)
{
// directory already exists
}
let
version
:
string
let
version
:
string
if
(
opts
.
ovm
)
{
if
(
opts
.
ovm
)
{
version
=
opts
.
contract
.
compilerVersion
version
=
opts
.
contract
.
compilerVersion
...
@@ -200,17 +242,15 @@ export const compile = (opts: {
...
@@ -200,17 +242,15 @@ export const compile = (opts: {
const
solcInstance
=
getSolc
(
version
,
opts
.
ovm
)
const
solcInstance
=
getSolc
(
version
,
opts
.
ovm
)
const
input
=
JSON
.
stringify
(
solcInput
(
opts
.
contract
))
const
input
=
JSON
.
stringify
(
solcInput
(
opts
.
contract
))
const
inputHash
=
ethers
.
utils
.
solidityKeccak256
([
'
string
'
],
[
input
])
const
inputHash
=
ethers
.
utils
.
solidityKeccak256
([
'
string
'
],
[
input
])
const
compilerTarget
=
opts
.
ovm
?
'
OVM
'
:
'
EVM
'
const
compilerTarget
=
opts
.
ovm
?
'
ovm
'
:
'
evm
'
// Cache the compiler output to speed up repeated compilations of the same contract. If this
// Cache the compiler output to speed up repeated compilations of the same contract. If this
// cache is too memory intensive, then we could consider only caching if the contract has been
// cache is too memory intensive, then we could consider only caching if the contract has been
// seen more than once.
// seen more than once.
let
output
:
any
let
output
=
readCompilerCache
(
compilerTarget
,
inputHash
)
if
(
compilerCache
[
compilerTarget
][
inputHash
])
{
if
(
output
===
undefined
)
{
output
=
compilerCache
[
compilerTarget
][
inputHash
]
}
else
{
output
=
JSON
.
parse
(
solcInstance
.
compile
(
input
))
output
=
JSON
.
parse
(
solcInstance
.
compile
(
input
))
compilerCache
[
compilerTarget
][
inputHash
]
=
output
writeCompilerCache
(
compilerTarget
,
inputHash
,
output
)
}
}
if
(
!
output
.
contracts
)
{
if
(
!
output
.
contracts
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment