Skip to content

Commit

Permalink
feat: update NewBlockProposedIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jan 13, 2025
1 parent 9230f4a commit d527a1f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ func (s *Syncer) processL1Blocks(ctx context.Context) error {
iter, err := eventIterator.NewBlockProposedIterator(ctx, &eventIterator.BlockProposedIteratorConfig{
Client: s.rpc.L1,
TaikoL1: s.rpc.OntakeClients.TaikoL1,
TaikoInbox: s.rpc.PacayaClients.TaikoInbox,
StartHeight: s.state.GetL1Current().Number,
EndHeight: l1End.Number,
FilterQuery: nil,
OnBlockProposedEvent: s.onBlockProposed,
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion packages/taiko-client/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (d *Driver) reportProtocolStatus() {
log.Info(
"📖 Protocol status",
// TODO: fix these two values, and add one more deleted value.
"lastVerifiedBacth", vars.Stats2.LastVerifiedBatchId,
"lastVerifiedBacthID", vars.Stats2.LastVerifiedBatchId,
"pendingBlocks", vars.Stats2.NumBatches-vars.Stats2.LastVerifiedBatchId-1,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/metadata"
ontakeBindings "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/ontake"
pacayaBindings "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/pacaya"
chainIterator "github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/chain_iterator"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
)
Expand All @@ -30,19 +31,19 @@ type OnBlockProposedEvent func(
type BlockProposedIterator struct {
ctx context.Context
taikoL1 *ontakeBindings.TaikoL1Client
taikoInbox *pacayaBindings.TaikoInboxClient
blockBatchIterator *chainIterator.BlockBatchIterator
filterQuery []*big.Int
isEnd bool
}

// BlockProposedIteratorConfig represents the configs of a BlockProposed event iterator.
type BlockProposedIteratorConfig struct {
Client *rpc.EthClient
TaikoL1 *ontakeBindings.TaikoL1Client
TaikoInbox *pacayaBindings.TaikoInboxClient
MaxBlocksReadPerEpoch *uint64
StartHeight *big.Int
EndHeight *big.Int
FilterQuery []*big.Int
OnBlockProposedEvent OnBlockProposedEvent
BlockConfirmations *uint64
}
Expand All @@ -54,9 +55,8 @@ func NewBlockProposedIterator(ctx context.Context, cfg *BlockProposedIteratorCon
}

iterator := &BlockProposedIterator{
ctx: ctx,
taikoL1: cfg.TaikoL1,
filterQuery: cfg.FilterQuery,
ctx: ctx,
taikoL1: cfg.TaikoL1,
}

// Initialize the inner block iterator.
Expand All @@ -69,7 +69,7 @@ func NewBlockProposedIterator(ctx context.Context, cfg *BlockProposedIteratorCon
OnBlocks: assembleBlockProposedIteratorCallback(
cfg.Client,
cfg.TaikoL1,
cfg.FilterQuery,
cfg.TaikoInbox,
cfg.OnBlockProposedEvent,
iterator,
),
Expand Down Expand Up @@ -99,7 +99,7 @@ func (i *BlockProposedIterator) end() {
func assembleBlockProposedIteratorCallback(
client *rpc.EthClient,
taikoL1 *ontakeBindings.TaikoL1Client,
filterQuery []*big.Int,
taikoInbox *pacayaBindings.TaikoInboxClient,
callback OnBlockProposedEvent,
eventIter *BlockProposedIterator,
) chainIterator.OnBlocksFunc {
Expand All @@ -113,7 +113,7 @@ func assembleBlockProposedIteratorCallback(

iterOntake, err := taikoL1.FilterBlockProposedV2(
&bind.FilterOpts{Start: start.Number.Uint64(), End: &endHeight, Context: ctx},
filterQuery,
nil,
)
if err != nil {
return err
Expand All @@ -140,6 +140,42 @@ func assembleBlockProposedIteratorCallback(
updateCurrentFunc(current)
}

return iterOntake.Error()
iterPacaya, err := taikoInbox.FilterBatchProposed(
&bind.FilterOpts{Start: start.Number.Uint64(), End: &endHeight, Context: ctx},
)
if err != nil {
return err
}
defer iterPacaya.Close()

for iterOntake.Next() {
event := iterOntake.Event

if err := callback(ctx, metadata.NewTaikoDataBlockMetadataOntake(event), eventIter.end); err != nil {
return err
}

if eventIter.isEnd {
endFunc()
return nil
}

current, err := client.HeaderByHash(ctx, event.Raw.BlockHash)
if err != nil {
return err
}

updateCurrentFunc(current)
}

// Check if there is any error during the iteration.
if iterOntake.Error() != nil {
return iterOntake.Error()
}
if iterPacaya.Error() != nil {
return iterPacaya.Error()
}

return nil
}
}
1 change: 1 addition & 0 deletions packages/taiko-client/prover/event_handler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func getMetadataFromBlockID(
iter, err := eventIterator.NewBlockProposedIterator(ctx, &eventIterator.BlockProposedIteratorConfig{
Client: rpc.L1,
TaikoL1: rpc.OntakeClients.TaikoL1,
TaikoInbox: rpc.PacayaClients.TaikoInbox,
StartHeight: new(big.Int).Sub(proposedIn, common.Big1),
EndHeight: proposedIn,
OnBlockProposedEvent: callback,
Expand Down
1 change: 1 addition & 0 deletions packages/taiko-client/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ func (p *Prover) proveOp() error {
iter, err := eventIterator.NewBlockProposedIterator(p.ctx, &eventIterator.BlockProposedIteratorConfig{
Client: p.rpc.L1,
TaikoL1: p.rpc.OntakeClients.TaikoL1,
TaikoInbox: p.rpc.PacayaClients.TaikoInbox,
StartHeight: new(big.Int).SetUint64(p.sharedState.GetL1Current().Number.Uint64()),
OnBlockProposedEvent: p.blockProposedHandler.Handle,
BlockConfirmations: &p.cfg.BlockConfirmations,
Expand Down

0 comments on commit d527a1f

Please sign in to comment.