diff --git a/packages/taiko-client/prover/proof_submitter/proof_buffer.go b/packages/taiko-client/prover/proof_submitter/proof_buffer.go index d48fc87664..9d2fa4b7d6 100644 --- a/packages/taiko-client/prover/proof_submitter/proof_buffer.go +++ b/packages/taiko-client/prover/proof_submitter/proof_buffer.go @@ -16,7 +16,7 @@ var ( type ProofBuffer struct { MaxLength uint64 buffer []*producer.ProofWithHeader - mutex sync.Mutex + mutex sync.RWMutex } // NewProofBuffer creates a new ProofBuffer instance. @@ -42,6 +42,8 @@ func (pb *ProofBuffer) Write(item *producer.ProofWithHeader) (int, error) { // Read returns the content with given length in the buffer. func (pb *ProofBuffer) Read(length int) ([]*producer.ProofWithHeader, error) { + pb.mutex.RLock() + defer pb.mutex.RUnlock() if length > len(pb.buffer) { return nil, errNotEnoughProof } @@ -54,13 +56,13 @@ func (pb *ProofBuffer) Read(length int) ([]*producer.ProofWithHeader, error) { // ReadAll returns all the content in the buffer. func (pb *ProofBuffer) ReadAll() ([]*producer.ProofWithHeader, error) { - return pb.Read(len(pb.buffer)) + return pb.Read(pb.Len()) } // Len returns current length of the buffer. func (pb *ProofBuffer) Len() int { - pb.mutex.Lock() - defer pb.mutex.Unlock() + pb.mutex.RLock() + defer pb.mutex.RUnlock() return len(pb.buffer) } diff --git a/packages/taiko-client/prover/proof_submitter/proof_submitter.go b/packages/taiko-client/prover/proof_submitter/proof_submitter.go index 3ac3daa47e..628d104691 100644 --- a/packages/taiko-client/prover/proof_submitter/proof_submitter.go +++ b/packages/taiko-client/prover/proof_submitter/proof_submitter.go @@ -159,6 +159,11 @@ func (s *ProofSubmitter) RequestProof(ctx context.Context, meta metadata.TaikoBl log.Error("Failed to request proof, context is canceled", "blockID", opts.BlockID, "error", ctx.Err()) return nil } + if int(s.proofBuffer.MaxLength) == s.proofBuffer.Len() { + if err = s.AggregateProofs(ctx); err != nil { + return fmt.Errorf("failed to aggregate proof : %w", err) + } + } // Check if there is a need to generate proof proofStatus, err := rpc.GetBlockProofStatus( ctx, @@ -209,7 +214,7 @@ func (s *ProofSubmitter) RequestProof(ctx context.Context, meta metadata.TaikoBl ) if s.proofBuffer.MaxLength == uint64(bufferSize) { if err = s.AggregateProofs(ctx); err != nil { - return fmt.Errorf("failed to aggregate proof : %w", err) + log.Error("failed to aggregate proof", "error", err) } } } else { @@ -420,6 +425,7 @@ func (s *ProofSubmitter) BatchSubmitProofs(ctx context.Context, batchProof *proo if err := s.sender.SendBatchProof( ctx, s.txBuilder.BuildProveBlocks(batchProof), + batchProof, ); err != nil { if err.Error() == transaction.ErrUnretryableSubmission.Error() { return nil @@ -428,6 +434,7 @@ func (s *ProofSubmitter) BatchSubmitProofs(ctx context.Context, batchProof *proo return err } + // TODO metrics.ProverSentProofCounter.Add(1) metrics.ProverLatestProvenBlockIDGauge.Set(float64(latestProvenBlockID.Uint64())) s.proofBuffer.Clear() diff --git a/packages/taiko-client/prover/proof_submitter/transaction/sender.go b/packages/taiko-client/prover/proof_submitter/transaction/sender.go index c8e835d453..b530799d87 100644 --- a/packages/taiko-client/prover/proof_submitter/transaction/sender.go +++ b/packages/taiko-client/prover/proof_submitter/transaction/sender.go @@ -118,6 +118,7 @@ func (s *Sender) Send( func (s *Sender) SendBatchProof( ctx context.Context, buildTx TxBuilder, + batchProof *producer.BatchProofs, ) error { // Assemble the TaikoL1.proveBlocks transaction. txCandidate, err := buildTx(&bind.TransactOpts{GasLimit: s.gasLimit}) @@ -148,8 +149,11 @@ func (s *Sender) SendBatchProof( log.Info( "💰 Your block proof aggregation was accepted", "txHash", receipt.TxHash, + "tier", batchProof.Tier, + "blockIDs", batchProof.BlockIDs, ) + // TODO metrics.ProverSubmissionAcceptedCounter.Add(1) return nil