Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new bridge history apis #1024

Merged
merged 63 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f011fd5
feat: new bridge-history apis
colinlyguo Nov 16, 2023
bdbddc3
update go mod
colinlyguo Dec 6, 2023
0803dd9
refactor
colinlyguo Dec 6, 2023
e79900e
refactor
colinlyguo Dec 6, 2023
5902bee
fix
colinlyguo Dec 6, 2023
7629f06
change config default value
colinlyguo Dec 6, 2023
299f5e4
change Makefile
colinlyguo Dec 6, 2023
a6c72a2
fix
colinlyguo Dec 6, 2023
9bfefa0
update l1 start block height to first queue event
colinlyguo Dec 6, 2023
f031c38
Apply suggestions from code review
colinlyguo Dec 6, 2023
5936cd6
fixes
colinlyguo Dec 6, 2023
5622f8f
tweak
colinlyguo Dec 7, 2023
59c8470
fix batch index update
colinlyguo Dec 7, 2023
01d35d7
add fetching reverted relayed messages and fixes
colinlyguo Dec 7, 2023
a75813e
add PageSize limit
colinlyguo Dec 7, 2023
8587116
Update bridge-history-api/internal/config/config.go
colinlyguo Dec 7, 2023
cc5fd77
tweak
colinlyguo Dec 7, 2023
2f1abc0
address comments of new bridge history api (#1027)
colinlyguo Dec 8, 2023
3676368
fix: avoid duplicated batch updates (#1029)
colinlyguo Dec 11, 2023
7f5c823
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 11, 2023
c4c68ef
chore: auto version bump [bot]
colinlyguo Dec 11, 2023
bee9489
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 11, 2023
3a090ee
chore: auto version bump [bot]
colinlyguo Dec 11, 2023
faec5a5
trigger ci
colinlyguo Dec 11, 2023
e00d5a9
fix bugs
colinlyguo Dec 12, 2023
f11ce33
perf(bridge-history-api): add db indices and concurrent blocks fetchi…
colinlyguo Dec 12, 2023
cd883a3
add batch sync height in db
colinlyguo Dec 12, 2023
ebf7a46
remove useless logs
colinlyguo Dec 13, 2023
1d358fa
tweak logs
colinlyguo Dec 13, 2023
b534aed
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 13, 2023
9b5a7f7
fix go mod tidy
colinlyguo Dec 13, 2023
0da1355
tweak Makefile
colinlyguo Dec 13, 2023
7fe751f
fix ERROR: ON CONFLICT DO UPDATE command cannot affect row a second t…
colinlyguo Dec 13, 2023
04006b3
update message_type in relayed messages
colinlyguo Dec 13, 2023
3f9e500
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 13, 2023
420c96d
go mod tidy
colinlyguo Dec 13, 2023
1075d7d
chore: auto version bump [bot]
colinlyguo Dec 13, 2023
fef9f83
go mod tidy
colinlyguo Dec 13, 2023
bb1a7f6
add 0x prefix in merkle proof
colinlyguo Dec 13, 2023
5c1de26
split relayed failed to failed relayed and relayed tx reverted
colinlyguo Dec 13, 2023
33ec1e1
add withdraw root check
colinlyguo Dec 13, 2023
2f7e329
fix duplicated update reverted txs
colinlyguo Dec 14, 2023
7011c3e
feat: update some layer logic (#1050)
georgehao Dec 14, 2023
9484c1c
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 14, 2023
8d034de
feat: tweak some code (#1052)
georgehao Dec 15, 2023
a5ca547
bug fixes
colinlyguo Dec 16, 2023
5e2fe45
change start height
colinlyguo Dec 16, 2023
91d9926
fix a bug
colinlyguo Dec 17, 2023
ec6e618
fix another bug
colinlyguo Dec 17, 2023
fae11cc
add a case
colinlyguo Dec 17, 2023
60a4cde
add a clarify comment
colinlyguo Dec 17, 2023
3fc6534
add a comment
colinlyguo Dec 17, 2023
16d82f5
fix comment
colinlyguo Dec 17, 2023
e596a38
change some withdraw trie functions internal
colinlyguo Dec 17, 2023
8ee4dd8
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 18, 2023
7ddd1b7
fix a comment
colinlyguo Dec 18, 2023
842e256
fix a bug
colinlyguo Dec 18, 2023
6526878
filter L1 sentMessage in QueueTransaction
colinlyguo Dec 18, 2023
57e4987
feat(bridge-history-api): reorg handling (#1055)
colinlyguo Dec 19, 2023
dc1c18c
feat(bridge-history-api): add metrics (#1056)
colinlyguo Dec 22, 2023
bcd9489
refactor(bridge-history-api): rename some variables (#1057)
colinlyguo Dec 22, 2023
cad9e2b
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 22, 2023
3aa2c90
Merge branch 'develop' into fix-bridge-history-api-write-db
colinlyguo Dec 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bridge-history-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ test:
bridgehistoryapi-db-cli:
go build -o $(PWD)/build/bin/bridgehistoryapi-db-cli ./cmd/db_cli

bridgehistoryapi-cross-msg-fetcher:
go build -o $(PWD)/build/bin/bridgehistoryapi-cross-msg-fetcher ./cmd/cross_msg_fetcher
bridgehistoryapi-fetcher:
go build -o $(PWD)/build/bin/bridgehistoryapi-fetcher ./cmd/fetcher

bridgehistoryapi-server:
go build -o $(PWD)/build/bin/bridgehistoryapi-server ./cmd/backend_server
bridgehistoryapi-api:
go build -o $(PWD)/build/bin/bridgehistoryapi-api ./cmd/api

db-docker:
docker run --name bridgehistoryapi-history-db -p 5444:5432 -e POSTGRES_PASSWORD=123456 -e POSTGRES_DB=test -d postgres

bridgehistoryapi-docker:
DOCKER_BUILDKIT=1 docker build -t scrolltech/bridgehistoryapi-cross-msg-fetcher:${IMAGE_VERSION} ${REPO_ROOT_DIR}/ -f ${REPO_ROOT_DIR}/build/dockerfiles/bridgehistoryapi-cross-msg-fetcher.Dockerfile
DOCKER_BUILDKIT=1 docker build -t scrolltech/bridgehistoryapi-cross-message-fetcher:${IMAGE_VERSION} ${REPO_ROOT_DIR}/ -f ${REPO_ROOT_DIR}/build/dockerfiles/bridgehistoryapi-cross-message-fetcher.Dockerfile
DOCKER_BUILDKIT=1 docker build -t scrolltech/bridgehistoryapi-server:${IMAGE_VERSION} ${REPO_ROOT_DIR}/ -f ${REPO_ROOT_DIR}/build/dockerfiles/bridgehistoryapi-server.Dockerfile
DOCKER_BUILDKIT=1 docker build -t scrolltech/bridgehistoryapi-db-cli:${IMAGE_VERSION} ${REPO_ROOT_DIR}/ -f ${REPO_ROOT_DIR}/build/dockerfiles/bridgehistoryapi-db-cli.Dockerfile
30 changes: 16 additions & 14 deletions bridge-history-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Provide init, show version, rollback, check status services of DB

### bridgehistoryapi-cross-msg-fetcher

Fetch the transactions from both l1 and l2
Fetch the transactions from both L1 and L2
```
cd ./bridge-history-api
make bridgehistoryapi-cross-msg-fetcher
Expand Down Expand Up @@ -49,34 +49,36 @@ can change this port thru modify `config.json`
// @Router /api/txs [get]
```

2. `/txsbyhashes`
2. `/withdrawals`
```
// @Summary get txs by given tx hashes
// @Summary get all L2 withdrawals under given address
// @Accept plain
// @Produce plain
// @Param hashes query string array true "array of hashes list"
// @Success 200
// @Router /api/txsbyhashes [post]
// @Param address query string true "wallet address"
// @Param page_size query int true "page size"
// @Param page query int true "page"
// @Success 200
// @Router /api/withdrawals [get]
```

3. `/claimable`
3. `/claimablewithdrawals`
```
// @Summary get all claimable txs under given address
// @Summary get all L2 claimable withdrawals under given address
// @Accept plain
// @Produce plain
// @Param address query string true "wallet address"
// @Param page_size query int true "page size"
// @Param page query int true "page"
// @Success 200
// @Router /api/claimable [get]
// @Router /api/claimablewithdrawals [get]
```

4. `/withdraw_root`
4. `/txsbyhashes`
```
// @Summary get withdraw_root of given batch index
// @Summary get txs by given tx hashes
// @Accept plain
// @Produce plain
// @Param batch_index query string true "batch_index"
// @Param hashes query string array true "array of hashes"
// @Success 200
// @Router /api/withdraw_root [get]
```
// @Router /api/txsbyhashes [post]
```
379 changes: 131 additions & 248 deletions bridge-history-api/abi/backend_abi.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (
"os"
"os/signal"

"github.com/ethereum/go-ethereum/log"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
"github.com/prometheus/client_golang/prometheus"
"github.com/scroll-tech/go-ethereum/log"
"github.com/urfave/cli/v2"

"bridge-history-api/config"
"bridge-history-api/internal/controller"
"bridge-history-api/internal/route"
"bridge-history-api/observability"
"bridge-history-api/utils"
"scroll-tech/bridge-history-api/internal/config"
"scroll-tech/bridge-history-api/internal/controller/api"
"scroll-tech/bridge-history-api/internal/route"
"scroll-tech/common/database"
"scroll-tech/common/observability"
"scroll-tech/common/utils"
)

var (
Expand Down Expand Up @@ -42,25 +44,28 @@ func action(ctx *cli.Context) error {
if err != nil {
log.Crit("failed to load config file", "config file", cfgFile, "error", err)
}
db, err := utils.InitDB(cfg.DB)
db, err := database.InitDB(cfg.DB)
if err != nil {
log.Crit("failed to init db", "err", err)
}
defer func() {
if deferErr := utils.CloseDB(db); deferErr != nil {
if deferErr := database.CloseDB(db); deferErr != nil {
log.Error("failed to close db", "err", err)
}
}()
// init Prover Stats API
port := cfg.Server.HostPort
redis := redis.NewClient(&redis.Options{
Addr: cfg.Redis.Address,
Password: cfg.Redis.Password,
DB: cfg.Redis.DB,
})
api.InitController(db, redis)

router := gin.Default()
controller.InitController(db)

registry := prometheus.DefaultRegisterer
route.Route(router, cfg, registry)

go func() {
port := cfg.Server.HostPort
if runServerErr := router.Run(fmt.Sprintf(":%s", port)); runServerErr != nil {
log.Crit("run http server failure", "error", runServerErr)
}
Expand Down
7 changes: 7 additions & 0 deletions bridge-history-api/cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "scroll-tech/bridge-history-api/cmd/api/app"

func main() {
app.Run()
}
7 changes: 0 additions & 7 deletions bridge-history-api/cmd/backend_server/main.go

This file was deleted.

168 changes: 0 additions & 168 deletions bridge-history-api/cmd/cross_msg_fetcher/app/app.go

This file was deleted.

7 changes: 0 additions & 7 deletions bridge-history-api/cmd/cross_msg_fetcher/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion bridge-history-api/cmd/db_cli/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/urfave/cli/v2"

"bridge-history-api/utils"
"scroll-tech/common/utils"
)

var (
Expand Down
13 changes: 7 additions & 6 deletions bridge-history-api/cmd/db_cli/app/client.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app

import (
"github.com/ethereum/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/log"
"github.com/urfave/cli/v2"
"gorm.io/gorm"

"bridge-history-api/config"
"bridge-history-api/orm/migrate"
"bridge-history-api/utils"
"scroll-tech/bridge-history-api/internal/config"
"scroll-tech/bridge-history-api/internal/orm/migrate"
"scroll-tech/common/database"
"scroll-tech/common/utils"
)

func getConfig(ctx *cli.Context) (*config.Config, error) {
Expand All @@ -19,8 +20,8 @@ func getConfig(ctx *cli.Context) (*config.Config, error) {
return dbCfg, nil
}

func initDB(dbCfg *config.DBConfig) (*gorm.DB, error) {
return utils.InitDB(dbCfg)
func initDB(dbCfg *database.Config) (*gorm.DB, error) {
return database.InitDB(dbCfg)
}

// resetDB clean or reset database.
Expand Down
2 changes: 1 addition & 1 deletion bridge-history-api/cmd/db_cli/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "bridge-history-api/cmd/db_cli/app"
import "scroll-tech/bridge-history-api/cmd/db_cli/app"

func main() {
app.Run()
Expand Down
Loading