Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-supervisor: Load the starting block from log db #11090

Merged
merged 8 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion op-supervisor/supervisor/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"math"
"math/big"
"sync/atomic"
"time"
Expand Down Expand Up @@ -51,7 +52,21 @@ func NewSupervisorBackend(ctx context.Context, logger log.Logger, m Metrics, cfg
return nil, fmt.Errorf("failed to create logdb for chain %v at %v: %w", chainID, path, err)
}
logDBs[i] = logDB
monitor, err := source.NewChainMonitor(ctx, logger, cm, chainID, rpc, rpcClient)

//we'll need to get the last checkpoint that was written (could use ClosestBlockInfo and pass math.maxUInt64)
//then Rewind the db to the block prior to that block and start from there.
//That guarantees we will always roll back at least one block
//so we know we're always starting from a fully written block.
ajsutton marked this conversation as resolved.
Show resolved Hide resolved
checkPointBlock, _ ,err := logDB.ClosestBlockInfo(math.MaxUint64)
if err != nil {
return nil, fmt.Errorf("failed to get block from checkpoint: %w", err)
}
block := checkPointBlock - 1
err = logDB.Rewind(block)
if err != nil {
return nil, fmt.Errorf("failed to 'Rewind' the database: %w", err)
}
monitor, err := source.NewChainMonitor(ctx, logger, cm, chainID, rpc, rpcClient, block)
if err != nil {
return nil, fmt.Errorf("failed to create monitor for rpc %v: %w", rpc, err)
}
Expand Down
7 changes: 4 additions & 3 deletions op-supervisor/supervisor/backend/source/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ type ChainMonitor struct {
headMonitor *HeadMonitor
}

func NewChainMonitor(ctx context.Context, logger log.Logger, m Metrics, chainID *big.Int, rpc string, client client.RPC) (*ChainMonitor, error) {
func NewChainMonitor(ctx context.Context, logger log.Logger, m Metrics, chainID *big.Int, rpc string, client client.RPC, block uint64) (*ChainMonitor, error) {
logger = logger.New("chainID", chainID)
cl, err := newClient(ctx, logger, m, rpc, client, pollInterval, trustRpc, rpcKind)
if err != nil {
return nil, err
}

// TODO(optimism#11023): Load the starting block from log db
startingHead := eth.L1BlockRef{}
startingHead := eth.L1BlockRef{
Number: block,
}

fetchReceipts := newLogFetcher(cl, &loggingReceiptProcessor{logger})
unsafeBlockProcessor := NewChainProcessor(logger, cl, startingHead, fetchReceipts)
Expand Down