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
b290cfe0
Unverified
Commit
b290cfe0
authored
Apr 19, 2021
by
Mark Tyneway
Committed by
GitHub
Apr 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimization: add back in the abi caching (#492)
* optimization: add back in the geohot abi caching * changeset: patch
parent
c4266faf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
rude-moons-kiss.md
.changeset/rude-moons-kiss.md
+5
-0
abi.go
l2geth/accounts/abi/abi.go
+12
-6
No files found.
.changeset/rude-moons-kiss.md
0 → 100644
View file @
b290cfe0
---
"
@eth-optimism/l2geth"
:
patch
---
CPU Optimization by caching ABI methods
l2geth/accounts/abi/abi.go
View file @
b290cfe0
...
...
@@ -32,6 +32,7 @@ type ABI struct {
Constructor
Method
Methods
map
[
string
]
Method
Events
map
[
string
]
Event
MethodsById
map
[[
4
]
byte
]
*
Method
}
// JSON returns a parsed ABI interface and error if it failed.
...
...
@@ -120,6 +121,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
return
err
}
abi
.
Methods
=
make
(
map
[
string
]
Method
)
abi
.
MethodsById
=
make
(
map
[[
4
]
byte
]
*
Method
)
abi
.
Events
=
make
(
map
[
string
]
Event
)
for
_
,
field
:=
range
fields
{
switch
field
.
Type
{
...
...
@@ -136,13 +138,17 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
_
,
ok
=
abi
.
Methods
[
name
]
}
isConst
:=
field
.
Constant
||
field
.
StateMutability
==
"pure"
||
field
.
StateMutability
==
"view"
abi
.
Methods
[
name
]
=
Method
{
method
:
=
Method
{
Name
:
name
,
RawName
:
field
.
Name
,
Const
:
isConst
,
Inputs
:
field
.
Inputs
,
Outputs
:
field
.
Outputs
,
}
abi
.
Methods
[
name
]
=
method
// add method to the id cache
sigdata
:=
method
.
ID
()
abi
.
MethodsById
[[
4
]
byte
{
sigdata
[
0
],
sigdata
[
1
],
sigdata
[
2
],
sigdata
[
3
]}]
=
&
method
case
"event"
:
name
:=
field
.
Name
_
,
ok
:=
abi
.
Events
[
name
]
...
...
@@ -168,12 +174,12 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
if
len
(
sigdata
)
<
4
{
return
nil
,
fmt
.
Errorf
(
"data too short (%d bytes) for abi method lookup"
,
len
(
sigdata
))
}
for
_
,
method
:=
range
abi
.
Methods
{
if
bytes
.
Equal
(
method
.
ID
(),
sigdata
[
:
4
])
{
return
&
method
,
nil
}
method
,
exist
:=
abi
.
MethodsById
[[
4
]
byte
{
sigdata
[
0
],
sigdata
[
1
],
sigdata
[
2
],
sigdata
[
3
]}]
if
!
exist
{
return
nil
,
fmt
.
Errorf
(
"no method with id: %#x"
,
sigdata
[
:
4
])
}
return
nil
,
fmt
.
Errorf
(
"no method with id: %#x"
,
sigdata
[
:
4
])
return
method
,
nil
}
// EventByID looks an event up by its topic hash in the
...
...
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