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
ad5a7ce1
Commit
ad5a7ce1
authored
Jul 17, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add output index to output proposals table
parent
5d44097b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
blocks.go
indexer/database/blocks.go
+49
-1
20230523_create_schema.sql
indexer/migrations/20230523_create_schema.sql
+2
-0
No files found.
indexer/database/blocks.go
View file @
ad5a7ce1
...
...
@@ -3,6 +3,7 @@ package database
import
(
"context"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
...
...
@@ -53,15 +54,20 @@ type LegacyStateBatch struct {
type
OutputProposal
struct
{
OutputRoot
common
.
Hash
`gorm:"primaryKey;serializer:json"`
L2OutputIndex
U256
L2BlockNumber
U256
L1ContractEventGUID
uuid
.
UUID
}
type
BlocksView
interface
{
L1BlockHeader
(
*
big
.
Int
)
(
*
L1BlockHeader
,
error
)
LatestL1BlockHeader
()
(
*
L1BlockHeader
,
error
)
LatestCheckpointedOutput
()
(
*
OutputProposal
,
error
)
OutputProposal
(
index
*
big
.
Int
)
(
*
OutputProposal
,
error
)
L2BlockHeader
(
*
big
.
Int
)
(
*
L2BlockHeader
,
error
)
LatestL2BlockHeader
()
(
*
L2BlockHeader
,
error
)
}
...
...
@@ -104,6 +110,20 @@ func (db *blocksDB) StoreOutputProposals(outputs []*OutputProposal) error {
return
result
.
Error
}
func
(
db
*
blocksDB
)
L1BlockHeader
(
height
*
big
.
Int
)
(
*
L1BlockHeader
,
error
)
{
var
l1Header
L1BlockHeader
result
:=
db
.
gorm
.
Where
(
&
BlockHeader
{
Number
:
U256
{
Int
:
height
}})
.
Take
(
&
l1Header
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
}
return
nil
,
result
.
Error
}
return
&
l1Header
,
nil
}
func
(
db
*
blocksDB
)
LatestL1BlockHeader
()
(
*
L1BlockHeader
,
error
)
{
var
l1Header
L1BlockHeader
result
:=
db
.
gorm
.
Order
(
"number DESC"
)
.
Take
(
&
l1Header
)
...
...
@@ -120,7 +140,21 @@ func (db *blocksDB) LatestL1BlockHeader() (*L1BlockHeader, error) {
func
(
db
*
blocksDB
)
LatestCheckpointedOutput
()
(
*
OutputProposal
,
error
)
{
var
outputProposal
OutputProposal
result
:=
db
.
gorm
.
Order
(
"l2_block_number DESC"
)
.
Take
(
&
outputProposal
)
result
:=
db
.
gorm
.
Order
(
"l2_output_index DESC"
)
.
Take
(
&
outputProposal
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
}
return
nil
,
result
.
Error
}
return
&
outputProposal
,
nil
}
func
(
db
*
blocksDB
)
OutputProposal
(
index
*
big
.
Int
)
(
*
OutputProposal
,
error
)
{
var
outputProposal
OutputProposal
result
:=
db
.
gorm
.
Where
(
&
OutputProposal
{
L2OutputIndex
:
U256
{
Int
:
index
}})
.
Take
(
&
outputProposal
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
...
...
@@ -139,6 +173,20 @@ func (db *blocksDB) StoreL2BlockHeaders(headers []*L2BlockHeader) error {
return
result
.
Error
}
func
(
db
*
blocksDB
)
L2BlockHeader
(
height
*
big
.
Int
)
(
*
L2BlockHeader
,
error
)
{
var
l2Header
L2BlockHeader
result
:=
db
.
gorm
.
Where
(
&
BlockHeader
{
Number
:
U256
{
Int
:
height
}})
.
Take
(
&
l2Header
)
if
result
.
Error
!=
nil
{
if
errors
.
Is
(
result
.
Error
,
gorm
.
ErrRecordNotFound
)
{
return
nil
,
nil
}
return
nil
,
result
.
Error
}
return
&
l2Header
,
nil
}
func
(
db
*
blocksDB
)
LatestL2BlockHeader
()
(
*
L2BlockHeader
,
error
)
{
var
l2Header
L2BlockHeader
result
:=
db
.
gorm
.
Order
(
"number DESC"
)
.
Take
(
&
l2Header
)
...
...
indexer/migrations/20230523_create_schema.sql
View file @
ad5a7ce1
...
...
@@ -56,6 +56,8 @@ CREATE TABLE IF NOT EXISTS legacy_state_batches (
CREATE
TABLE
IF
NOT
EXISTS
output_proposals
(
output_root
VARCHAR
NOT
NULL
PRIMARY
KEY
,
l2_output_index
UINT256
,
l2_block_number
UINT256
,
l1_contract_event_guid
VARCHAR
REFERENCES
l1_contract_events
(
guid
)
...
...
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