Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Sep 29, 2024
1 parent 1afd4fe commit 9222d1c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/taiko-client/prover/proof_submitter/proof_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9222d1c

Please sign in to comment.