mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-12 23:48:15 -05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97dded9619 | ||
|
|
f48762bf33 | ||
|
|
42190feb6c | ||
|
|
56080204c5 | ||
|
|
2674dfaf69 | ||
|
|
5bffb151a3 | ||
|
|
fadaec7add |
@@ -113,7 +113,7 @@ func (r *Layer1Relayer) processSavedEvent(msg *orm.L1Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
hash, err := r.sender.SendTransaction(msg.MsgHash, &r.cfg.MessengerContractAddress, big.NewInt(0), data)
|
hash, err := r.sender.SendTransaction(msg.MsgHash, &r.cfg.MessengerContractAddress, big.NewInt(0), data, 0)
|
||||||
if err != nil && err.Error() == "execution reverted: Message expired" {
|
if err != nil && err.Error() == "execution reverted: Message expired" {
|
||||||
return r.db.UpdateLayer1Status(r.ctx, msg.MsgHash, orm.MsgExpired)
|
return r.db.UpdateLayer1Status(r.ctx, msg.MsgHash, orm.MsgExpired)
|
||||||
}
|
}
|
||||||
@@ -134,6 +134,8 @@ func (r *Layer1Relayer) processSavedEvent(msg *orm.L1Message) error {
|
|||||||
|
|
||||||
// Start the relayer process
|
// Start the relayer process
|
||||||
func (r *Layer1Relayer) Start() {
|
func (r *Layer1Relayer) Start() {
|
||||||
|
log.Info("Starting l1/relayer")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// trigger by timer
|
// trigger by timer
|
||||||
ticker := time.NewTicker(3 * time.Second)
|
ticker := time.NewTicker(3 * time.Second)
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ func NewWatcher(ctx context.Context, client *ethclient.Client, startHeight uint6
|
|||||||
|
|
||||||
// Start the Watcher module.
|
// Start the Watcher module.
|
||||||
func (w *Watcher) Start() {
|
func (w *Watcher) Start() {
|
||||||
|
log.Info("Starting l1/watcher")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ func (r *Layer2Relayer) processSavedEvent(msg *orm.L2Message, index uint64) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
hash, err := r.messageSender.SendTransaction(msg.MsgHash, &r.cfg.MessengerContractAddress, big.NewInt(0), data)
|
hash, err := r.messageSender.SendTransaction(msg.MsgHash, &r.cfg.MessengerContractAddress, big.NewInt(0), data, 0)
|
||||||
if err != nil && err.Error() == "execution reverted: Message expired" {
|
if err != nil && err.Error() == "execution reverted: Message expired" {
|
||||||
return r.db.UpdateLayer2Status(r.ctx, msg.MsgHash, orm.MsgExpired)
|
return r.db.UpdateLayer2Status(r.ctx, msg.MsgHash, orm.MsgExpired)
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,26 @@ func (r *Layer2Relayer) ProcessPendingBatches(wg *sync.WaitGroup) {
|
|||||||
|
|
||||||
txID := id + "-commit"
|
txID := id + "-commit"
|
||||||
// add suffix `-commit` to avoid duplication with finalize tx in unit tests
|
// add suffix `-commit` to avoid duplication with finalize tx in unit tests
|
||||||
hash, err := r.rollupSender.SendTransaction(txID, &r.cfg.RollupContractAddress, big.NewInt(0), data)
|
hash, err := r.rollupSender.SendTransaction(txID, &r.cfg.RollupContractAddress, big.NewInt(0), data, 0)
|
||||||
|
|
||||||
|
if err != nil && err.Error() == "execution reverted: Parent batch hasn't been committed" {
|
||||||
|
|
||||||
|
// check parent is committing
|
||||||
|
batches, err = r.db.GetBlockBatches(map[string]interface{}{"end_block_hash": batch.ParentHash})
|
||||||
|
if err != nil || len(batches) == 0 {
|
||||||
|
log.Error("Failed to get parent batch from db", "batch_id", id, "parent_hash", batch.ParentHash, "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parentBatch := batches[0]
|
||||||
|
|
||||||
|
if parentBatch.RollupStatus >= orm.RollupCommitting {
|
||||||
|
// retry with manual gas estimation
|
||||||
|
gasLimit := estimateCommitBatchGas(len(data), len(layer2Batch.Blocks))
|
||||||
|
hash, err = r.rollupSender.SendTransaction(txID, &r.cfg.RollupContractAddress, big.NewInt(0), data, gasLimit)
|
||||||
|
log.Info("commitBatch tx resent with manual gas estimation ", "id", id, "index", batch.Index, "gasLimit", gasLimit, "hash", hash.String(), "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, sender.ErrNoAvailableAccount) {
|
if !errors.Is(err, sender.ErrNoAvailableAccount) {
|
||||||
log.Error("Failed to send commitBatch tx to layer1 ", "id", id, "index", batch.Index, "err", err)
|
log.Error("Failed to send commitBatch tx to layer1 ", "id", id, "index", batch.Index, "err", err)
|
||||||
@@ -375,7 +394,7 @@ func (r *Layer2Relayer) ProcessCommittedBatches(wg *sync.WaitGroup) {
|
|||||||
|
|
||||||
txID := id + "-finalize"
|
txID := id + "-finalize"
|
||||||
// add suffix `-finalize` to avoid duplication with commit tx in unit tests
|
// add suffix `-finalize` to avoid duplication with commit tx in unit tests
|
||||||
txHash, err := r.rollupSender.SendTransaction(txID, &r.cfg.RollupContractAddress, big.NewInt(0), data)
|
txHash, err := r.rollupSender.SendTransaction(txID, &r.cfg.RollupContractAddress, big.NewInt(0), data, 0)
|
||||||
hash := &txHash
|
hash := &txHash
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, sender.ErrNoAvailableAccount) {
|
if !errors.Is(err, sender.ErrNoAvailableAccount) {
|
||||||
@@ -402,6 +421,8 @@ func (r *Layer2Relayer) ProcessCommittedBatches(wg *sync.WaitGroup) {
|
|||||||
|
|
||||||
// Start the relayer process
|
// Start the relayer process
|
||||||
func (r *Layer2Relayer) Start() {
|
func (r *Layer2Relayer) Start() {
|
||||||
|
log.Info("Starting l2/relayer")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// trigger by timer
|
// trigger by timer
|
||||||
ticker := time.NewTicker(time.Second)
|
ticker := time.NewTicker(time.Second)
|
||||||
@@ -473,3 +494,12 @@ func (r *Layer2Relayer) handleConfirmation(confirmation *sender.Confirmation) {
|
|||||||
}
|
}
|
||||||
log.Info("transaction confirmed in layer1", "type", transactionType, "confirmation", confirmation)
|
log.Info("transaction confirmed in layer1", "type", transactionType, "confirmation", confirmation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func estimateCommitBatchGas(callDataLength int, numBlocks int) uint64 {
|
||||||
|
gasLimit := uint64(0)
|
||||||
|
gasLimit += 16 * uint64(callDataLength) // calldata cost
|
||||||
|
gasLimit += 4*2100 + 3*22100 // fixed cost per batch
|
||||||
|
gasLimit += 4 * 22100 * uint64(numBlocks) // cost per block in batch
|
||||||
|
gasLimit = gasLimit * 12 / 10 // apply multiplier
|
||||||
|
return gasLimit
|
||||||
|
}
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ func NewL2WatcherClient(ctx context.Context, client *ethclient.Client, confirmat
|
|||||||
|
|
||||||
// Start the Listening process
|
// Start the Listening process
|
||||||
func (w *WatcherClient) Start() {
|
func (w *WatcherClient) Start() {
|
||||||
|
log.Info("Starting l2/watcher")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if reflect.ValueOf(w.orm).IsNil() {
|
if reflect.ValueOf(w.orm).IsNil() {
|
||||||
panic("must run L2 watcher with DB")
|
panic("must run L2 watcher with DB")
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func testCreateNewWatcherAndStop(t *testing.T) {
|
|||||||
numTransactions := 3
|
numTransactions := 3
|
||||||
toAddress := common.HexToAddress("0x4592d8f8d7b001e72cb26a73e4fa1806a51ac79d")
|
toAddress := common.HexToAddress("0x4592d8f8d7b001e72cb26a73e4fa1806a51ac79d")
|
||||||
for i := 0; i < numTransactions; i++ {
|
for i := 0; i < numTransactions; i++ {
|
||||||
_, err = newSender.SendTransaction(strconv.Itoa(1000+i), &toAddress, big.NewInt(1000000000), nil)
|
_, err = newSender.SendTransaction(strconv.Itoa(1000+i), &toAddress, big.NewInt(1000000000), nil, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
<-newSender.ConfirmChan()
|
<-newSender.ConfirmChan()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,18 +154,21 @@ func (s *Sender) NumberOfAccounts() int {
|
|||||||
return len(s.auths.accounts)
|
return len(s.auths.accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sender) getFeeData(auth *bind.TransactOpts, target *common.Address, value *big.Int, data []byte) (*FeeData, error) {
|
func (s *Sender) getFeeData(auth *bind.TransactOpts, target *common.Address, value *big.Int, data []byte, gasLimit uint64) (*FeeData, error) {
|
||||||
// estimate gas limit
|
if gasLimit == 0 {
|
||||||
gasLimit, err := s.client.EstimateGas(s.ctx, geth.CallMsg{From: auth.From, To: target, Value: value, Data: data})
|
// estimate gas limit
|
||||||
if err != nil {
|
var err error
|
||||||
return nil, err
|
gasLimit, err = s.client.EstimateGas(s.ctx, geth.CallMsg{From: auth.From, To: target, Value: value, Data: data})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
gasLimit = gasLimit * 15 / 10 // 50% extra gas to void out of gas error
|
||||||
}
|
}
|
||||||
gasLimit = gasLimit * 15 / 10 // 50% extra gas to void out of gas error
|
|
||||||
// @todo change it when Scroll enable EIP1559
|
// @todo change it when Scroll enable EIP1559
|
||||||
if s.config.TxType != DynamicFeeTxType {
|
if s.config.TxType != DynamicFeeTxType {
|
||||||
// estimate gas price
|
// estimate gas price
|
||||||
var gasPrice *big.Int
|
gasPrice, err := s.client.SuggestGasPrice(s.ctx)
|
||||||
gasPrice, err = s.client.SuggestGasPrice(s.ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -189,7 +192,7 @@ func (s *Sender) getFeeData(auth *bind.TransactOpts, target *common.Address, val
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendTransaction send a signed L2tL1 transaction.
|
// SendTransaction send a signed L2tL1 transaction.
|
||||||
func (s *Sender) SendTransaction(ID string, target *common.Address, value *big.Int, data []byte) (hash common.Hash, err error) {
|
func (s *Sender) SendTransaction(ID string, target *common.Address, value *big.Int, data []byte, gasLimit uint64) (hash common.Hash, err error) {
|
||||||
// We occupy the ID, in case some other threads call with the same ID in the same time
|
// We occupy the ID, in case some other threads call with the same ID in the same time
|
||||||
if _, loaded := s.pendingTxs.LoadOrStore(ID, nil); loaded {
|
if _, loaded := s.pendingTxs.LoadOrStore(ID, nil); loaded {
|
||||||
return common.Hash{}, fmt.Errorf("has the repeat tx ID, ID: %s", ID)
|
return common.Hash{}, fmt.Errorf("has the repeat tx ID, ID: %s", ID)
|
||||||
@@ -213,9 +216,10 @@ func (s *Sender) SendTransaction(ID string, target *common.Address, value *big.I
|
|||||||
tx *types.Transaction
|
tx *types.Transaction
|
||||||
)
|
)
|
||||||
// estimate gas fee
|
// estimate gas fee
|
||||||
if feeData, err = s.getFeeData(auth, target, value, data); err != nil {
|
if feeData, err = s.getFeeData(auth, target, value, data, gasLimit); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if tx, err = s.createAndSendTx(auth, feeData, target, value, data, nil); err == nil {
|
if tx, err = s.createAndSendTx(auth, feeData, target, value, data, nil); err == nil {
|
||||||
// add pending transaction to queue
|
// add pending transaction to queue
|
||||||
pending := &PendingTransaction{
|
pending := &PendingTransaction{
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func testBatchSender(t *testing.T, batchSize int) {
|
|||||||
for i := 0; i < TXBatch; i++ {
|
for i := 0; i < TXBatch; i++ {
|
||||||
toAddr := common.HexToAddress("0x4592d8f8d7b001e72cb26a73e4fa1806a51ac79d")
|
toAddr := common.HexToAddress("0x4592d8f8d7b001e72cb26a73e4fa1806a51ac79d")
|
||||||
id := strconv.Itoa(i + index*1000)
|
id := strconv.Itoa(i + index*1000)
|
||||||
_, err := newSender.SendTransaction(id, &toAddr, big.NewInt(1), nil)
|
_, err := newSender.SendTransaction(id, &toAddr, big.NewInt(1), nil, 0)
|
||||||
if errors.Is(err, sender.ErrNoAvailableAccount) {
|
if errors.Is(err, sender.ErrNoAvailableAccount) {
|
||||||
<-time.After(time.Second)
|
<-time.After(time.Second)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user