diff --git a/node/db/store.go b/node/db/store.go index 3a6124e26..dcabfc091 100644 --- a/node/db/store.go +++ b/node/db/store.go @@ -57,7 +57,7 @@ func (s *Store) ReadLatestDerivationL1Height() *uint64 { panic(fmt.Sprintf("Failed to read batch index from database,err:%v", err)) } if len(data) == 0 { - return new(uint64) + return nil } number := new(big.Int).SetBytes(data) diff --git a/node/derivation/batch_info.go b/node/derivation/batch_info.go index 203271396..8b55ed92b 100644 --- a/node/derivation/batch_info.go +++ b/node/derivation/batch_info.go @@ -13,10 +13,6 @@ import ( "morph-l2/node/types" ) -//type Chunk struct { -// blockContextes []*BlockContext -//} - type BlockContext struct { Number uint64 `json:"number"` Timestamp uint64 `json:"timestamp"` diff --git a/node/derivation/database.go b/node/derivation/database.go index 3b286dfd4..a63f4eba1 100644 --- a/node/derivation/database.go +++ b/node/derivation/database.go @@ -12,10 +12,8 @@ type Database interface { type Reader interface { ReadLatestDerivationL1Height() *uint64 - //ReadLatestBatchBls() types.BatchBls } type Writer interface { WriteLatestDerivationL1Height(latest uint64) - //WriteLatestBatchBls(batchBls types.BatchBls) } diff --git a/node/derivation/derivation.go b/node/derivation/derivation.go index 28f69bbae..ae0beb7ac 100644 --- a/node/derivation/derivation.go +++ b/node/derivation/derivation.go @@ -50,6 +50,7 @@ type Derivation struct { cancel context.CancelFunc + startHeight uint64 fetchBlockRange uint64 pollInterval time.Duration logProgressInterval time.Duration @@ -107,6 +108,7 @@ func NewDerivationClient(ctx context.Context, cfg *Config, syncer *sync.Syncer, l2Client: types.NewRetryableClient(aClient, eClient, tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout))), cancel: cancel, stop: make(chan struct{}), + startHeight: cfg.StartHeight, fetchBlockRange: cfg.FetchBlockRange, pollInterval: cfg.PollInterval, logProgressInterval: cfg.LogProgressInterval, @@ -156,7 +158,12 @@ func (d *Derivation) Stop() { func (d *Derivation) derivationBlock(ctx context.Context) { latestDerivation := d.db.ReadLatestDerivationL1Height() latest := d.syncer.LatestSynced() - start := *latestDerivation + 1 + var start uint64 + if latestDerivation == nil { + start = d.startHeight + } else { + start = *latestDerivation + 1 + } end := latest if latest < start { d.logger.Info("latest less than start", "latest", latest, "start", start) @@ -170,9 +177,7 @@ func (d *Derivation) derivationBlock(ctx context.Context) { d.logger.Error("eth_getLogs failed", "err", err) return } - latestBatchIndex, err := d.rollup.LastCommittedBatchIndex(&bind.CallOpts{ - BlockNumber: big.NewInt(int64(latest)), - }) + latestBatchIndex, err := d.rollup.LastCommittedBatchIndex(nil) if err != nil { d.logger.Error("query rollup latestCommitted batch Index failed", "err", err) return