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
7e0450b5
Unverified
Commit
7e0450b5
authored
Oct 06, 2022
by
Matthew Slipper
Committed by
GitHub
Oct 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexer: Update DB package (#3659)
parent
0a6166f8
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
228 additions
and
121 deletions
+228
-121
db.go
indexer/db/db.go
+103
-75
eth.go
indexer/db/eth.go
+4
-2
l1block.go
indexer/db/l1block.go
+5
-7
sql.go
indexer/db/sql.go
+29
-7
state_batch.go
indexer/db/state_batch.go
+30
-0
withdrawal.go
indexer/db/withdrawal.go
+51
-13
service.go
indexer/services/l1/service.go
+5
-6
service.go
indexer/services/l2/service.go
+1
-11
No files found.
indexer/db/db.go
View file @
7e0450b5
This diff is collapsed.
Click to expand it.
indexer/db/eth.go
View file @
7e0450b5
...
@@ -2,10 +2,12 @@ package db
...
@@ -2,10 +2,12 @@ package db
import
"github.com/ethereum/go-ethereum/common"
import
"github.com/ethereum/go-ethereum/common"
var
ETHL1Address
common
.
Address
// ETHL1Token is a placeholder token for differentiating ETH transactions from
// ETHL1Token is a placeholder token for differentiating ETH transactions from
// ERC20 transactions on L1.
// ERC20 transactions on L1.
var
ETHL1Token
=
&
Token
{
var
ETHL1Token
=
&
Token
{
Address
:
"0x0000000000000000000000000000000000000000"
,
Address
:
ETHL1Address
.
String
()
,
Name
:
"Ethereum"
,
Name
:
"Ethereum"
,
Symbol
:
"ETH"
,
Symbol
:
"ETH"
,
Decimals
:
18
,
Decimals
:
18
,
...
@@ -18,7 +20,7 @@ var ETHL2Address = common.HexToAddress("0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD00
...
@@ -18,7 +20,7 @@ var ETHL2Address = common.HexToAddress("0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD00
// ETHL2Token is a placeholder token for differentiating ETH transactions from
// ETHL2Token is a placeholder token for differentiating ETH transactions from
// ERC20 transactions on L2.
// ERC20 transactions on L2.
var
ETHL2Token
=
&
Token
{
var
ETHL2Token
=
&
Token
{
Address
:
"0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000"
,
Address
:
ETHL2Address
.
String
()
,
Name
:
"Ethereum"
,
Name
:
"Ethereum"
,
Symbol
:
"ETH"
,
Symbol
:
"ETH"
,
Decimals
:
18
,
Decimals
:
18
,
...
...
indexer/db/l1block.go
View file @
7e0450b5
...
@@ -6,12 +6,11 @@ import (
...
@@ -6,12 +6,11 @@ import (
// IndexedL1Block contains the L1 block including the deposits in it.
// IndexedL1Block contains the L1 block including the deposits in it.
type
IndexedL1Block
struct
{
type
IndexedL1Block
struct
{
Hash
common
.
Hash
Hash
common
.
Hash
ParentHash
common
.
Hash
ParentHash
common
.
Hash
Number
uint64
Number
uint64
Timestamp
uint64
Timestamp
uint64
Deposits
[]
Deposit
Deposits
[]
Deposit
Withdrawals
[]
Withdrawal
}
}
// String returns the block hash for the indexed l1 block.
// String returns the block hash for the indexed l1 block.
...
@@ -25,7 +24,6 @@ type IndexedL2Block struct {
...
@@ -25,7 +24,6 @@ type IndexedL2Block struct {
ParentHash
common
.
Hash
ParentHash
common
.
Hash
Number
uint64
Number
uint64
Timestamp
uint64
Timestamp
uint64
Deposits
[]
Deposit
Withdrawals
[]
Withdrawal
Withdrawals
[]
Withdrawal
}
}
...
...
indexer/db/sql.go
View file @
7e0450b5
...
@@ -28,10 +28,8 @@ CREATE TABLE IF NOT EXISTS deposits (
...
@@ -28,10 +28,8 @@ CREATE TABLE IF NOT EXISTS deposits (
amount VARCHAR NOT NULL,
amount VARCHAR NOT NULL,
data BYTEA NOT NULL,
data BYTEA NOT NULL,
log_index INTEGER NOT NULL,
log_index INTEGER NOT NULL,
l1_block_hash VARCHAR NOT NULL REFERENCES l1_blocks(hash),
block_hash VARCHAR NOT NULL REFERENCES l1_blocks(hash),
l2_block_hash VARCHAR REFERENCES l2_blocks(hash),
tx_hash VARCHAR NOT NULL
tx_hash VARCHAR NOT NULL,
failed BOOLEAN NOT NULL DEFAULT false
)
)
`
`
...
@@ -53,6 +51,20 @@ CREATE TABLE IF NOT EXISTS l2_tokens (
...
@@ -53,6 +51,20 @@ CREATE TABLE IF NOT EXISTS l2_tokens (
)
)
`
`
const
createStateBatchesTable
=
`
CREATE TABLE IF NOT EXISTS state_batches (
index INTEGER NOT NULL PRIMARY KEY,
root VARCHAR NOT NULL,
size INTEGER NOT NULL,
prev_total INTEGER NOT NULL,
extra_data BYTEA NOT NULL,
block_hash VARCHAR NOT NULL REFERENCES l1_blocks(hash)
);
CREATE INDEX IF NOT EXISTS state_batches_block_hash ON state_batches(block_hash);
CREATE INDEX IF NOT EXISTS state_batches_size ON state_batches(size);
CREATE INDEX IF NOT EXISTS state_batches_prev_total ON state_batches(prev_total);
`
const
createWithdrawalsTable
=
`
const
createWithdrawalsTable
=
`
CREATE TABLE IF NOT EXISTS withdrawals (
CREATE TABLE IF NOT EXISTS withdrawals (
guid VARCHAR PRIMARY KEY NOT NULL,
guid VARCHAR PRIMARY KEY NOT NULL,
...
@@ -63,9 +75,9 @@ CREATE TABLE IF NOT EXISTS withdrawals (
...
@@ -63,9 +75,9 @@ CREATE TABLE IF NOT EXISTS withdrawals (
amount VARCHAR NOT NULL,
amount VARCHAR NOT NULL,
data BYTEA NOT NULL,
data BYTEA NOT NULL,
log_index INTEGER NOT NULL,
log_index INTEGER NOT NULL,
l1_block_hash VARCHAR REFERENCES l1
_blocks(hash),
block_hash VARCHAR NOT NULL REFERENCES l2
_blocks(hash),
l2_block_hash VARCHAR NOT NULL REFERENCES l2_blocks(hash)
,
tx_hash VARCHAR NOT NULL
,
tx_hash VARCHAR NOT NULL
state_batch INTEGER REFERENCES state_batches(index)
)
)
`
`
...
@@ -110,15 +122,25 @@ CREATE TABLE IF NOT EXISTS airdrops (
...
@@ -110,15 +122,25 @@ CREATE TABLE IF NOT EXISTS airdrops (
)
)
`
`
const
updateWithdrawalsTable
=
`
ALTER TABLE withdrawals ADD COLUMN IF NOT EXISTS br_withdrawal_hash VARCHAR NULL;
ALTER TABLE withdrawals ADD COLUMN IF NOT EXISTS br_withdrawal_finalized_tx_hash VARCHAR NULL;
ALTER TABLE withdrawals ADD COLUMN IF NOT EXISTS br_withdrawal_finalized_log_index BOOLEAN NULL;
ALTER TABLE withdrawals ADD COLUMN IF NOT EXISTS br_withdrawal_success BOOLEAN NULL;
CREATE INDEX IF NOT EXISTS withdrawals_br_withdrawal_hash ON withdrawals(br_withdrawal_hash);
`
var
schema
=
[]
string
{
var
schema
=
[]
string
{
createL1BlocksTable
,
createL1BlocksTable
,
createL2BlocksTable
,
createL2BlocksTable
,
createL1TokensTable
,
createL1TokensTable
,
createL2TokensTable
,
createL2TokensTable
,
createStateBatchesTable
,
insertETHL1Token
,
insertETHL1Token
,
insertETHL2Token
,
insertETHL2Token
,
createDepositsTable
,
createDepositsTable
,
createWithdrawalsTable
,
createWithdrawalsTable
,
createL1L2NumberIndex
,
createL1L2NumberIndex
,
createAirdropsTable
,
createAirdropsTable
,
updateWithdrawalsTable
,
}
}
indexer/db/state_batch.go
0 → 100644
View file @
7e0450b5
package
db
import
(
"math/big"
"github.com/ethereum/go-ethereum/common"
)
// StateBatch is the state batch containing merkle root of the withdrawals
// periodically written to L1.
type
StateBatch
struct
{
Index
*
big
.
Int
Root
common
.
Hash
Size
*
big
.
Int
PrevTotal
*
big
.
Int
ExtraData
[]
byte
BlockHash
common
.
Hash
}
// StateBatchJSON contains StateBatch data suitable for JSON serialization.
type
StateBatchJSON
struct
{
Index
uint64
`json:"index"`
Root
string
`json:"root"`
Size
uint64
`json:"size"`
PrevTotal
uint64
`json:"prevTotal"`
ExtraData
[]
byte
`json:"extraData"`
BlockHash
string
`json:"blockHash"`
BlockNumber
uint64
`json:"blockNumber"`
BlockTimestamp
uint64
`json:"blockTimestamp"`
}
indexer/db/withdrawal.go
View file @
7e0450b5
...
@@ -17,6 +17,7 @@ type Withdrawal struct {
...
@@ -17,6 +17,7 @@ type Withdrawal struct {
Amount
*
big
.
Int
Amount
*
big
.
Int
Data
[]
byte
Data
[]
byte
LogIndex
uint
LogIndex
uint
BedrockHash
*
common
.
Hash
}
}
// String returns the tx hash for the withdrawal.
// String returns the tx hash for the withdrawal.
...
@@ -26,17 +27,54 @@ func (w Withdrawal) String() string {
...
@@ -26,17 +27,54 @@ func (w Withdrawal) String() string {
// WithdrawalJSON contains Withdrawal data suitable for JSON serialization.
// WithdrawalJSON contains Withdrawal data suitable for JSON serialization.
type
WithdrawalJSON
struct
{
type
WithdrawalJSON
struct
{
GUID
string
`json:"guid"`
GUID
string
`json:"guid"`
FromAddress
string
`json:"from"`
FromAddress
string
`json:"from"`
ToAddress
string
`json:"to"`
ToAddress
string
`json:"to"`
L1Token
string
`json:"l1Token"`
L1Token
string
`json:"l1Token"`
L2Token
*
Token
`json:"l2Token"`
L2Token
*
Token
`json:"l2Token"`
Amount
string
`json:"amount"`
Amount
string
`json:"amount"`
Data
[]
byte
`json:"data"`
Data
[]
byte
`json:"data"`
LogIndex
uint64
`json:"logIndex"`
LogIndex
uint64
`json:"logIndex"`
L1BlockNumber
uint64
`json:"l1BlockNumber"`
BlockNumber
uint64
`json:"blockNumber"`
L1BlockTimestamp
string
`json:"l1BlockTimestamp"`
BlockTimestamp
string
`json:"blockTimestamp"`
L2BlockNumber
uint64
`json:"l2BlockNumber"`
TxHash
string
`json:"transactionHash"`
L2BlockTimestamp
string
`json:"l2BlockTimestamp"`
Batch
*
StateBatchJSON
`json:"batch"`
TxHash
string
`json:"transactionHash"`
BedrockWithdrawalHash
*
string
`json:"bedrockWithdrawalHash"`
}
type
FinalizationState
int
const
(
FinalizationStateAny
FinalizationState
=
iota
FinalizationStateFinalized
FinalizationStateUnfinalized
)
func
ParseFinalizationState
(
in
string
)
FinalizationState
{
switch
in
{
case
"true"
:
return
FinalizationStateFinalized
case
"false"
:
return
FinalizationStateUnfinalized
default
:
return
FinalizationStateAny
}
}
func
(
f
FinalizationState
)
SQL
()
string
{
switch
f
{
case
FinalizationStateFinalized
:
return
"AND withdrawals.l1_block_hash IS NOT NULL"
case
FinalizationStateUnfinalized
:
return
"AND withdrawals.l2_block_hash IS NULL"
}
return
""
}
type
FinalizedWithdrawal
struct
{
WithdrawalHash
common
.
Hash
TxHash
common
.
Hash
Success
bool
LogIndex
uint
}
}
indexer/services/l1/service.go
View file @
7e0450b5
...
@@ -298,12 +298,11 @@ func (s *Service) Update(newHeader *types.Header) error {
...
@@ -298,12 +298,11 @@ func (s *Service) Update(newHeader *types.Header) error {
}
}
block
:=
&
db
.
IndexedL1Block
{
block
:=
&
db
.
IndexedL1Block
{
Hash
:
blockHash
,
Hash
:
blockHash
,
ParentHash
:
header
.
ParentHash
,
ParentHash
:
header
.
ParentHash
,
Number
:
number
,
Number
:
number
,
Timestamp
:
header
.
Time
,
Timestamp
:
header
.
Time
,
Deposits
:
deposits
,
Deposits
:
deposits
,
Withdrawals
:
withdrawals
,
}
}
err
:=
s
.
cfg
.
DB
.
AddIndexedL1Block
(
block
)
err
:=
s
.
cfg
.
DB
.
AddIndexedL1Block
(
block
)
...
...
indexer/services/l2/service.go
View file @
7e0450b5
...
@@ -286,7 +286,6 @@ func (s *Service) Update(newHeader *types.Header) error {
...
@@ -286,7 +286,6 @@ func (s *Service) Update(newHeader *types.Header) error {
for
i
,
header
:=
range
headers
{
for
i
,
header
:=
range
headers
{
blockHash
:=
header
.
Hash
()
blockHash
:=
header
.
Hash
()
number
:=
header
.
Number
.
Uint64
()
number
:=
header
.
Number
.
Uint64
()
deposits
:=
depositsByBlockHash
[
blockHash
]
withdrawals
:=
withdrawalsByBlockHash
[
blockHash
]
withdrawals
:=
withdrawalsByBlockHash
[
blockHash
]
if
len
(
withdrawals
)
==
0
&&
i
!=
len
(
headers
)
-
1
{
if
len
(
withdrawals
)
==
0
&&
i
!=
len
(
headers
)
-
1
{
...
@@ -298,7 +297,6 @@ func (s *Service) Update(newHeader *types.Header) error {
...
@@ -298,7 +297,6 @@ func (s *Service) Update(newHeader *types.Header) error {
ParentHash
:
header
.
ParentHash
,
ParentHash
:
header
.
ParentHash
,
Number
:
number
,
Number
:
number
,
Timestamp
:
header
.
Time
,
Timestamp
:
header
.
Time
,
Deposits
:
deposits
,
Withdrawals
:
withdrawals
,
Withdrawals
:
withdrawals
,
}
}
...
@@ -359,15 +357,7 @@ func (s *Service) GetIndexerStatus(w http.ResponseWriter, r *http.Request) {
...
@@ -359,15 +357,7 @@ func (s *Service) GetIndexerStatus(w http.ResponseWriter, r *http.Request) {
}
}
func
(
s
*
Service
)
GetWithdrawalStatus
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
s
*
Service
)
GetWithdrawalStatus
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
// Temporary stub until rest of indexer is landed
withdrawal
,
err
:=
s
.
cfg
.
DB
.
GetWithdrawalStatus
(
common
.
HexToHash
(
vars
[
"hash"
]))
if
err
!=
nil
{
server
.
RespondWithError
(
w
,
http
.
StatusInternalServerError
,
err
.
Error
())
return
}
server
.
RespondWithJSON
(
w
,
http
.
StatusOK
,
withdrawal
)
}
}
func
(
s
*
Service
)
GetWithdrawals
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
s
*
Service
)
GetWithdrawals
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
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