mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
Upgrade check logic.
This commit is contained in:
@@ -79,19 +79,21 @@ func (r *Layer1Relayer) checkSubmittedMessages() error {
|
||||
BEGIN:
|
||||
msgs, err := r.db.GetL1Messages(
|
||||
map[string]interface{}{"status": orm.MsgSubmitted},
|
||||
fmt.Sprintf("AND height<=%d", blockNumber),
|
||||
fmt.Sprintf("AND height < %d", blockNumber),
|
||||
fmt.Sprintf("ORDER BY height DESC LIMIT %d", 100),
|
||||
)
|
||||
if err != nil || len(msgs) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, msg := range msgs {
|
||||
// TODO: messageSender can't receive txs any more, sleep a while or just return?
|
||||
for msg := msgs[0]; len(msgs) > 0; {
|
||||
// If pending txs pool is full, wait a while and retry.
|
||||
if r.sender.IsFull() {
|
||||
log.Error("layer1 submitted tx sender is full")
|
||||
return nil
|
||||
log.Warn("layer1 submitted tx sender is full")
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
continue
|
||||
}
|
||||
msg, msgs = msgs[0], msgs[1:]
|
||||
|
||||
blockNumber = mathutil.MinUint64(blockNumber, msg.Height)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/common/math"
|
||||
@@ -21,19 +22,21 @@ func (r *Layer2Relayer) checkCommittingBatches() error {
|
||||
BEGIN:
|
||||
batches, err := r.db.GetBlockBatches(
|
||||
map[string]interface{}{"rollup_status": orm.RollupCommitting},
|
||||
fmt.Sprintf("AND end_block_number <= %d", blockNumber),
|
||||
fmt.Sprintf("AND end_block_number < %d", blockNumber),
|
||||
fmt.Sprintf("ORDER BY end_block_number DESC LIMIT %d", 10),
|
||||
)
|
||||
if err != nil || len(batches) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, batch := range batches {
|
||||
// TODO: messageSender can't receive txs any more, sleep a while or just return?
|
||||
for batch := batches[0]; len(batches) > 0; {
|
||||
// If pending txs pool is full, wait a while and retry.
|
||||
if r.rollupSender.IsFull() {
|
||||
log.Error("layer2 committed tx sender is full")
|
||||
return nil
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
continue
|
||||
}
|
||||
batch, batches = batches[0], batches[1:]
|
||||
|
||||
id := batch.ID
|
||||
blockNumber = mathutil.MinUint64(blockNumber, batch.EndBlockNumber)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
@@ -25,19 +26,21 @@ func (r *Layer2Relayer) checkFinalizingBatches() error {
|
||||
BEGIN:
|
||||
batches, err := r.db.GetBlockBatches(
|
||||
map[string]interface{}{"rollup_status": orm.RollupFinalizing},
|
||||
fmt.Sprintf("AND end_block_number <= %d", blockNumber),
|
||||
fmt.Sprintf("AND end_block_number < %d", blockNumber),
|
||||
fmt.Sprintf("ORDER BY end_block_number DESC LIMIT %d", batch),
|
||||
)
|
||||
if err != nil || len(batches) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, batch := range batches {
|
||||
// TODO: messageSender can't receive txs any more, sleep a while or just return?
|
||||
for batch := batches[0]; len(batches) > 0; {
|
||||
// If pending txs pool is full, wait a while and retry.
|
||||
if r.rollupSender.IsFull() {
|
||||
log.Error("layer2 finalized tx sender is full")
|
||||
return nil
|
||||
log.Warn("layer2 finalized tx sender is full")
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
continue
|
||||
}
|
||||
batch, batches = batches[0], batches[1:]
|
||||
|
||||
id := batch.ID
|
||||
blockNumber = mathutil.MinUint64(blockNumber, batch.EndBlockNumber)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
@@ -34,19 +35,21 @@ BEGIN:
|
||||
// msgs are sorted by nonce in increasing order
|
||||
msgs, err := r.db.GetL2Messages(
|
||||
map[string]interface{}{"status": orm.MsgSubmitted},
|
||||
fmt.Sprintf("AND height<=%d", blockNumber),
|
||||
fmt.Sprintf("AND height < %d", blockNumber),
|
||||
fmt.Sprintf("ORDER BY height DESC LIMIT %d", r.messageSender.PendingLimit()),
|
||||
)
|
||||
if err != nil || len(msgs) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, msg := range msgs {
|
||||
// TODO: messageSender can't receive txs any more, sleep a while or just return?
|
||||
for msg := msgs[0]; len(msgs) > 0; {
|
||||
// If pending txs pool is full, wait a while and retry.
|
||||
if r.messageSender.IsFull() {
|
||||
log.Error("layer2 message tx sender is full")
|
||||
return nil
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
continue
|
||||
}
|
||||
msg, msgs = msgs[0], msgs[1:]
|
||||
|
||||
blockNumber = mathutil.MinUint64(blockNumber, msg.Height)
|
||||
data, err := r.messagePack(msg, batch.Index)
|
||||
|
||||
@@ -93,7 +93,7 @@ func (m *l1MessageOrm) GetL1ProcessedNonce() (int64, error) {
|
||||
func (m *l1MessageOrm) GetL1Messages(fields map[string]interface{}, args ...string) ([]*L1Message, error) {
|
||||
query := "SELECT nonce, msg_hash, height, sender, target, value, fee, gas_limit, deadline, calldata, layer1_hash, layer2_hash, status FROM l2_message WHERE 1 = 1 "
|
||||
for key := range fields {
|
||||
query += fmt.Sprintf("AND %s=:%s ", key, key)
|
||||
query += fmt.Sprintf(" AND %s=:%s ", key, key)
|
||||
}
|
||||
query = strings.Join(append([]string{query}, args...), " ")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user