Skip to content

Commit

Permalink
feat(taiko-client): optimising statistics on proof request times (#17976
Browse files Browse the repository at this point in the history
)

Co-authored-by: David <[email protected]>
  • Loading branch information
YoGhurt111 and davidtaikocha authored Aug 27, 2024
1 parent a0c3388 commit 791f44f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/taiko-client/prover/proof_producer/dummy_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package producer
import (
"bytes"
"math/big"
"time"

"github.com/ethereum/go-ethereum/core/types"

Expand All @@ -19,6 +20,7 @@ func (o *DummyProofProducer) RequestProof(
meta metadata.TaikoBlockMetaData,
header *types.Header,
tier uint16,
_ time.Time,
) (*ProofWithHeader, error) {
return &ProofWithHeader{
BlockID: blockID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestDummyProducerRequestProof(t *testing.T) {
&metadata.TaikoDataBlockMetadataLegacy{},
header,
tier,
time.Now(),
)
require.Nil(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package producer
import (
"context"
"math/big"
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -36,6 +37,7 @@ func (g *GuardianProofProducer) RequestProof(
blockID *big.Int,
meta metadata.TaikoBlockMetaData,
header *types.Header,
requestAt time.Time,
) (*ProofWithHeader, error) {
log.Info(
"Request guardian proof",
Expand All @@ -56,7 +58,7 @@ func (g *GuardianProofProducer) RequestProof(
}, nil
}

return g.DummyProofProducer.RequestProof(opts, blockID, meta, header, g.Tier())
return g.DummyProofProducer.RequestProof(opts, blockID, meta, header, g.Tier(), requestAt)
}

func (g *GuardianProofProducer) RequestCancel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestGuardianProducerRequestProof(t *testing.T) {
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
header,
time.Now(),
)
require.Nil(t, err)

Expand Down Expand Up @@ -79,6 +80,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) {
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
header,
time.Now(),
)
require.Nil(t, err)

Expand Down Expand Up @@ -117,6 +119,7 @@ func TestMinorityRequestProof(t *testing.T) {
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
header,
time.Now(),
)
require.Nil(t, err)

Expand Down Expand Up @@ -154,6 +157,7 @@ func TestRequestMinorityProofReturnLivenessBond(t *testing.T) {
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
header,
time.Now(),
)
require.Nil(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package producer
import (
"context"
"math/big"
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -21,6 +22,7 @@ func (o *OptimisticProofProducer) RequestProof(
blockID *big.Int,
meta metadata.TaikoBlockMetaData,
header *types.Header,
requestAt time.Time,
) (*ProofWithHeader, error) {
log.Info(
"Request optimistic proof",
Expand All @@ -30,7 +32,7 @@ func (o *OptimisticProofProducer) RequestProof(
"hash", header.Hash(),
)

return o.DummyProofProducer.RequestProof(opts, blockID, meta, header, o.Tier())
return o.DummyProofProducer.RequestProof(opts, blockID, meta, header, o.Tier(), requestAt)
}

func (o *OptimisticProofProducer) RequestCancel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestOptimisticRequestProof(t *testing.T) {
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
header,
time.Now(),
)
require.Nil(t, err)

Expand Down Expand Up @@ -80,6 +81,7 @@ func TestProofCancel(t *testing.T) {
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
header,
time.Now(),
)
require.Nil(t, err)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/taiko-client/prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -62,6 +63,7 @@ type ProofProducer interface {
blockID *big.Int,
meta metadata.TaikoBlockMetaData,
header *types.Header,
requestAt time.Time,
) (*ProofWithHeader, error)
RequestCancel(
ctx context.Context,
Expand Down
16 changes: 10 additions & 6 deletions packages/taiko-client/prover/proof_producer/sgx_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (s *SGXProofProducer) RequestProof(
blockID *big.Int,
meta metadata.TaikoBlockMetaData,
header *types.Header,
requestAt time.Time,
) (*ProofWithHeader, error) {
log.Info(
"Request sgx proof from raiko-host service",
Expand All @@ -89,10 +90,10 @@ func (s *SGXProofProducer) RequestProof(
)

if s.Dummy {
return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier())
return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier(), requestAt)
}

proof, err := s.callProverDaemon(ctx, opts)
proof, err := s.callProverDaemon(ctx, opts, requestAt)
if err != nil {
return nil, err
}
Expand All @@ -117,10 +118,13 @@ func (s *SGXProofProducer) RequestCancel(
}

// callProverDaemon keeps polling the proverd service to get the requested proof.
func (s *SGXProofProducer) callProverDaemon(ctx context.Context, opts *ProofRequestOptions) ([]byte, error) {
func (s *SGXProofProducer) callProverDaemon(
ctx context.Context,
opts *ProofRequestOptions,
requestAt time.Time,
) ([]byte, error) {
var (
proof []byte
start = time.Now()
)

ctx, cancel := rpc.CtxWithTimeoutOrDefault(ctx, s.RaikoRequestTimeout)
Expand All @@ -136,7 +140,7 @@ func (s *SGXProofProducer) callProverDaemon(ctx context.Context, opts *ProofRequ
log.Info(
"Proof generating",
"height", opts.BlockID,
"time", time.Since(start),
"time", time.Since(requestAt),
"producer", "SGXProofProducer",
)
return nil, errProofGenerating
Expand All @@ -153,7 +157,7 @@ func (s *SGXProofProducer) callProverDaemon(ctx context.Context, opts *ProofRequ
log.Info(
"Proof generated",
"height", opts.BlockID,
"time", time.Since(start),
"time", time.Since(requestAt),
"producer", "SGXProofProducer",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestSGXProducerRequestProof(t *testing.T) {
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
header,
time.Now(),
)
require.Nil(t, err)

Expand Down
14 changes: 9 additions & 5 deletions packages/taiko-client/prover/proof_producer/zkvm_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (s *ZKvmProofProducer) RequestProof(
blockID *big.Int,
meta metadata.TaikoBlockMetaData,
header *types.Header,
requestAt time.Time,
) (*ProofWithHeader, error) {
log.Info(
"Request zk proof from raiko-host service",
Expand All @@ -78,10 +79,10 @@ func (s *ZKvmProofProducer) RequestProof(
)

if s.Dummy {
return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier())
return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier(), requestAt)
}

proof, err := s.callProverDaemon(ctx, opts)
proof, err := s.callProverDaemon(ctx, opts, requestAt)
if err != nil {
return nil, err
}
Expand All @@ -106,10 +107,13 @@ func (s *ZKvmProofProducer) RequestCancel(
}

// callProverDaemon keeps polling the proverd service to get the requested proof.
func (s *ZKvmProofProducer) callProverDaemon(ctx context.Context, opts *ProofRequestOptions) ([]byte, error) {
func (s *ZKvmProofProducer) callProverDaemon(
ctx context.Context,
opts *ProofRequestOptions,
requestAt time.Time,
) ([]byte, error) {
var (
proof []byte
start = time.Now()
)

zkCtx, zkCancel := rpc.CtxWithTimeoutOrDefault(ctx, s.RaikoRequestTimeout)
Expand All @@ -132,7 +136,7 @@ func (s *ZKvmProofProducer) callProverDaemon(ctx context.Context, opts *ProofReq
log.Info(
"Proof generated",
"height", opts.BlockID,
"time", time.Since(start),
"time", time.Since(requestAt),
"producer", "ZKvmProofProducer",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (s *ProofSubmitter) RequestProof(ctx context.Context, meta metadata.TaikoBl
meta.GetBlockID(),
meta,
header,
startTime,
)
if err != nil {
// If request proof has timed out in retry, let's cancel the proof generating and skip
Expand Down

0 comments on commit 791f44f

Please sign in to comment.