Commit b6152b2f authored by vicotor's avatar vicotor

fix bug and add log

parent 893bf27b
package bindings
import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"math/big"
"testing"
)
func TestL2oo(t *testing.T) {
url := "https://achain.bitheart.org"
client, _ := ethclient.Dial(url)
l2ooContract, _ := NewL2OutputOracle(common.HexToAddress("0xB90B39722517Fcaa565146Ee3877fF9AEa0C9a85"), client)
callOpts := &bind.CallOpts{}
index, err := l2ooContract.GetL2OutputIndexAfter(callOpts, big.NewInt(10))
if err != nil {
t.Error(err)
} else {
t.Log("index:", index)
}
}
...@@ -259,12 +259,12 @@ func (l *L2OutputSubmitter) FetchL2OOOutput(ctx context.Context) (*eth.OutputRes ...@@ -259,12 +259,12 @@ func (l *L2OutputSubmitter) FetchL2OOOutput(ctx context.Context) (*eth.OutputRes
// Always propose if it's part of the Finalized L2 chain. Or if allowed, if it's part of the safe L2 chain. // Always propose if it's part of the Finalized L2 chain. Or if allowed, if it's part of the safe L2 chain.
if output.BlockRef.Number > output.Status.FinalizedL2.Number && (!l.Cfg.AllowNonFinalized || output.BlockRef.Number > output.Status.SafeL2.Number) { if output.BlockRef.Number > output.Status.FinalizedL2.Number && (!l.Cfg.AllowNonFinalized || output.BlockRef.Number > output.Status.SafeL2.Number) {
l.Log.Debug("Not proposing yet, L2 block is not ready for proposal", //l.Log.Info("Not proposing yet, L2 block is not ready for proposal",
"l2_proposal", output.BlockRef, // "l2_proposal", output.BlockRef,
"l2_safe", output.Status.SafeL2, // "l2_safe", output.Status.SafeL2,
"l2_finalized", output.Status.FinalizedL2, // "l2_finalized", output.Status.FinalizedL2,
"allow_non_finalized", l.Cfg.AllowNonFinalized) // "allow_non_finalized", l.Cfg.AllowNonFinalized)
return output, false, nil //return output, false, nil
} }
return output, true, nil return output, true, nil
} }
......
...@@ -111,11 +111,7 @@ func (l *Operator) GetProgress() OperatorProgress { ...@@ -111,11 +111,7 @@ func (l *Operator) GetProgress() OperatorProgress {
return progress return progress
} }
func (l *Operator) SetProgress(blockNum uint64, index uint64) { func (l *Operator) SetProgress(progress OperatorProgress) {
progress := OperatorProgress{
BlockNumber: blockNum,
Index: index,
}
value, err := json.Marshal(progress) value, err := json.Marshal(progress)
if err != nil { if err != nil {
l.Log.Error("failed to marshal operator progress", "err", err) l.Log.Error("failed to marshal operator progress", "err", err)
...@@ -202,7 +198,7 @@ func (l *Operator) StopOperatorIfRunning() error { ...@@ -202,7 +198,7 @@ func (l *Operator) StopOperatorIfRunning() error {
func (l *Operator) getL2ooIndex(callOpts *bind.CallOpts, l2BlockNumber uint64) (*big.Int, error) { func (l *Operator) getL2ooIndex(callOpts *bind.CallOpts, l2BlockNumber uint64) (*big.Int, error) {
index, err := l.l2ooContract.GetL2OutputIndexAfter(callOpts, big.NewInt(int64(l2BlockNumber))) index, err := l.l2ooContract.GetL2OutputIndexAfter(callOpts, big.NewInt(int64(l2BlockNumber)))
if err != nil { if err != nil {
l.Log.Error("failed to get l2 output index after", "err", err) l.Log.Error("failed to get l2 output index after", "err", err, "l2blk", l2BlockNumber)
return nil, err return nil, err
} }
return index, nil return index, nil
...@@ -242,7 +238,7 @@ func (l *Operator) DoOperator(ctx context.Context) { ...@@ -242,7 +238,7 @@ func (l *Operator) DoOperator(ctx context.Context) {
l.Log.Error("failed to get latest block number from l2oo", "err", err) l.Log.Error("failed to get latest block number from l2oo", "err", err)
return return
} }
l.Log.Info("latest block number from l2oo", "l2Latest", l2Latest, "progress", progress) l.Log.Info("operator latest block number from l2oo", "l2Latest", l2Latest, "progress", progress)
currentFinished := false currentFinished := false
if progress.Total == 0 || progress.Index == (progress.Total-1) { if progress.Total == 0 || progress.Index == (progress.Total-1) {
currentFinished = true currentFinished = true
...@@ -299,7 +295,11 @@ func (l *Operator) DoOperator(ctx context.Context) { ...@@ -299,7 +295,11 @@ func (l *Operator) DoOperator(ctx context.Context) {
} else { } else {
index++ index++
// update process. // update process.
l.SetProgress(index, progress.Total) l.SetProgress(OperatorProgress{
BlockNumber: progress.BlockNumber,
Index: index,
Total: progress.Total,
})
} }
} }
} }
...@@ -311,11 +311,28 @@ func (l *Operator) DoOperator(ctx context.Context) { ...@@ -311,11 +311,28 @@ func (l *Operator) DoOperator(ctx context.Context) {
} }
// 4. to process next block. // 4. to process next block.
for blkNum := progress.BlockNumber + 1; blkNum <= l2Latest.Uint64(); blkNum++ { for blkNum := progress.BlockNumber + 1; blkNum <= l2Latest.Uint64(); blkNum++ {
ooIndex, err := l.getL2ooIndex(callOpts, blkNum)
if err != nil {
l.Log.Error("operator failed to get l2oo index and output", "err", err)
return
}
withDrawalTxs := make([]common.Hash, 0) withDrawalTxs := make([]common.Hash, 0)
if txs, err := rollupClient.WithdrawalTxs(ctx, blkNum); err != nil { if txs, err := rollupClient.WithdrawalTxs(ctx, blkNum); err != nil {
l.Log.Error("failed to get withdrawal txs", "blknum", blkNum, "err", err) l.Log.Error("failed to get withdrawal txs", "blknum", blkNum, "err", err)
return return
} else { } else {
if len(txs) == 0 {
l.Log.Info("ignore block no txs to withdrawal", "blknum", blkNum)
l.SetOperatorTaskList(OperatorTaskList{})
l.SetProgress(OperatorProgress{
BlockNumber: blkNum,
Index: 0,
Total: 0,
})
continue
}
withDrawalTxs = append(withDrawalTxs, txs...) withDrawalTxs = append(withDrawalTxs, txs...)
} }
newProgress := OperatorProgress{ newProgress := OperatorProgress{
...@@ -331,13 +348,7 @@ func (l *Operator) DoOperator(ctx context.Context) { ...@@ -331,13 +348,7 @@ func (l *Operator) DoOperator(ctx context.Context) {
tasks = append(tasks, task) tasks = append(tasks, task)
} }
l.SetOperatorTaskList(tasks) l.SetOperatorTaskList(tasks)
l.SetProgress(newProgress.BlockNumber, newProgress.Index) l.SetProgress(newProgress)
ooIndex, err := l.getL2ooIndex(callOpts, progress.BlockNumber)
if err != nil {
l.Log.Error("failed to get l2oo index and output", "err", err)
return
}
// 5. to process each withdrawal tx. // 5. to process each withdrawal tx.
index := newProgress.Index index := newProgress.Index
...@@ -373,7 +384,11 @@ func (l *Operator) DoOperator(ctx context.Context) { ...@@ -373,7 +384,11 @@ func (l *Operator) DoOperator(ctx context.Context) {
} else { } else {
index++ index++
// update process. // update process.
l.SetProgress(index, newProgress.Total) l.SetProgress(OperatorProgress{
BlockNumber: newProgress.BlockNumber,
Index: index,
Total: newProgress.Total,
})
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment