Skip to content

Commit 6e3b937

Browse files
committed
Revert "feat(cache and trace api): Add redis cache in database and add trace api in bridge.l2backend. (#228)"
This reverts commit b5549f6.
1 parent 63261c7 commit 6e3b937

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+241
-775
lines changed

bridge/config.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,7 @@
6161
}
6262
},
6363
"db_config": {
64-
"persistence": {
65-
"driver_name": "postgres",
66-
"dsn": "postgres://admin:123456@localhost/test?sslmode=disable"
67-
},
68-
"redis": {
69-
"url": "redis://default:@localhost:6379/0",
70-
"expirations": {
71-
"trace": 3600
72-
}
73-
}
64+
"driver_name": "postgres",
65+
"dsn": "postgres://admin:123456@localhost/test?sslmode=disable"
7466
}
7567
}

bridge/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/iden3/go-iden3-crypto v0.0.13
77
github.com/orcaman/concurrent-map v1.0.0
8-
github.com/scroll-tech/go-ethereum v1.10.14-0.20230113082126-cdaea939622e
8+
github.com/scroll-tech/go-ethereum v1.10.14-0.20230112091133-2891916a0f81
99
github.com/stretchr/testify v1.8.0
1010
github.com/urfave/cli/v2 v2.10.2
1111
golang.org/x/sync v0.1.0
@@ -14,7 +14,7 @@ require (
1414

1515
require (
1616
github.com/btcsuite/btcd v0.20.1-beta // indirect
17-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
17+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
1818
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
1919
github.com/davecgh/go-spew v1.1.1 // indirect
2020
github.com/deckarep/golang-set v1.8.0 // indirect

bridge/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
7373
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
7474
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
7575
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
76-
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
77-
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
76+
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
77+
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
7878
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
7979
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
8080
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -350,8 +350,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
350350
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
351351
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
352352
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
353-
github.com/scroll-tech/go-ethereum v1.10.14-0.20230113082126-cdaea939622e h1:TAqAeQiQI6b+TRyqyQ6qhizqY35LhqYe8lWhG0nNRGw=
354-
github.com/scroll-tech/go-ethereum v1.10.14-0.20230113082126-cdaea939622e/go.mod h1:jurIpDQ0hqtp9//xxeWzr8X9KMP/+TYn+vz3K1wZrv0=
353+
github.com/scroll-tech/go-ethereum v1.10.14-0.20230112091133-2891916a0f81 h1:Gm18RZ9WTR2Dupumr60E2m1Noe+l9/lITt6iRyxxZoc=
354+
github.com/scroll-tech/go-ethereum v1.10.14-0.20230112091133-2891916a0f81/go.mod h1:jurIpDQ0hqtp9//xxeWzr8X9KMP/+TYn+vz3K1wZrv0=
355355
github.com/scroll-tech/zktrie v0.3.0/go.mod h1:CuJFlG1/soTJJBAySxCZgTF7oPvd5qF6utHOEciC43Q=
356356
github.com/scroll-tech/zktrie v0.3.1 h1:HlR+fMBdjXX1/7cUMqpUgGEhGy/3vN1JpwQ0ovg/Ys8=
357357
github.com/scroll-tech/zktrie v0.3.1/go.mod h1:CuJFlG1/soTJJBAySxCZgTF7oPvd5qF6utHOEciC43Q=

bridge/l1/l1_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func setupEnv(t *testing.T) {
3737
cfg.L2Config.Endpoint = l2gethImg.Endpoint()
3838

3939
// Create db container.
40-
dbImg = docker.NewTestDBDocker(t, cfg.DBConfig.Persistence.DriverName)
41-
cfg.DBConfig.Persistence.DSN = dbImg.Endpoint()
40+
dbImg = docker.NewTestDBDocker(t, cfg.DBConfig.DriverName)
41+
cfg.DBConfig.DSN = dbImg.Endpoint()
4242
}
4343

4444
func free(t *testing.T) {

bridge/l1/watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (w *Watcher) Stop() {
116116

117117
const contractEventsBlocksFetchLimit = int64(10)
118118

119-
// FetchContractEvent pull latest event logs from given contract address and save in Persistence
119+
// FetchContractEvent pull latest event logs from given contract address and save in DB
120120
func (w *Watcher) FetchContractEvent(blockHeight uint64) error {
121121
defer func() {
122122
log.Info("l1 watcher fetchContractEvent", "w.processedMsgHeight", w.processedMsgHeight)

bridge/l2/backend.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ func New(ctx context.Context, cfg *config.L2Config, orm database.OrmFactory) (*B
3232
return nil, err
3333
}
3434

35-
l2Watcher, err := NewL2WatcherClient(ctx, client, cfg.Confirmations, cfg.BatchProposerConfig, cfg.L2MessengerAddress, orm)
36-
if err != nil {
37-
return nil, err
38-
}
35+
l2Watcher := NewL2WatcherClient(ctx, client, cfg.Confirmations, cfg.BatchProposerConfig, cfg.L2MessengerAddress, orm)
3936

4037
return &Backend{
4138
cfg: cfg,

bridge/l2/l2_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var (
1919
l1gethImg docker.ImgInstance
2020
l2gethImg docker.ImgInstance
2121
dbImg docker.ImgInstance
22-
redisImg docker.ImgInstance
2322

2423
// l2geth client
2524
l2Cli *ethclient.Client
@@ -41,12 +40,8 @@ func setupEnv(t *testing.T) (err error) {
4140
cfg.L2Config.Endpoint = l2gethImg.Endpoint()
4241

4342
// Create db container.
44-
dbImg = docker.NewTestDBDocker(t, cfg.DBConfig.Persistence.DriverName)
45-
cfg.DBConfig.Persistence.DSN = dbImg.Endpoint()
46-
47-
// Create redis container.
48-
redisImg = docker.NewTestRedisDocker(t)
49-
cfg.DBConfig.Redis.URL = redisImg.Endpoint()
43+
dbImg = docker.NewTestDBDocker(t, cfg.DBConfig.DriverName)
44+
cfg.DBConfig.DSN = dbImg.Endpoint()
5045

5146
// Create l2geth client.
5247
l2Cli, err = ethclient.Dial(cfg.L2Config.Endpoint)
@@ -65,9 +60,6 @@ func free(t *testing.T) {
6560
if l2gethImg != nil {
6661
assert.NoError(t, l2gethImg.Stop())
6762
}
68-
if redisImg != nil {
69-
assert.NoError(t, redisImg.Stop())
70-
}
7163
}
7264

7365
func TestFunction(t *testing.T) {

bridge/l2/watcher.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ type WatcherClient struct {
5959
}
6060

6161
// NewL2WatcherClient take a l2geth instance to generate a l2watcherclient instance
62-
func NewL2WatcherClient(ctx context.Context, client *ethclient.Client, confirmations uint64, bpCfg *config.BatchProposerConfig, messengerAddress common.Address, orm database.OrmFactory) (*WatcherClient, error) {
62+
func NewL2WatcherClient(ctx context.Context, client *ethclient.Client, confirmations uint64, bpCfg *config.BatchProposerConfig, messengerAddress common.Address, orm database.OrmFactory) *WatcherClient {
6363
savedHeight, err := orm.GetLayer2LatestWatchedHeight()
6464
if err != nil {
6565
log.Warn("fetch height from db failed", "err", err)
6666
savedHeight = 0
6767
}
6868

69-
watcher := &WatcherClient{
69+
return &WatcherClient{
7070
ctx: ctx,
7171
Client: client,
7272
orm: orm,
@@ -78,20 +78,13 @@ func NewL2WatcherClient(ctx context.Context, client *ethclient.Client, confirmat
7878
stopped: 0,
7979
batchProposer: newBatchProposer(bpCfg, orm),
8080
}
81-
// Init cache, if traces in cache expired reset it.
82-
if err = watcher.initCache(ctx); err != nil {
83-
log.Error("failed to init cache in l2 watcher")
84-
return nil, err
85-
}
86-
87-
return watcher, nil
8881
}
8982

9083
// Start the Listening process
9184
func (w *WatcherClient) Start() {
9285
go func() {
9386
if reflect.ValueOf(w.orm).IsNil() {
94-
panic("must run L2 watcher with Persistence")
87+
panic("must run L2 watcher with DB")
9588
}
9689

9790
ctx, cancel := context.WithCancel(w.ctx)
@@ -184,7 +177,7 @@ const blockTracesFetchLimit = uint64(10)
184177

185178
// try fetch missing blocks if inconsistent
186179
func (w *WatcherClient) tryFetchRunningMissingBlocks(ctx context.Context, blockHeight uint64) {
187-
// Get newest block in Persistence. must have blocks at that time.
180+
// Get newest block in DB. must have blocks at that time.
188181
// Don't use "block_trace" table "trace" column's BlockTrace.Number,
189182
// because it might be empty if the corresponding rollup_result is finalized/finalization_skipped
190183
heightInDB, err := w.orm.GetBlockTracesLatestHeight()
@@ -226,6 +219,7 @@ func (w *WatcherClient) getAndStoreBlockTraces(ctx context.Context, from, to uin
226219
log.Info("retrieved block trace", "height", trace.Header.Number, "hash", trace.Header.Hash().String())
227220

228221
traces = append(traces, trace)
222+
229223
}
230224
if len(traces) > 0 {
231225
if err := w.orm.InsertBlockTraces(traces); err != nil {
@@ -238,7 +232,7 @@ func (w *WatcherClient) getAndStoreBlockTraces(ctx context.Context, from, to uin
238232

239233
const contractEventsBlocksFetchLimit = int64(10)
240234

241-
// FetchContractEvent pull latest event logs from given contract address and save in Persistence
235+
// FetchContractEvent pull latest event logs from given contract address and save in DB
242236
func (w *WatcherClient) FetchContractEvent(blockHeight uint64) {
243237
defer func() {
244238
log.Info("l2 watcher fetchContractEvent", "w.processedMsgHeight", w.processedMsgHeight)

bridge/l2/watcher_api.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
package l2
22

3-
import (
4-
"context"
5-
6-
"github.com/scroll-tech/go-ethereum/core/types"
7-
)
8-
93
// WatcherAPI watcher api service
104
type WatcherAPI interface {
11-
GetTracesByBatchIndex(ctx context.Context, index uint64) ([]*types.BlockTrace, error)
12-
}
13-
14-
// GetTracesByBatchIndex get traces by batch_id.
15-
func (w *WatcherClient) GetTracesByBatchIndex(ctx context.Context, index uint64) ([]*types.BlockTrace, error) {
16-
id, err := w.orm.GetBatchIDByIndex(index)
17-
if err != nil {
18-
return nil, err
19-
}
20-
return w.orm.GetBlockTraces(map[string]interface{}{"batch_id": id})
215
}

bridge/l2/watcher_init.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)