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
601e0e5e
Commit
601e0e5e
authored
Jul 17, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
e2e test indexing l1 blocks with contract events
parent
808bc8bd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
122 additions
and
23 deletions
+122
-23
contract_events.go
indexer/database/contract_events.go
+63
-0
blocks_test.go
indexer/e2e_test/blocks_test.go
+36
-4
bridge_test.go
indexer/e2e_test/bridge_test.go
+1
-0
setup.go
indexer/e2e_test/setup.go
+2
-1
indexer.go
indexer/indexer.go
+3
-11
l1_processor.go
indexer/processor/l1_processor.go
+15
-5
l2_processor.go
indexer/processor/l2_processor.go
+2
-2
No files found.
indexer/database/contract_events.go
View file @
601e0e5e
package
database
import
(
"errors"
"gorm.io/gorm"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -46,6 +48,11 @@ type L2ContractEvent struct {
}
type
ContractEventsView
interface
{
L1ContractEvent
(
uuid
.
UUID
)
(
*
L1ContractEvent
,
error
)
L1ContractEventByTxLogIndex
(
common
.
Hash
,
uint64
)
(
*
L1ContractEvent
,
error
)
L2ContractEvent
(
uuid
.
UUID
)
(
*
L2ContractEvent
,
error
)
L2ContractEventByTxLogIndex
(
common
.
Hash
,
uint64
)
(
*
L2ContractEvent
,
error
)
}
type
ContractEventsDB
interface
{
...
...
@@ -74,9 +81,65 @@ func (db *contractEventsDB) StoreL1ContractEvents(events []*L1ContractEvent) err
return
result
.
Error
}
func
(
db
*
contractEventsDB
)
L1ContractEvent
(
uuid
uuid
.
UUID
)
(
*
L1ContractEvent
,
error
)
{
var
l1ContractEvent
L1ContractEvent
result
:=
db
.
gorm
.
Where
(
&
ContractEvent
{
GUID
:
uuid
})
.
Take
(
&
l1ContractEvent
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
}
return
nil
,
result
.
Error
}
return
&
l1ContractEvent
,
nil
}
func
(
db
*
contractEventsDB
)
L1ContractEventByTxLogIndex
(
txHash
common
.
Hash
,
logIndex
uint64
)
(
*
L1ContractEvent
,
error
)
{
var
l1ContractEvent
L1ContractEvent
result
:=
db
.
gorm
.
Where
(
&
ContractEvent
{
TransactionHash
:
txHash
,
LogIndex
:
logIndex
})
.
Take
(
&
l1ContractEvent
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
}
return
nil
,
result
.
Error
}
return
&
l1ContractEvent
,
nil
}
// L2
func
(
db
*
contractEventsDB
)
StoreL2ContractEvents
(
events
[]
*
L2ContractEvent
)
error
{
result
:=
db
.
gorm
.
Create
(
&
events
)
return
result
.
Error
}
func
(
db
*
contractEventsDB
)
L2ContractEvent
(
uuid
uuid
.
UUID
)
(
*
L2ContractEvent
,
error
)
{
var
l2ContractEvent
L2ContractEvent
result
:=
db
.
gorm
.
Where
(
&
ContractEvent
{
GUID
:
uuid
})
.
Take
(
&
l2ContractEvent
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
}
return
nil
,
result
.
Error
}
return
&
l2ContractEvent
,
nil
}
func
(
db
*
contractEventsDB
)
L2ContractEventByTxLogIndex
(
txHash
common
.
Hash
,
logIndex
uint64
)
(
*
L2ContractEvent
,
error
)
{
var
l2ContractEvent
L2ContractEvent
result
:=
db
.
gorm
.
Where
(
&
ContractEvent
{
TransactionHash
:
txHash
,
LogIndex
:
logIndex
})
.
Take
(
&
l2ContractEvent
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
}
return
nil
,
result
.
Error
}
return
&
l2ContractEvent
,
nil
}
indexer/e2e_test/
e2e
_test.go
→
indexer/e2e_test/
blocks
_test.go
View file @
601e0e5e
package
integration
_tests
package
e2e
_tests
import
(
"context"
...
...
@@ -7,17 +7,20 @@ import (
"time"
"github.com/ethereum-optimism/optimism/indexer/node"
"github.com/ethereum-optimism/optimism/indexer/processor"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
e2eutils
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
)
func
TestE2E
(
t
*
testing
.
T
)
{
func
TestE2E
BlockHeaders
(
t
*
testing
.
T
)
{
testSuite
:=
createE2ETestSuite
(
t
)
l1Client
:=
testSuite
.
OpSys
.
Clients
[
"l1"
]
...
...
@@ -44,7 +47,7 @@ func TestE2E(t *testing.T) {
return
(
l1Header
!=
nil
&&
l1Header
.
Number
.
Uint64
()
>=
l1Height
)
&&
(
l2Header
!=
nil
&&
l2Header
.
Number
.
Uint64
()
>=
9
),
nil
}))
t
.
Run
(
"indexes L2
header
s"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"indexes L2
block
s"
,
func
(
t
*
testing
.
T
)
{
latestL2Header
,
err
:=
testSuite
.
DB
.
Blocks
.
LatestL2BlockHeader
()
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
latestL2Header
)
...
...
@@ -104,6 +107,35 @@ func TestE2E(t *testing.T) {
}
})
t
.
Run
(
"indexes L1 blocks of interest"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"indexes L1 logs and associated blocks"
,
func
(
t
*
testing
.
T
)
{
testCtx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
devContracts
:=
processor
.
DevL1Contracts
()
.
ToSlice
()
logFilter
:=
ethereum
.
FilterQuery
{
FromBlock
:
big
.
NewInt
(
0
),
ToBlock
:
big
.
NewInt
(
int64
(
l1Height
)),
Addresses
:
devContracts
}
logs
,
err
:=
l1Client
.
FilterLogs
(
testCtx
,
logFilter
)
// []types.Log
require
.
NoError
(
t
,
err
)
for
_
,
log
:=
range
logs
{
contractEvent
,
err
:=
testSuite
.
DB
.
ContractEvents
.
L1ContractEventByTxLogIndex
(
log
.
TxHash
,
uint64
(
log
.
Index
))
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
log
.
Topics
[
0
],
contractEvent
.
EventSignature
)
require
.
Equal
(
t
,
log
.
BlockHash
,
contractEvent
.
BlockHash
)
require
.
Equal
(
t
,
log
.
TxHash
,
contractEvent
.
TransactionHash
)
require
.
Equal
(
t
,
log
.
Index
,
uint
(
contractEvent
.
LogIndex
))
// ensure the block is also indexed
block
,
err
:=
l1Client
.
BlockByNumber
(
testCtx
,
big
.
NewInt
(
int64
(
log
.
BlockNumber
)))
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
block
.
Time
(),
contractEvent
.
Timestamp
)
l1BlockHeader
,
err
:=
testSuite
.
DB
.
Blocks
.
L1BlockHeader
(
block
.
Number
())
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
block
.
Hash
(),
l1BlockHeader
.
Hash
)
require
.
Equal
(
t
,
block
.
ParentHash
(),
l1BlockHeader
.
ParentHash
)
require
.
Equal
(
t
,
block
.
Number
(),
l1BlockHeader
.
Number
.
Int
)
require
.
Equal
(
t
,
block
.
Time
(),
l1BlockHeader
.
Timestamp
)
}
})
}
indexer/e2e_test/bridge_test.go
0 → 100644
View file @
601e0e5e
package
e2e_tests
indexer/e2e_test/setup.go
View file @
601e0e5e
package
integration
_tests
package
e2e
_tests
import
(
"context"
...
...
@@ -13,6 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/indexer"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum-optimism/optimism/indexer/database"
op_e2e
"github.com/ethereum-optimism/optimism/op-e2e"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum/go-ethereum/log"
...
...
indexer/indexer.go
View file @
601e0e5e
...
...
@@ -9,8 +9,6 @@ import (
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/node"
"github.com/ethereum-optimism/optimism/indexer/processor"
"github.com/ethereum/go-ethereum/common"
)
// Indexer contains the necessary resources for
...
...
@@ -31,13 +29,7 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
}
// L1 Processor (hardhat devnet contracts). Make this configurable
l1Contracts
:=
processor
.
L1Contracts
{
OptimismPortal
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000000"
),
L2OutputOracle
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000001"
),
L1CrossDomainMessenger
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000002"
),
L1StandardBridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000003"
),
L1ERC721Bridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000004"
),
}
l1Contracts
:=
processor
.
DevL1Contracts
()
l1EthClient
,
err
:=
node
.
DialEthClient
(
cfg
.
RPCs
.
L1RPC
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -47,8 +39,8 @@ func NewIndexer(cfg config.Config) (*Indexer, error) {
return
nil
,
err
}
// L2Processor
l2Contracts
:=
processor
.
L2ContractPredeploys
()
// Make this configurable
// L2Processor
(predeploys). Although most likely the right setting, make this configurable?
l2Contracts
:=
processor
.
L2ContractPredeploys
()
l2EthClient
,
err
:=
node
.
DialEthClient
(
cfg
.
RPCs
.
L2RPC
)
if
err
!=
nil
{
return
nil
,
err
...
...
indexer/processor/l1_processor.go
View file @
601e0e5e
...
...
@@ -34,12 +34,17 @@ type L1Contracts struct {
// Remove afterwards?
}
type
checkpointAbi
struct
{
l2OutputOracle
*
abi
.
ABI
legacyStateCommitmentChain
*
abi
.
ABI
func
DevL1Contracts
()
L1Contracts
{
return
L1Contracts
{
OptimismPortal
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000000"
),
L2OutputOracle
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000001"
),
L1CrossDomainMessenger
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000002"
),
L1StandardBridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000003"
),
L1ERC721Bridge
:
common
.
HexToAddress
(
"0x6900000000000000000000000000000000000004"
),
}
}
func
(
c
L1Contracts
)
t
oSlice
()
[]
common
.
Address
{
func
(
c
L1Contracts
)
T
oSlice
()
[]
common
.
Address
{
fields
:=
reflect
.
VisibleFields
(
reflect
.
TypeOf
(
c
))
v
:=
reflect
.
ValueOf
(
c
)
...
...
@@ -51,6 +56,11 @@ func (c L1Contracts) toSlice() []common.Address {
return
contracts
}
type
checkpointAbi
struct
{
l2OutputOracle
*
abi
.
ABI
legacyStateCommitmentChain
*
abi
.
ABI
}
type
L1Processor
struct
{
processor
}
...
...
@@ -107,7 +117,7 @@ func NewL1Processor(logger log.Logger, ethClient node.EthClient, db *database.DB
func
l1ProcessFn
(
processLog
log
.
Logger
,
ethClient
node
.
EthClient
,
l1Contracts
L1Contracts
,
checkpointAbi
checkpointAbi
)
ProcessFn
{
rawEthClient
:=
ethclient
.
NewClient
(
ethClient
.
RawRpcClient
())
contractAddrs
:=
l1Contracts
.
t
oSlice
()
contractAddrs
:=
l1Contracts
.
T
oSlice
()
processLog
.
Info
(
"processor configured with contracts"
,
"contracts"
,
l1Contracts
)
outputProposedEventName
:=
"OutputProposed"
...
...
indexer/processor/l2_processor.go
View file @
601e0e5e
...
...
@@ -39,7 +39,7 @@ func L2ContractPredeploys() L2Contracts {
}
}
func
(
c
L2Contracts
)
t
oSlice
()
[]
common
.
Address
{
func
(
c
L2Contracts
)
T
oSlice
()
[]
common
.
Address
{
fields
:=
reflect
.
VisibleFields
(
reflect
.
TypeOf
(
c
))
v
:=
reflect
.
ValueOf
(
c
)
...
...
@@ -94,7 +94,7 @@ func NewL2Processor(logger log.Logger, ethClient node.EthClient, db *database.DB
func
l2ProcessFn
(
processLog
log
.
Logger
,
ethClient
node
.
EthClient
,
l2Contracts
L2Contracts
)
ProcessFn
{
rawEthClient
:=
ethclient
.
NewClient
(
ethClient
.
RawRpcClient
())
contractAddrs
:=
l2Contracts
.
t
oSlice
()
contractAddrs
:=
l2Contracts
.
T
oSlice
()
processLog
.
Info
(
"processor configured with contracts"
,
"contracts"
,
l2Contracts
)
return
func
(
db
*
database
.
DB
,
headers
[]
*
types
.
Header
)
error
{
numHeaders
:=
len
(
headers
)
...
...
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