Compare commits

...

6 Commits

Author SHA1 Message Date
ChuhanJin
8013ab8529 fix(bridge-history-api): fix GetLatestL2SentMsgBatchIndex return wrong column (#713) 2023-08-03 12:55:25 +08:00
Péter Garamvölgyi
f16a300d87 fix(batch): fix null pointer test failure (#709)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-08-03 05:09:48 +02:00
Péter Garamvölgyi
559ad6a5f1 fix: update l2geth test image genesis config (#711) 2023-08-03 10:51:04 +08:00
Péter Garamvölgyi
ab34ff0315 fix: make coordinator API tests more resilient and informative (#707)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-08-03 10:09:21 +08:00
ChuhanJin
d183125c59 feat(bridge-history-api): server add withdraw_root api service (#708)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-08-03 09:58:51 +08:00
Nazarii Denha
a36b4bb8ed fix: flaky api_test (#710) 2023-08-02 17:25:07 +02:00
15 changed files with 151 additions and 32 deletions

View File

@@ -53,6 +53,7 @@ func (m *MsgProofUpdater) Start() {
continue
}
latestBatchIndexWithProof, err := m.l2SentMsgOrm.GetLatestL2SentMsgBatchIndex(m.ctx)
log.Info("latest batc with proof", "batch_index", latestBatchIndexWithProof)
if err != nil {
log.Error("MsgProofUpdater: Can not get latest L2SentMsgBatchIndex: ", "err", err)
continue

View File

@@ -0,0 +1,37 @@
package controller
import (
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"bridge-history-api/internal/logic"
"bridge-history-api/internal/types"
)
// BatchController contains the query claimable txs service
type BatchController struct {
batchLogic *logic.BatchLogic
}
// NewBatchController return NewBatchController instance
func NewBatchController(db *gorm.DB) *BatchController {
return &BatchController{
batchLogic: logic.NewBatchLogic(db),
}
}
// GetWithdrawRootByBatchIndex defines the http get method behavior
func (b *BatchController) GetWithdrawRootByBatchIndex(ctx *gin.Context) {
var req types.QueryByBatchIndexRequest
if err := ctx.ShouldBind(&req); err != nil {
types.RenderJSON(ctx, types.ErrParameterInvalidNo, err, nil)
return
}
result, err := b.batchLogic.GetWithdrawRootByBatchIndex(ctx, req.BatchIndex)
if err != nil {
types.RenderJSON(ctx, types.ErrGetWithdrawRootByBatchIndexFailure, err, nil)
return
}
types.RenderJSON(ctx, types.Success, nil, result)
}

View File

@@ -8,7 +8,9 @@ import (
var (
// HistoryCtrler is controller instance
HistoryCtrler *HistoryController
HistoryCtrler *HistoryController
// BatchCtrler is controller instance
BatchCtrler *BatchController
initControllerOnce sync.Once
)
@@ -16,5 +18,6 @@ var (
func InitController(db *gorm.DB) {
initControllerOnce.Do(func() {
HistoryCtrler = NewHistoryController(db)
BatchCtrler = NewBatchController(db)
})
}

View File

@@ -0,0 +1,35 @@
package logic
import (
"context"
"github.com/ethereum/go-ethereum/log"
"gorm.io/gorm"
"bridge-history-api/orm"
)
// BatchLogic example service.
type BatchLogic struct {
rollupOrm *orm.RollupBatch
}
// NewBatchLogic returns services backed with a "db"
func NewBatchLogic(db *gorm.DB) *BatchLogic {
logic := &BatchLogic{rollupOrm: orm.NewRollupBatch(db)}
return logic
}
// GetWithdrawRootByBatchIndex get withdraw root by batch index from db
func (b *BatchLogic) GetWithdrawRootByBatchIndex(ctx context.Context, batchIndex uint64) (string, error) {
batch, err := b.rollupOrm.GetRollupBatchByIndex(ctx, batchIndex)
if err != nil {
log.Debug("getWithdrawRootByBatchIndex failed", "error", err)
return "", err
}
if batch == nil {
log.Debug("getWithdrawRootByBatchIndex failed", "error", "batch not found")
return "", nil
}
return batch.WithdrawRoot, nil
}

View File

@@ -23,4 +23,5 @@ func Route(router *gin.Engine, conf *config.Config) {
r.GET("/txs", controller.HistoryCtrler.GetAllTxsByAddr)
r.POST("/txsbyhashes", controller.HistoryCtrler.PostQueryTxsByHash)
r.GET("/claimable", controller.HistoryCtrler.GetAllClaimableTxsByAddr)
r.GET("/withdraw_root", controller.BatchCtrler.GetWithdrawRootByBatchIndex)
}

View File

@@ -18,6 +18,8 @@ const (
ErrGetTxsByHashFailure = 40003
// ErrGetTxsByAddrFailure is getting txs by address error
ErrGetTxsByAddrFailure = 40004
// ErrGetWithdrawRootByBatchIndexFailure is getting withdraw root by batch index error
ErrGetWithdrawRootByBatchIndexFailure = 40005
)
// QueryByAddressRequest the request parameter of address api
@@ -32,6 +34,12 @@ type QueryByHashRequest struct {
Txs []string `raw:"txs" binding:"required"`
}
// QueryByBatchIndexRequest the request parameter of batch index api
type QueryByBatchIndexRequest struct {
// BatchIndex can not be 0, because we dont decode the genesis block
BatchIndex uint64 `form:"batch_index" binding:"required"`
}
// ResultData contains return txs and total
type ResultData struct {
Result []*TxHistoryInfo `json:"result"`

View File

@@ -19,6 +19,7 @@ type RollupBatch struct {
CommitHeight uint64 `json:"commit_height" gorm:"column:commit_height"`
StartBlockNumber uint64 `json:"start_block_number" gorm:"column:start_block_number"`
EndBlockNumber uint64 `json:"end_block_number" gorm:"column:end_block_number"`
WithdrawRoot string `json:"withdraw_root" gorm:"column:withdraw_root;default:NULL"`
CreatedAt *time.Time `json:"created_at" gorm:"column:created_at"`
UpdatedAt *time.Time `json:"updated_at" gorm:"column:updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"column:deleted_at;default:NULL"`

View File

@@ -106,7 +106,7 @@ func (l *L2SentMsg) GetLatestL2SentMsgBatchIndex(ctx context.Context) (int64, er
return -1, fmt.Errorf("L2SentMsg.GetLatestL2SentMsgBatchIndex error: %w", err)
}
// Watch for overflow, tho its not likely to happen
return int64(result.Height), nil
return int64(result.BatchIndex), nil
}
// GetL2SentMsgMsgHashByHeightRange get l2 sent msg msg hash by height range

View File

@@ -266,8 +266,8 @@ func (r *Layer2Relayer) commitGenesisBatch(batchHash string, batchHeader []byte,
// ProcessGasPriceOracle imports gas price to layer1
func (r *Layer2Relayer) ProcessGasPriceOracle() {
batch, err := r.batchOrm.GetLatestBatch(r.ctx)
if err != nil {
log.Error("Failed to GetLatestBatch", "err", err)
if batch == nil || err != nil {
log.Error("Failed to GetLatestBatch", "batch", batch, "err", err)
return
}

View File

@@ -218,6 +218,7 @@ func TestBatchOrm(t *testing.T) {
updatedBatch, err := batchOrm.GetLatestBatch(context.Background())
assert.NoError(t, err)
assert.NotNil(t, updatedBatch)
assert.Equal(t, types.ProvingTaskVerified, types.ProvingStatus(updatedBatch.ProvingStatus))
assert.Equal(t, types.RollupFinalized, types.RollupStatus(updatedBatch.RollupStatus))
assert.Equal(t, types.GasOracleImported, types.GasOracleStatus(updatedBatch.OracleStatus))
@@ -227,6 +228,7 @@ func TestBatchOrm(t *testing.T) {
assert.NoError(t, err)
updatedBatch, err = batchOrm.GetLatestBatch(context.Background())
assert.NoError(t, err)
assert.NotNil(t, updatedBatch)
assert.Equal(t, "commitTxHash", updatedBatch.CommitTxHash)
assert.Equal(t, types.RollupCommitted, types.RollupStatus(updatedBatch.RollupStatus))
@@ -235,6 +237,7 @@ func TestBatchOrm(t *testing.T) {
updatedBatch, err = batchOrm.GetLatestBatch(context.Background())
assert.NoError(t, err)
assert.NotNil(t, updatedBatch)
assert.Equal(t, "finalizeTxHash", updatedBatch.FinalizeTxHash)
assert.Equal(t, types.RollupFinalizeFailed, types.RollupStatus(updatedBatch.RollupStatus))
}

View File

@@ -95,6 +95,7 @@ func testImportL2GasPrice(t *testing.T) {
// check db status
batch, err := batchOrm.GetLatestBatch(context.Background())
assert.NoError(t, err)
assert.NotNil(t, batch)
assert.Empty(t, batch.OracleTxHash)
assert.Equal(t, types.GasOracleStatus(batch.OracleStatus), types.GasOraclePending)
@@ -102,6 +103,7 @@ func testImportL2GasPrice(t *testing.T) {
l2Relayer.ProcessGasPriceOracle()
batch, err = batchOrm.GetLatestBatch(context.Background())
assert.NoError(t, err)
assert.NotNil(t, batch)
assert.NotEmpty(t, batch.OracleTxHash)
assert.Equal(t, types.GasOracleStatus(batch.OracleStatus), types.GasOracleImporting)
}

View File

@@ -84,6 +84,7 @@ func testCommitBatchAndFinalizeBatch(t *testing.T) {
batchOrm := orm.NewBatch(db)
batch, err := batchOrm.GetLatestBatch(context.Background())
assert.NoError(t, err)
assert.NotNil(t, batch)
batchHash := batch.Hash
assert.NotEmpty(t, batch.CommitTxHash)
assert.Equal(t, types.RollupCommitting, types.RollupStatus(batch.RollupStatus))
@@ -122,6 +123,7 @@ func testCommitBatchAndFinalizeBatch(t *testing.T) {
batch, err = batchOrm.GetLatestBatch(context.Background())
assert.NoError(t, err)
assert.NotNil(t, batch)
assert.NotEmpty(t, batch.FinalizeTxHash)
finalizeTx, _, err := l1Client.TransactionByHash(context.Background(), common.HexToHash(batch.FinalizeTxHash))

View File

@@ -12,6 +12,8 @@
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"archimedesBlock": 0,
"shanghaiBlock": 0,
"clique": {
"period": 3,
"epoch": 30000
@@ -19,6 +21,7 @@
"scroll": {
"useZktrie": true,
"maxTxPerBlock": 44,
"maxTxPayloadBytesPerBlock": 122880,
"feeVaultAddress": "0x5300000000000000000000000000000000000005",
"enableEIP2718": false,
"enableEIP1559": false

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "v4.0.39"
var tag = "v4.0.41"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {

View File

@@ -79,7 +79,7 @@ func setupCoordinator(t *testing.T, proversPerSession uint8, wsURL string, reset
CollectionTime: 1,
TokenTimeToLive: 5,
MaxVerifierWorkers: 10,
SessionAttempts: 2,
SessionAttempts: 3,
},
}
proofCollector := cron.NewCollector(context.Background(), db, &conf)
@@ -322,21 +322,25 @@ func testValidProof(t *testing.T) {
// verify proof status
var (
tick = time.Tick(500 * time.Millisecond)
tick = time.Tick(1500 * time.Millisecond)
tickStop = time.Tick(time.Minute)
)
var chunkProofStatus types.ProvingStatus
var batchProofStatus types.ProvingStatus
for {
select {
case <-tick:
chunkProofStatus, err := chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
chunkProofStatus, err = chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
assert.NoError(t, err)
batchProofStatus, err := batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
batchProofStatus, err = batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
assert.NoError(t, err)
if chunkProofStatus == types.ProvingTaskVerified && batchProofStatus == types.ProvingTaskVerified {
return
}
case <-tickStop:
t.Error("failed to check proof status")
t.Error("failed to check proof status", "chunkProofStatus", chunkProofStatus.String(), "batchProofStatus", batchProofStatus.String())
return
}
}
@@ -383,21 +387,25 @@ func testInvalidProof(t *testing.T) {
// verify proof status
var (
tick = time.Tick(500 * time.Millisecond)
tick = time.Tick(1500 * time.Millisecond)
tickStop = time.Tick(time.Minute)
)
var chunkProofStatus types.ProvingStatus
var batchProofStatus types.ProvingStatus
for {
select {
case <-tick:
chunkProofStatus, err := chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
chunkProofStatus, err = chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
assert.NoError(t, err)
batchProofStatus, err := batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
batchProofStatus, err = batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
assert.NoError(t, err)
if chunkProofStatus == types.ProvingTaskFailed && batchProofStatus == types.ProvingTaskFailed {
return
}
case <-tickStop:
t.Error("failed to check proof status")
t.Error("failed to check proof status", "chunkProofStatus", chunkProofStatus.String(), "batchProofStatus", batchProofStatus.String())
return
}
}
@@ -444,21 +452,25 @@ func testProofGeneratedFailed(t *testing.T) {
// verify proof status
var (
tick = time.Tick(500 * time.Millisecond)
tick = time.Tick(1500 * time.Millisecond)
tickStop = time.Tick(time.Minute)
)
var chunkProofStatus types.ProvingStatus
var batchProofStatus types.ProvingStatus
for {
select {
case <-tick:
chunkProofStatus, err := chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
chunkProofStatus, err = chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
assert.NoError(t, err)
batchProofStatus, err := batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
batchProofStatus, err = batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
assert.NoError(t, err)
if chunkProofStatus == types.ProvingTaskFailed && batchProofStatus == types.ProvingTaskFailed {
return
}
case <-tickStop:
t.Error("failed to check proof status")
t.Error("failed to check proof status", "chunkProofStatus", chunkProofStatus.String(), "batchProofStatus", batchProofStatus.String())
return
}
}
@@ -494,18 +506,21 @@ func testTimeoutProof(t *testing.T) {
assert.NoError(t, err)
// verify proof status, it should be assigned, because prover didn't send any proof
var chunkProofStatus types.ProvingStatus
var batchProofStatus types.ProvingStatus
ok := utils.TryTimes(30, func() bool {
chunkProofStatus, err := chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
chunkProofStatus, err = chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
if err != nil {
return false
}
batchProofStatus, err := batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
batchProofStatus, err = batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
if err != nil {
return false
}
return chunkProofStatus == types.ProvingTaskAssigned && batchProofStatus == types.ProvingTaskAssigned
})
assert.Falsef(t, !ok, "failed to check proof status")
assert.Falsef(t, !ok, "failed to check proof status", "chunkProofStatus", chunkProofStatus.String(), "batchProofStatus", batchProofStatus.String())
// create second mock prover, that will send valid proof.
chunkProver2 := newMockProver(t, "prover_test"+strconv.Itoa(2), wsURL, message.ProofTypeChunk)
@@ -522,17 +537,17 @@ func testTimeoutProof(t *testing.T) {
// verify proof status, it should be verified now, because second prover sent valid proof
ok = utils.TryTimes(200, func() bool {
chunkProofStatus, err := chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
chunkProofStatus, err = chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
if err != nil {
return false
}
batchProofStatus, err := batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
batchProofStatus, err = batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
if err != nil {
return false
}
return chunkProofStatus == types.ProvingTaskVerified && batchProofStatus == types.ProvingTaskVerified
})
assert.Falsef(t, !ok, "failed to check proof status")
assert.Falsef(t, !ok, "failed to check proof status", "chunkProofStatus", chunkProofStatus.String(), "batchProofStatus", batchProofStatus.String())
}
func testIdleProverSelection(t *testing.T) {
@@ -577,21 +592,25 @@ func testIdleProverSelection(t *testing.T) {
// verify proof status
var (
tick = time.Tick(500 * time.Millisecond)
tick = time.Tick(1500 * time.Millisecond)
tickStop = time.Tick(10 * time.Second)
)
var chunkProofStatus types.ProvingStatus
var batchProofStatus types.ProvingStatus
for {
select {
case <-tick:
chunkProofStatus, err := chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
chunkProofStatus, err = chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
assert.NoError(t, err)
batchProofStatus, err := batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
batchProofStatus, err = batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
assert.NoError(t, err)
if chunkProofStatus == types.ProvingTaskVerified && batchProofStatus == types.ProvingTaskVerified {
return
}
case <-tickStop:
t.Error("failed to check proof status")
t.Error("failed to check proof status", "chunkProofStatus", chunkProofStatus.String(), "batchProofStatus", batchProofStatus.String())
return
}
}
@@ -657,23 +676,27 @@ func testGracefulRestart(t *testing.T) {
// verify proof status
var (
tick = time.Tick(500 * time.Millisecond)
tick = time.Tick(1500 * time.Millisecond)
tickStop = time.Tick(15 * time.Second)
)
var chunkProofStatus types.ProvingStatus
var batchProofStatus types.ProvingStatus
for {
select {
case <-tick:
// this proves that the prover submits to the new coordinator,
// because the prover client for `submitProof` has been overwritten
chunkProofStatus, err := chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
chunkProofStatus, err = chunkOrm.GetProvingStatusByHash(context.Background(), dbChunk.Hash)
assert.NoError(t, err)
batchProofStatus, err := batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
batchProofStatus, err = batchOrm.GetProvingStatusByHash(context.Background(), batch.Hash)
assert.NoError(t, err)
if chunkProofStatus == types.ProvingTaskVerified && batchProofStatus == types.ProvingTaskVerified {
return
}
case <-tickStop:
t.Error("failed to check proof status")
t.Error("failed to check proof status", "chunkProofStatus", chunkProofStatus.String(), "batchProofStatus", batchProofStatus.String())
return
}
}