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
61e99b00
Commit
61e99b00
authored
Jul 17, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ability to compute storage hash for client
parent
ad5a7ce1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
13 deletions
+43
-13
indexer.go
indexer/indexer.go
+8
-8
client.go
indexer/node/client.go
+30
-5
client_test.go
indexer/node/client_test.go
+5
-0
No files found.
indexer/indexer.go
View file @
61e99b00
...
@@ -18,8 +18,8 @@ import (
...
@@ -18,8 +18,8 @@ import (
type
Indexer
struct
{
type
Indexer
struct
{
db
*
database
.
DB
db
*
database
.
DB
l
1Processor
*
processor
.
L1Processor
L
1Processor
*
processor
.
L1Processor
l
2Processor
*
processor
.
L2Processor
L
2Processor
*
processor
.
L2Processor
}
}
// NewIndexer initializes an instance of the Indexer
// NewIndexer initializes an instance of the Indexer
...
@@ -38,7 +38,7 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
...
@@ -38,7 +38,7 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
L1StandardBridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000003"
),
L1StandardBridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000003"
),
L1ERC721Bridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000004"
),
L1ERC721Bridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000004"
),
}
}
l1EthClient
,
err
:=
node
.
New
EthClient
(
cfg
.
RPCs
.
L1RPC
)
l1EthClient
,
err
:=
node
.
Dial
EthClient
(
cfg
.
RPCs
.
L1RPC
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -49,7 +49,7 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
...
@@ -49,7 +49,7 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
// L2Processor
// L2Processor
l2Contracts
:=
processor
.
L2ContractPredeploys
()
// Make this configurable
l2Contracts
:=
processor
.
L2ContractPredeploys
()
// Make this configurable
l2EthClient
,
err
:=
node
.
New
EthClient
(
cfg
.
RPCs
.
L2RPC
)
l2EthClient
,
err
:=
node
.
Dial
EthClient
(
cfg
.
RPCs
.
L2RPC
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -60,8 +60,8 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
...
@@ -60,8 +60,8 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
indexer
:=
&
Indexer
{
indexer
:=
&
Indexer
{
db
:
db
,
db
:
db
,
l
1Processor
:
l1Processor
,
L
1Processor
:
l1Processor
,
l
2Processor
:
l2Processor
,
L
2Processor
:
l2Processor
,
}
}
return
indexer
,
nil
return
indexer
,
nil
...
@@ -86,8 +86,8 @@ func (i *Indexer) Run(ctx context.Context) error {
...
@@ -86,8 +86,8 @@ func (i *Indexer) Run(ctx context.Context) error {
}
}
// Kick off the processors
// Kick off the processors
go
run
(
i
.
l
1Processor
.
Start
)
go
run
(
i
.
L
1Processor
.
Start
)
go
run
(
i
.
l
2Processor
.
Start
)
go
run
(
i
.
L
2Processor
.
Start
)
err
:=
<-
errCh
err
:=
<-
errCh
// ensure both processors have halted before returning
// ensure both processors have halted before returning
...
...
indexer/node/client.go
View file @
61e99b00
...
@@ -3,6 +3,7 @@ package node
...
@@ -3,6 +3,7 @@ package node
import
(
import
(
"context"
"context"
"errors"
"errors"
"fmt"
"math/big"
"math/big"
"time"
"time"
...
@@ -29,6 +30,8 @@ type EthClient interface {
...
@@ -29,6 +30,8 @@ type EthClient interface {
BlockHeadersByRange
(
*
big
.
Int
,
*
big
.
Int
)
([]
*
types
.
Header
,
error
)
BlockHeadersByRange
(
*
big
.
Int
,
*
big
.
Int
)
([]
*
types
.
Header
,
error
)
BlockHeaderByHash
(
common
.
Hash
)
(
*
types
.
Header
,
error
)
BlockHeaderByHash
(
common
.
Hash
)
(
*
types
.
Header
,
error
)
StorageHash
(
common
.
Address
,
*
big
.
Int
)
(
common
.
Hash
,
error
)
RawRpcClient
()
*
rpc
.
Client
RawRpcClient
()
*
rpc
.
Client
}
}
...
@@ -36,7 +39,7 @@ type client struct {
...
@@ -36,7 +39,7 @@ type client struct {
rpcClient
*
rpc
.
Client
rpcClient
*
rpc
.
Client
}
}
func
New
EthClient
(
rpcUrl
string
)
(
EthClient
,
error
)
{
func
Dial
EthClient
(
rpcUrl
string
)
(
EthClient
,
error
)
{
ctxwt
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
defaultDialTimeout
)
ctxwt
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
defaultDialTimeout
)
defer
cancel
()
defer
cancel
()
...
@@ -49,6 +52,10 @@ func NewEthClient(rpcUrl string) (EthClient, error) {
...
@@ -49,6 +52,10 @@ func NewEthClient(rpcUrl string) (EthClient, error) {
return
client
,
nil
return
client
,
nil
}
}
func
NewEthClient
(
rpcClient
*
rpc
.
Client
)
EthClient
{
return
&
client
{
rpcClient
}
}
func
(
c
*
client
)
RawRpcClient
()
*
rpc
.
Client
{
func
(
c
*
client
)
RawRpcClient
()
*
rpc
.
Client
{
return
c
.
rpcClient
return
c
.
rpcClient
}
}
...
@@ -136,15 +143,33 @@ func (c *client) BlockHeadersByRange(startHeight, endHeight *big.Int) ([]*types.
...
@@ -136,15 +143,33 @@ func (c *client) BlockHeadersByRange(startHeight, endHeight *big.Int) ([]*types.
return
headers
,
nil
return
headers
,
nil
}
}
// StorageHash returns the sha3 of the storage root for the specified account
func
(
c
*
client
)
StorageHash
(
address
common
.
Address
,
blockNumber
*
big
.
Int
)
(
common
.
Hash
,
error
)
{
ctxwt
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
defaultRequestTimeout
)
defer
cancel
()
proof
:=
struct
{
StorageHash
common
.
Hash
}{}
err
:=
c
.
rpcClient
.
CallContext
(
ctxwt
,
&
proof
,
"eth_getProof"
,
address
,
nil
,
toBlockNumArg
(
blockNumber
))
if
err
!=
nil
{
return
common
.
Hash
{},
err
}
return
proof
.
StorageHash
,
nil
}
func
toBlockNumArg
(
number
*
big
.
Int
)
string
{
func
toBlockNumArg
(
number
*
big
.
Int
)
string
{
if
number
==
nil
{
if
number
==
nil
{
return
"latest"
return
"latest"
}
else
if
number
.
Sign
()
>=
0
{
return
hexutil
.
EncodeBig
(
number
)
}
}
pending
:=
big
.
NewInt
(
-
1
)
// It's negative.
if
number
.
Cmp
(
pending
)
==
0
{
if
number
.
IsInt64
()
{
return
"pending"
tag
,
_
:=
rpc
.
BlockNumber
(
number
.
Int64
())
.
MarshalText
()
return
string
(
tag
)
}
}
return
hexutil
.
EncodeBig
(
number
)
// It's negative and large, which is invalid.
return
fmt
.
Sprintf
(
"<invalid %d>"
,
number
)
}
}
indexer/node/client_test.go
View file @
61e99b00
...
@@ -31,6 +31,11 @@ func (m *MockEthClient) BlockHeaderByHash(hash common.Hash) (*types.Header, erro
...
@@ -31,6 +31,11 @@ func (m *MockEthClient) BlockHeaderByHash(hash common.Hash) (*types.Header, erro
return
args
.
Get
(
0
)
.
(
*
types
.
Header
),
args
.
Error
(
1
)
return
args
.
Get
(
0
)
.
(
*
types
.
Header
),
args
.
Error
(
1
)
}
}
func
(
m
*
MockEthClient
)
StorageHash
(
address
common
.
Address
,
blockNumber
*
big
.
Int
)
(
common
.
Hash
,
error
)
{
args
:=
m
.
Called
(
address
,
blockNumber
)
return
args
.
Get
(
0
)
.
(
common
.
Hash
),
args
.
Error
(
1
)
}
func
(
m
*
MockEthClient
)
RawRpcClient
()
*
rpc
.
Client
{
func
(
m
*
MockEthClient
)
RawRpcClient
()
*
rpc
.
Client
{
args
:=
m
.
Called
()
args
:=
m
.
Called
()
return
args
.
Get
(
0
)
.
(
*
rpc
.
Client
)
return
args
.
Get
(
0
)
.
(
*
rpc
.
Client
)
...
...
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