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
b9c1ce0f
Unverified
Commit
b9c1ce0f
authored
Oct 09, 2022
by
Matthew Slipper
Committed by
GitHub
Oct 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexer: Perform Bedrock DB upgrade (#3666)
parent
3dcf11ba
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
45 deletions
+83
-45
db.go
indexer/db/db.go
+56
-22
l1block.go
indexer/db/l1block.go
+6
-5
sql.go
indexer/db/sql.go
+2
-2
withdrawal.go
indexer/db/withdrawal.go
+18
-15
service.go
indexer/services/l2/service.go
+1
-1
No files found.
indexer/db/db.go
View file @
b9c1ce0f
...
@@ -197,6 +197,12 @@ func (d *Database) AddIndexedL1Block(block *IndexedL1Block) error {
...
@@ -197,6 +197,12 @@ func (d *Database) AddIndexedL1Block(block *IndexedL1Block) error {
VALUES
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
`
`
const
updateWithdrawalStatement
=
`
UPDATE withdrawals SET (br_withdrawal_finalized_tx_hash, br_withdrawal_finalized_log_index, br_withdrawal_finalized_success) = ($1, $2, $3)
WHERE br_withdrawal_hash = $4
`
return
txn
(
d
.
db
,
func
(
tx
*
sql
.
Tx
)
error
{
return
txn
(
d
.
db
,
func
(
tx
*
sql
.
Tx
)
error
{
_
,
err
:=
tx
.
Exec
(
_
,
err
:=
tx
.
Exec
(
insertBlockStatement
,
insertBlockStatement
,
...
@@ -209,26 +215,39 @@ func (d *Database) AddIndexedL1Block(block *IndexedL1Block) error {
...
@@ -209,26 +215,39 @@ func (d *Database) AddIndexedL1Block(block *IndexedL1Block) error {
return
err
return
err
}
}
if
len
(
block
.
Deposits
)
==
0
{
if
len
(
block
.
Deposits
)
>
0
{
return
nil
for
_
,
deposit
:=
range
block
.
Deposits
{
_
,
err
=
tx
.
Exec
(
insertDepositStatement
,
NewGUID
(),
deposit
.
FromAddress
.
String
(),
deposit
.
ToAddress
.
String
(),
deposit
.
L1Token
.
String
(),
deposit
.
L2Token
.
String
(),
deposit
.
Amount
.
String
(),
deposit
.
TxHash
.
String
(),
deposit
.
LogIndex
,
block
.
Hash
.
String
(),
deposit
.
Data
,
)
if
err
!=
nil
{
return
err
}
}
}
}
for
_
,
deposit
:=
range
block
.
Deposits
{
if
len
(
block
.
FinalizedWithdrawals
)
>
0
{
_
,
err
=
tx
.
Exec
(
for
_
,
wd
:=
range
block
.
FinalizedWithdrawals
{
insertDepositStatement
,
_
,
err
=
tx
.
Exec
(
NewGUID
(),
updateWithdrawalStatement
,
deposit
.
FromAddress
.
String
(),
wd
.
TxHash
.
String
(),
deposit
.
ToAddress
.
String
(),
wd
.
LogIndex
,
deposit
.
L1Token
.
String
(),
wd
.
Success
,
deposit
.
L2Token
.
String
(),
wd
.
WithdrawalHash
.
String
(),
deposit
.
Amount
.
String
(),
)
deposit
.
TxHash
.
String
(),
if
err
!=
nil
{
deposit
.
LogIndex
,
return
err
block
.
Hash
.
String
(),
}
deposit
.
Data
,
)
if
err
!=
nil
{
return
err
}
}
}
}
...
@@ -459,19 +478,21 @@ func (d *Database) GetWithdrawalBatch(hash common.Hash) (*StateBatchJSON, error)
...
@@ -459,19 +478,21 @@ func (d *Database) GetWithdrawalBatch(hash common.Hash) (*StateBatchJSON, error)
// GetWithdrawalsByAddress returns the list of Withdrawals indexed for the given
// GetWithdrawalsByAddress returns the list of Withdrawals indexed for the given
// address paginated by the given params.
// address paginated by the given params.
func
(
d
*
Database
)
GetWithdrawalsByAddress
(
address
common
.
Address
,
page
PaginationParam
)
(
*
PaginatedWithdrawals
,
error
)
{
func
(
d
*
Database
)
GetWithdrawalsByAddress
(
address
common
.
Address
,
page
PaginationParam
,
state
FinalizationState
)
(
*
PaginatedWithdrawals
,
error
)
{
selectWithdrawalsStatement
:=
fmt
.
Sprintf
(
`
selectWithdrawalsStatement
:=
fmt
.
Sprintf
(
`
SELECT
SELECT
withdrawals.guid, withdrawals.from_address, withdrawals.to_address,
withdrawals.guid, withdrawals.from_address, withdrawals.to_address,
withdrawals.amount, withdrawals.tx_hash, withdrawals.data,
withdrawals.amount, withdrawals.tx_hash, withdrawals.data,
withdrawals.l1_token, withdrawals.l2_token,
withdrawals.l1_token, withdrawals.l2_token,
l2_tokens.name, l2_tokens.symbol, l2_tokens.decimals,
l2_tokens.name, l2_tokens.symbol, l2_tokens.decimals,
l2_blocks.number, l2_blocks.timestamp, withdrawals.br_withdrawal_hash
l2_blocks.number, l2_blocks.timestamp, withdrawals.br_withdrawal_hash,
withdrawals.br_withdrawal_finalized_tx_hash, withdrawals.br_withdrawal_finalized_log_index,
withdrawals.br_withdrawal_finalized_success
FROM withdrawals
FROM withdrawals
INNER JOIN l2_blocks ON withdrawals.block_hash=l2_blocks.hash
INNER JOIN l2_blocks ON withdrawals.block_hash=l2_blocks.hash
INNER JOIN l2_tokens ON withdrawals.l2_token=l2_tokens.address
INNER JOIN l2_tokens ON withdrawals.l2_token=l2_tokens.address
WHERE withdrawals.from_address = $1 %s ORDER BY l2_blocks.timestamp LIMIT $2 OFFSET $3;
WHERE withdrawals.from_address = $1 %s ORDER BY l2_blocks.timestamp LIMIT $2 OFFSET $3;
`
,
FinalizationStateAny
.
SQL
())
`
,
state
.
SQL
())
var
withdrawals
[]
WithdrawalJSON
var
withdrawals
[]
WithdrawalJSON
err
:=
txn
(
d
.
db
,
func
(
tx
*
sql
.
Tx
)
error
{
err
:=
txn
(
d
.
db
,
func
(
tx
*
sql
.
Tx
)
error
{
...
@@ -485,13 +506,16 @@ func (d *Database) GetWithdrawalsByAddress(address common.Address, page Paginati
...
@@ -485,13 +506,16 @@ func (d *Database) GetWithdrawalsByAddress(address common.Address, page Paginati
var
withdrawal
WithdrawalJSON
var
withdrawal
WithdrawalJSON
var
l2Token
Token
var
l2Token
Token
var
wdHash
sql
.
NullString
var
wdHash
sql
.
NullString
var
finTxHash
sql
.
NullString
var
finLogIndex
sql
.
NullInt32
var
finSuccess
sql
.
NullBool
if
err
:=
rows
.
Scan
(
if
err
:=
rows
.
Scan
(
&
withdrawal
.
GUID
,
&
withdrawal
.
FromAddress
,
&
withdrawal
.
ToAddress
,
&
withdrawal
.
GUID
,
&
withdrawal
.
FromAddress
,
&
withdrawal
.
ToAddress
,
&
withdrawal
.
Amount
,
&
withdrawal
.
TxHash
,
&
withdrawal
.
Data
,
&
withdrawal
.
Amount
,
&
withdrawal
.
TxHash
,
&
withdrawal
.
Data
,
&
withdrawal
.
L1Token
,
&
l2Token
.
Address
,
&
withdrawal
.
L1Token
,
&
l2Token
.
Address
,
&
l2Token
.
Name
,
&
l2Token
.
Symbol
,
&
l2Token
.
Decimals
,
&
l2Token
.
Name
,
&
l2Token
.
Symbol
,
&
l2Token
.
Decimals
,
&
withdrawal
.
BlockNumber
,
&
withdrawal
.
BlockTimestamp
,
&
withdrawal
.
BlockNumber
,
&
withdrawal
.
BlockTimestamp
,
&
wdHash
,
&
wdHash
,
&
finTxHash
,
&
finLogIndex
,
&
finSuccess
,
);
err
!=
nil
{
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -499,6 +523,16 @@ func (d *Database) GetWithdrawalsByAddress(address common.Address, page Paginati
...
@@ -499,6 +523,16 @@ func (d *Database) GetWithdrawalsByAddress(address common.Address, page Paginati
if
wdHash
.
Valid
{
if
wdHash
.
Valid
{
withdrawal
.
BedrockWithdrawalHash
=
&
wdHash
.
String
withdrawal
.
BedrockWithdrawalHash
=
&
wdHash
.
String
}
}
if
finTxHash
.
Valid
{
withdrawal
.
BedrockFinalizedTxHash
=
&
finTxHash
.
String
}
if
finLogIndex
.
Valid
{
idx
:=
int
(
finLogIndex
.
Int32
)
withdrawal
.
BedrockFinalizedLogIndex
=
&
idx
}
if
finSuccess
.
Valid
{
withdrawal
.
BedrockFinalizedSuccess
=
&
finSuccess
.
Bool
}
withdrawals
=
append
(
withdrawals
,
withdrawal
)
withdrawals
=
append
(
withdrawals
,
withdrawal
)
}
}
...
...
indexer/db/l1block.go
View file @
b9c1ce0f
...
@@ -6,11 +6,12 @@ import (
...
@@ -6,11 +6,12 @@ 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
FinalizedWithdrawals
[]
FinalizedWithdrawal
}
}
// String returns the block hash for the indexed l1 block.
// String returns the block hash for the indexed l1 block.
...
...
indexer/db/sql.go
View file @
b9c1ce0f
...
@@ -125,8 +125,8 @@ CREATE TABLE IF NOT EXISTS airdrops (
...
@@ -125,8 +125,8 @@ CREATE TABLE IF NOT EXISTS airdrops (
const
updateWithdrawalsTable
=
`
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_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_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_finalized_log_index
INTEGER
NULL;
ALTER TABLE withdrawals ADD COLUMN IF NOT EXISTS br_withdrawal_success BOOLEAN NULL;
ALTER TABLE withdrawals ADD COLUMN IF NOT EXISTS br_withdrawal_
finalized_
success BOOLEAN NULL;
CREATE INDEX IF NOT EXISTS withdrawals_br_withdrawal_hash ON withdrawals(br_withdrawal_hash);
CREATE INDEX IF NOT EXISTS withdrawals_br_withdrawal_hash ON withdrawals(br_withdrawal_hash);
`
`
...
...
indexer/db/withdrawal.go
View file @
b9c1ce0f
...
@@ -27,19 +27,22 @@ func (w Withdrawal) String() string {
...
@@ -27,19 +27,22 @@ 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"`
BlockNumber
uint64
`json:"blockNumber"`
BlockNumber
uint64
`json:"blockNumber"`
BlockTimestamp
string
`json:"blockTimestamp"`
BlockTimestamp
string
`json:"blockTimestamp"`
TxHash
string
`json:"transactionHash"`
TxHash
string
`json:"transactionHash"`
Batch
*
StateBatchJSON
`json:"batch"`
Batch
*
StateBatchJSON
`json:"batch"`
BedrockWithdrawalHash
*
string
`json:"bedrockWithdrawalHash"`
BedrockWithdrawalHash
*
string
`json:"bedrockWithdrawalHash"`
BedrockFinalizedTxHash
*
string
`json:"bedrockFinalizedTxHash"`
BedrockFinalizedLogIndex
*
int
`json:"bedrockFinalizedLogIndex"`
BedrockFinalizedSuccess
*
bool
`json:"bedrockFinalizedSuccess"`
}
}
type
FinalizationState
int
type
FinalizationState
int
...
@@ -64,9 +67,9 @@ func ParseFinalizationState(in string) FinalizationState {
...
@@ -64,9 +67,9 @@ func ParseFinalizationState(in string) FinalizationState {
func
(
f
FinalizationState
)
SQL
()
string
{
func
(
f
FinalizationState
)
SQL
()
string
{
switch
f
{
switch
f
{
case
FinalizationStateFinalized
:
case
FinalizationStateFinalized
:
return
"AND withdrawals.
l1_block
_hash IS NOT NULL"
return
"AND withdrawals.
br_withdrawal_finalized_tx
_hash IS NOT NULL"
case
FinalizationStateUnfinalized
:
case
FinalizationStateUnfinalized
:
return
"AND withdrawals.
l2_block
_hash IS NULL"
return
"AND withdrawals.
br_withdrawal_finalized_tx
_hash IS NULL"
}
}
return
""
return
""
...
...
indexer/services/l2/service.go
View file @
b9c1ce0f
...
@@ -385,7 +385,7 @@ func (s *Service) GetWithdrawals(w http.ResponseWriter, r *http.Request) {
...
@@ -385,7 +385,7 @@ func (s *Service) GetWithdrawals(w http.ResponseWriter, r *http.Request) {
Offset
:
uint64
(
offset
),
Offset
:
uint64
(
offset
),
}
}
withdrawals
,
err
:=
s
.
cfg
.
DB
.
GetWithdrawalsByAddress
(
common
.
HexToAddress
(
vars
[
"address"
]),
page
)
withdrawals
,
err
:=
s
.
cfg
.
DB
.
GetWithdrawalsByAddress
(
common
.
HexToAddress
(
vars
[
"address"
]),
page
,
db
.
FinalizationStateAny
)
if
err
!=
nil
{
if
err
!=
nil
{
server
.
RespondWithError
(
w
,
http
.
StatusInternalServerError
,
err
.
Error
())
server
.
RespondWithError
(
w
,
http
.
StatusInternalServerError
,
err
.
Error
())
return
return
...
...
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