Skip to content

Commit

Permalink
Removed guardianProverAddress from BlockVerifiedEventHandler (#54)
Browse files Browse the repository at this point in the history
added more logs to init process
  • Loading branch information
mskrzypkows authored Jan 13, 2025
1 parent 8825362 commit 66cd1a7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
5 changes: 2 additions & 3 deletions packages/taiko-client/prover/event_handler/block_verified.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (

// BlockVerifiedEventHandler is responsible for handling the BlockVerified event.
type BlockVerifiedEventHandler struct {
guardianProverAddress common.Address
}

// NewBlockVerifiedEventHandler creates a new BlockVerifiedEventHandler instance.
func NewBlockVerifiedEventHandler(guardianProverAddress common.Address) *BlockVerifiedEventHandler {
return &BlockVerifiedEventHandler{guardianProverAddress: guardianProverAddress}
func NewBlockVerifiedEventHandler() *BlockVerifiedEventHandler {
return &BlockVerifiedEventHandler{}
}

// Handle handles the BlockVerified event.
Expand Down
29 changes: 24 additions & 5 deletions packages/taiko-client/prover/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,37 @@ func (p *Prover) initProofSubmitters(

// initL1Current initializes prover's L1Current cursor.
func (p *Prover) initL1Current(startingBlockID *big.Int) error {
log.Debug("Initializing L1Current cursor", "startingBlockID", startingBlockID)

if err := p.rpc.WaitTillL2ExecutionEngineSynced(p.ctx); err != nil {
log.Debug("Failed to wait for L2 execution engine sync", "error", err)
return err
}

stateVars, err := p.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: p.ctx})
if err != nil {
log.Debug("Failed to get protocol state variables", "error", err)
return err
}
log.Debug("Got protocol state variables", "lastVerifiedBlockId", stateVars.B.LastVerifiedBlockId)

if startingBlockID == nil {
if stateVars.B.LastVerifiedBlockId == 0 {
log.Debug("Last verified block ID is 0, using genesis height", "genesisHeight", stateVars.A.GenesisHeight)

genesisL1Header, err := p.rpc.L1.HeaderByNumber(p.ctx, new(big.Int).SetUint64(stateVars.A.GenesisHeight))
if err != nil {
log.Debug("Failed to get genesis L1 header", "error", err)
return err
}

p.sharedState.SetL1Current(genesisL1Header)
log.Debug("Set L1Current to genesis header", "blockNumber", genesisL1Header.Number)
return nil
}

startingBlockID = new(big.Int).SetUint64(stateVars.B.LastVerifiedBlockId)
log.Debug("Using last verified block ID as starting point", "startingBlockID", startingBlockID)
}

log.Info("Init L1Current cursor", "startingBlockID", startingBlockID)
Expand All @@ -249,26 +259,35 @@ func (p *Prover) initL1Current(startingBlockID *big.Int) error {
)
l1Head, err := p.rpc.L1.HeaderByNumber(p.ctx, nil)
if err != nil {
log.Debug("Failed to get latest L1 header", "error", err)
return err
}

p.sharedState.SetL1Current(l1Head)
log.Debug("Set L1Current to latest L1 head", "blockNumber", l1Head.Number)
return nil
}
log.Debug("Failed to get L1Origin by ID", "error", err)
return err
}
log.Debug("Got latest verified header L1 origin", "l1BlockHash", latestVerifiedHeaderL1Origin.L1BlockHash)

l1Current, err := p.rpc.L1.HeaderByHash(p.ctx, latestVerifiedHeaderL1Origin.L1BlockHash)
if err != nil {
log.Debug("Failed to get L1 header by hash", "error", err)
return err
}

p.sharedState.SetL1Current(l1Current)
log.Debug("Successfully set L1Current", "blockNumber", l1Current.Number)

return nil
}

// initEventHandlers initialize all event handlers which will be used by the current prover.
func (p *Prover) initEventHandlers() error {
log.Debug("Initializing event handlers")

// ------- BlockProposed -------
opts := &handler.NewBlockProposedEventHandlerOps{
SharedState: p.sharedState,
Expand All @@ -285,13 +304,15 @@ func (p *Prover) initEventHandlers() error {
ProveUnassignedBlocks: p.cfg.ProveUnassignedBlocks,
}
if p.IsGuardianProver() {
log.Debug("Initializing guardian BlockProposed handler")
p.blockProposedHandler = handler.NewBlockProposedEventGuardianHandler(
&handler.NewBlockProposedGuardianEventHandlerOps{
NewBlockProposedEventHandlerOps: opts,
GuardianProverHeartbeater: p.guardianProverHeartbeater,
},
)
} else {
log.Debug("Initializing regular BlockProposed handler")
p.blockProposedHandler = handler.NewBlockProposedEventHandler(opts)
}
// ------- TransitionProved -------
Expand Down Expand Up @@ -320,11 +341,9 @@ func (p *Prover) initEventHandlers() error {
)

// ------- BlockVerified -------
guardianProverAddress, err := p.rpc.GetGuardianProverAddress(p.ctx)
if err != nil {
return err
}
p.blockVerifiedHandler = handler.NewBlockVerifiedEventHandler(guardianProverAddress)
log.Debug("Setting up BlockVerified event handler")
p.blockVerifiedHandler = handler.NewBlockVerifiedEventHandler()

log.Debug("Successfully initialized all event handlers")
return nil
}
21 changes: 21 additions & 0 deletions packages/taiko-client/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func InitFromConfig(
txMgr *txmgr.SimpleTxManager,
privateTxMgr *txmgr.SimpleTxManager,
) (err error) {
log.Debug("Initializing prover from config")
p.cfg = cfg
p.ctx = ctx
// Initialize state which will be shared by event handlers.
Expand All @@ -104,6 +105,9 @@ func InitFromConfig(
)

// Clients
log.Debug("Initializing RPC client",
"l1Endpoint", cfg.L1WsEndpoint,
"l2Endpoint", cfg.L2WsEndpoint)
if p.rpc, err = rpc.NewClient(p.ctx, &rpc.ClientConfig{
L1Endpoint: cfg.L1WsEndpoint,
L2Endpoint: cfg.L2WsEndpoint,
Expand All @@ -119,27 +123,33 @@ func InitFromConfig(
}

// Configs
log.Debug("Getting protocol config")
p.protocolConfig = encoding.GetProtocolConfig(p.rpc.L2.ChainID.Uint64())
log.Info("Protocol configs", "configs", p.protocolConfig)

log.Debug("Initializing channels", "bufferSize", p.protocolConfig.BlockMaxProposals)
chBufferSize := p.protocolConfig.BlockMaxProposals
p.proofGenerationCh = make(chan *proofProducer.ProofWithHeader, chBufferSize)
p.assignmentExpiredCh = make(chan metadata.TaikoBlockMetaData, chBufferSize)
p.proofSubmissionCh = make(chan *proofProducer.ProofRequestBody, p.cfg.Capacity)
p.proofContestCh = make(chan *proofProducer.ContestRequestBody, p.cfg.Capacity)
p.proveNotify = make(chan struct{}, 1)

log.Debug("Initializing L1 current cursor", "startingBlockID", cfg.StartingBlockID)
if err := p.initL1Current(cfg.StartingBlockID); err != nil {
return fmt.Errorf("initialize L1 current cursor error: %w", err)
}

// Protocol proof tiers
log.Debug("Getting protocol tiers")
tiers, err := p.rpc.GetTiers(ctx)
if err != nil {
return err
}
p.sharedState.SetTiers(tiers)
log.Debug("Protocol tiers set", "tiers", tiers)

log.Debug("Initializing transaction builder")
txBuilder := transaction.NewProveBlockTxBuilder(
p.rpc,
p.cfg.TaikoL1Address,
Expand All @@ -148,9 +158,12 @@ func InitFromConfig(
p.cfg.GuardianProverMinorityAddress,
)

log.Debug("Setting up transaction managers")
if txMgr != nil {
p.txmgr = txMgr
log.Debug("Using provided transaction manager")
} else {
log.Debug("Creating new transaction manager")
if p.txmgr, err = txmgr.NewSimpleTxManager(
"prover",
log.Root(),
Expand All @@ -162,9 +175,12 @@ func InitFromConfig(
}

if privateTxMgr != nil {
log.Debug("Using provided private transaction manager")
p.privateTxmgr = privateTxMgr
} else {
log.Debug("Checking private transaction manager config")
if cfg.PrivateTxmgrConfigs != nil && len(cfg.PrivateTxmgrConfigs.L1RPCURL) > 0 {
log.Debug("Creating new private transaction manager")
if p.privateTxmgr, err = txmgr.NewSimpleTxManager(
"privateMempoolProver",
log.Root(),
Expand All @@ -174,16 +190,19 @@ func InitFromConfig(
return err
}
} else {
log.Debug("No private transaction manager configured")
p.privateTxmgr = nil
}
}

// Proof submitters
log.Debug("Initializing proof submitters")
if err := p.initProofSubmitters(txBuilder, tiers); err != nil {
return err
}

// Proof contester
log.Debug("Initializing proof contester")
p.proofContester = proofSubmitter.NewProofContester(
p.rpc,
p.cfg.ProveBlockGasLimit,
Expand All @@ -195,10 +214,12 @@ func InitFromConfig(
)

// Initialize event handlers.
log.Debug("Initializing event handlers")
if err := p.initEventHandlers(); err != nil {
return err
}

log.Debug("Prover initialization completed successfully")
return nil
}

Expand Down

0 comments on commit 66cd1a7

Please sign in to comment.