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
ff7f2d3c
Unverified
Commit
ff7f2d3c
authored
Aug 27, 2022
by
Javed Khan
Committed by
GitHub
Aug 26, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexer: rm state batch (#3323)
parent
1571d2f9
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
11 additions
and
176 deletions
+11
-176
db.go
indexer/db/db.go
+0
-93
sql.go
indexer/db/sql.go
+0
-16
state_batch.go
indexer/db/state_batch.go
+0
-30
withdrawal.go
indexer/db/withdrawal.go
+11
-12
indexer.go
indexer/indexer.go
+0
-1
metrics.go
indexer/metrics/metrics.go
+0
-12
service.go
indexer/services/l2/service.go
+0
-12
No files found.
indexer/db/db.go
View file @
ff7f2d3c
...
@@ -292,36 +292,6 @@ func (d *Database) AddIndexedL2Block(block *IndexedL2Block) error {
...
@@ -292,36 +292,6 @@ func (d *Database) AddIndexedL2Block(block *IndexedL2Block) error {
})
})
}
}
// AddStateBatch inserts the state batches into the known state batches
// database.
func
(
d
*
Database
)
AddStateBatch
(
batches
[]
StateBatch
)
error
{
const
insertStateBatchStatement
=
`
INSERT INTO state_batches
(index, root, size, prev_total, extra_data, block_hash)
VALUES
($1, $2, $3, $4, $5, $6)
`
return
txn
(
d
.
db
,
func
(
tx
*
sql
.
Tx
)
error
{
for
_
,
sb
:=
range
batches
{
_
,
err
:=
tx
.
Exec
(
insertStateBatchStatement
,
sb
.
Index
.
Uint64
(),
sb
.
Root
.
String
(),
sb
.
Size
.
Uint64
(),
sb
.
PrevTotal
.
Uint64
(),
sb
.
ExtraData
,
sb
.
BlockHash
.
String
(),
)
if
err
!=
nil
{
return
err
}
}
return
nil
})
}
// GetDepositsByAddress returns the list of Deposits indexed for the given
// GetDepositsByAddress returns the list of Deposits indexed for the given
// address paginated by the given params.
// address paginated by the given params.
func
(
d
*
Database
)
GetDepositsByAddress
(
address
common
.
Address
,
page
PaginationParam
)
(
*
PaginatedDeposits
,
error
)
{
func
(
d
*
Database
)
GetDepositsByAddress
(
address
common
.
Address
,
page
PaginationParam
)
(
*
PaginatedDeposits
,
error
)
{
...
@@ -398,64 +368,6 @@ func (d *Database) GetDepositsByAddress(address common.Address, page PaginationP
...
@@ -398,64 +368,6 @@ func (d *Database) GetDepositsByAddress(address common.Address, page PaginationP
},
nil
},
nil
}
}
// GetWithdrawalBatch returns the StateBatch corresponding to the given
// withdrawal transaction hash.
func
(
d
*
Database
)
GetWithdrawalBatch
(
hash
common
.
Hash
)
(
*
StateBatchJSON
,
error
)
{
const
selectWithdrawalBatchStatement
=
`
SELECT
state_batches.index, state_batches.root, state_batches.size, state_batches.prev_total, state_batches.extra_data, state_batches.block_hash,
l1_blocks.number, l1_blocks.timestamp
FROM state_batches
INNER JOIN l1_blocks ON state_batches.block_hash = l1_blocks.hash
WHERE size + prev_total >= (
SELECT
number
FROM
withdrawals
INNER JOIN l2_blocks ON withdrawals.block_hash = l2_blocks.hash where tx_hash=$1
) ORDER BY "index" LIMIT 1;
`
var
batch
*
StateBatchJSON
err
:=
txn
(
d
.
db
,
func
(
tx
*
sql
.
Tx
)
error
{
row
:=
tx
.
QueryRow
(
selectWithdrawalBatchStatement
,
hash
.
String
())
if
row
.
Err
()
!=
nil
{
return
row
.
Err
()
}
var
index
,
size
,
prevTotal
,
blockNumber
,
blockTimestamp
uint64
var
root
,
blockHash
string
var
extraData
[]
byte
err
:=
row
.
Scan
(
&
index
,
&
root
,
&
size
,
&
prevTotal
,
&
extraData
,
&
blockHash
,
&
blockNumber
,
&
blockTimestamp
)
if
err
!=
nil
{
if
errors
.
Is
(
err
,
sql
.
ErrNoRows
)
{
batch
=
nil
return
nil
}
return
err
}
batch
=
&
StateBatchJSON
{
Index
:
index
,
Root
:
root
,
Size
:
size
,
PrevTotal
:
prevTotal
,
ExtraData
:
extraData
,
BlockHash
:
blockHash
,
BlockNumber
:
blockNumber
,
BlockTimestamp
:
blockTimestamp
,
}
return
nil
})
if
err
!=
nil
{
return
nil
,
err
}
return
batch
,
nil
}
// 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
)
(
*
PaginatedWithdrawals
,
error
)
{
...
@@ -503,11 +415,6 @@ func (d *Database) GetWithdrawalsByAddress(address common.Address, page Paginati
...
@@ -503,11 +415,6 @@ func (d *Database) GetWithdrawalsByAddress(address common.Address, page Paginati
return
nil
,
err
return
nil
,
err
}
}
for
i
:=
range
withdrawals
{
batch
,
_
:=
d
.
GetWithdrawalBatch
(
common
.
HexToHash
(
withdrawals
[
i
]
.
TxHash
))
withdrawals
[
i
]
.
Batch
=
batch
}
const
selectWithdrawalCountStatement
=
`
const
selectWithdrawalCountStatement
=
`
SELECT
SELECT
count(*)
count(*)
...
...
indexer/db/sql.go
View file @
ff7f2d3c
...
@@ -51,20 +51,6 @@ CREATE TABLE IF NOT EXISTS l2_tokens (
...
@@ -51,20 +51,6 @@ 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,
...
@@ -77,7 +63,6 @@ CREATE TABLE IF NOT EXISTS withdrawals (
...
@@ -77,7 +63,6 @@ CREATE TABLE IF NOT EXISTS withdrawals (
log_index INTEGER NOT NULL,
log_index INTEGER NOT NULL,
block_hash VARCHAR NOT NULL REFERENCES l2_blocks(hash),
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)
)
)
`
`
...
@@ -127,7 +112,6 @@ var schema = []string{
...
@@ -127,7 +112,6 @@ var schema = []string{
createL2BlocksTable
,
createL2BlocksTable
,
createL1TokensTable
,
createL1TokensTable
,
createL2TokensTable
,
createL2TokensTable
,
createStateBatchesTable
,
insertETHL1Token
,
insertETHL1Token
,
insertETHL2Token
,
insertETHL2Token
,
createDepositsTable
,
createDepositsTable
,
...
...
indexer/db/state_batch.go
deleted
100644 → 0
View file @
1571d2f9
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 @
ff7f2d3c
...
@@ -37,5 +37,4 @@ type WithdrawalJSON struct {
...
@@ -37,5 +37,4 @@ type WithdrawalJSON struct {
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"`
}
}
indexer/indexer.go
View file @
ff7f2d3c
...
@@ -212,7 +212,6 @@ func (b *Indexer) Serve() error {
...
@@ -212,7 +212,6 @@ func (b *Indexer) Serve() error {
b
.
router
.
HandleFunc
(
"/v1/l1/status"
,
b
.
l1IndexingService
.
GetIndexerStatus
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/l1/status"
,
b
.
l1IndexingService
.
GetIndexerStatus
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/l2/status"
,
b
.
l2IndexingService
.
GetIndexerStatus
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/l2/status"
,
b
.
l2IndexingService
.
GetIndexerStatus
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/deposits/0x{address:[a-fA-F0-9]{40}}"
,
b
.
l1IndexingService
.
GetDeposits
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/deposits/0x{address:[a-fA-F0-9]{40}}"
,
b
.
l1IndexingService
.
GetDeposits
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/withdrawal/0x{hash:[a-fA-F0-9]{64}}"
,
b
.
l2IndexingService
.
GetWithdrawalBatch
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/withdrawals/0x{address:[a-fA-F0-9]{40}}"
,
b
.
l2IndexingService
.
GetWithdrawals
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/withdrawals/0x{address:[a-fA-F0-9]{40}}"
,
b
.
l2IndexingService
.
GetWithdrawals
)
.
Methods
(
"GET"
)
b
.
router
.
HandleFunc
(
"/v1/airdrops/0x{address:[a-fA-F0-9]{40}}"
,
b
.
airdropService
.
GetAirdrop
)
b
.
router
.
HandleFunc
(
"/v1/airdrops/0x{address:[a-fA-F0-9]{40}}"
,
b
.
airdropService
.
GetAirdrop
)
b
.
router
.
HandleFunc
(
"/healthz"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
b
.
router
.
HandleFunc
(
"/healthz"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
indexer/metrics/metrics.go
View file @
ff7f2d3c
...
@@ -21,8 +21,6 @@ type Metrics struct {
...
@@ -21,8 +21,6 @@ type Metrics struct {
WithdrawalsCount
*
prometheus
.
CounterVec
WithdrawalsCount
*
prometheus
.
CounterVec
StateBatchesCount
prometheus
.
Counter
L1CatchingUp
prometheus
.
Gauge
L1CatchingUp
prometheus
.
Gauge
L2CatchingUp
prometheus
.
Gauge
L2CatchingUp
prometheus
.
Gauge
...
@@ -74,12 +72,6 @@ func NewMetrics(monitoredTokens map[string]string) *Metrics {
...
@@ -74,12 +72,6 @@ func NewMetrics(monitoredTokens map[string]string) *Metrics {
"symbol"
,
"symbol"
,
}),
}),
StateBatchesCount
:
promauto
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"state_batches_count"
,
Help
:
"The number of state batches indexed."
,
Namespace
:
metricsNamespace
,
}),
L1CatchingUp
:
promauto
.
NewGauge
(
prometheus
.
GaugeOpts
{
L1CatchingUp
:
promauto
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"l1_catching_up"
,
Name
:
"l1_catching_up"
,
Help
:
"Whether or not L1 is far behind the chain tip."
,
Help
:
"Whether or not L1 is far behind the chain tip."
,
...
@@ -168,10 +160,6 @@ func (m *Metrics) RecordWithdrawal(addr common.Address) {
...
@@ -168,10 +160,6 @@ func (m *Metrics) RecordWithdrawal(addr common.Address) {
m
.
WithdrawalsCount
.
WithLabelValues
(
sym
)
.
Inc
()
m
.
WithdrawalsCount
.
WithLabelValues
(
sym
)
.
Inc
()
}
}
func
(
m
*
Metrics
)
RecordStateBatches
(
count
int
)
{
m
.
StateBatchesCount
.
Add
(
float64
(
count
))
}
func
(
m
*
Metrics
)
SetL1CatchingUp
(
state
bool
)
{
func
(
m
*
Metrics
)
SetL1CatchingUp
(
state
bool
)
{
var
catchingUp
float64
var
catchingUp
float64
if
state
{
if
state
{
...
...
indexer/services/l2/service.go
View file @
ff7f2d3c
...
@@ -336,18 +336,6 @@ func (s *Service) GetIndexerStatus(w http.ResponseWriter, r *http.Request) {
...
@@ -336,18 +336,6 @@ func (s *Service) GetIndexerStatus(w http.ResponseWriter, r *http.Request) {
server
.
RespondWithJSON
(
w
,
http
.
StatusOK
,
status
)
server
.
RespondWithJSON
(
w
,
http
.
StatusOK
,
status
)
}
}
func
(
s
*
Service
)
GetWithdrawalBatch
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
batch
,
err
:=
s
.
cfg
.
DB
.
GetWithdrawalBatch
(
common
.
HexToHash
(
vars
[
"hash"
]))
if
err
!=
nil
{
server
.
RespondWithError
(
w
,
http
.
StatusInternalServerError
,
err
.
Error
())
return
}
server
.
RespondWithJSON
(
w
,
http
.
StatusOK
,
batch
)
}
func
(
s
*
Service
)
GetWithdrawals
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
s
*
Service
)
GetWithdrawals
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
vars
:=
mux
.
Vars
(
r
)
...
...
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