From 756056f04a3ba9da2e9e3298e39e9608e7ce559f Mon Sep 17 00:00:00 2001 From: gavin Date: Mon, 26 Aug 2024 13:46:15 +0800 Subject: [PATCH 1/3] feat(taiko-client): optimising statistics on proof request times --- .../prover/proof_producer/dummy_producer.go | 2 ++ .../prover/proof_producer/dummy_producer_test.go | 1 + .../prover/proof_producer/guardian_producer.go | 4 +++- .../proof_producer/guardian_producer_test.go | 4 ++++ .../prover/proof_producer/optimistic_producer.go | 4 +++- .../proof_producer/optimistic_producer_test.go | 2 ++ .../prover/proof_producer/proof_producer.go | 2 ++ .../prover/proof_producer/sgx_producer.go | 16 ++++++++++------ .../prover/proof_producer/sgx_producer_test.go | 1 + .../prover/proof_producer/zkvm_producer.go | 14 +++++++++----- .../prover/proof_submitter/proof_submitter.go | 1 + 11 files changed, 38 insertions(+), 13 deletions(-) diff --git a/packages/taiko-client/prover/proof_producer/dummy_producer.go b/packages/taiko-client/prover/proof_producer/dummy_producer.go index 5124c43f67a..54d10df173c 100644 --- a/packages/taiko-client/prover/proof_producer/dummy_producer.go +++ b/packages/taiko-client/prover/proof_producer/dummy_producer.go @@ -3,6 +3,7 @@ package producer import ( "bytes" "math/big" + "time" "github.com/ethereum/go-ethereum/core/types" @@ -19,6 +20,7 @@ func (o *DummyProofProducer) RequestProof( meta metadata.TaikoBlockMetaData, header *types.Header, tier uint16, + _ time.Time, ) (*ProofWithHeader, error) { return &ProofWithHeader{ BlockID: blockID, diff --git a/packages/taiko-client/prover/proof_producer/dummy_producer_test.go b/packages/taiko-client/prover/proof_producer/dummy_producer_test.go index 4c227b58086..e2361ae9cc8 100644 --- a/packages/taiko-client/prover/proof_producer/dummy_producer_test.go +++ b/packages/taiko-client/prover/proof_producer/dummy_producer_test.go @@ -40,6 +40,7 @@ func TestDummyProducerRequestProof(t *testing.T) { &metadata.TaikoDataBlockMetadataLegacy{}, header, tier, + time.Now(), ) require.Nil(t, err) diff --git a/packages/taiko-client/prover/proof_producer/guardian_producer.go b/packages/taiko-client/prover/proof_producer/guardian_producer.go index e86b30e931c..6455bdd6ab6 100644 --- a/packages/taiko-client/prover/proof_producer/guardian_producer.go +++ b/packages/taiko-client/prover/proof_producer/guardian_producer.go @@ -3,6 +3,7 @@ package producer import ( "context" "math/big" + "time" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -36,6 +37,7 @@ func (g *GuardianProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, + firstRequestTime time.Time, ) (*ProofWithHeader, error) { log.Info( "Request guardian proof", @@ -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(), firstRequestTime) } func (g *GuardianProofProducer) RequestCancel( diff --git a/packages/taiko-client/prover/proof_producer/guardian_producer_test.go b/packages/taiko-client/prover/proof_producer/guardian_producer_test.go index 7ca1ea1a8f2..2d51c0073aa 100644 --- a/packages/taiko-client/prover/proof_producer/guardian_producer_test.go +++ b/packages/taiko-client/prover/proof_producer/guardian_producer_test.go @@ -42,6 +42,7 @@ func TestGuardianProducerRequestProof(t *testing.T) { blockID, &metadata.TaikoDataBlockMetadataLegacy{}, header, + time.Now(), ) require.Nil(t, err) @@ -79,6 +80,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) { blockID, &metadata.TaikoDataBlockMetadataLegacy{}, header, + time.Now(), ) require.Nil(t, err) @@ -117,6 +119,7 @@ func TestMinorityRequestProof(t *testing.T) { blockID, &metadata.TaikoDataBlockMetadataLegacy{}, header, + time.Now(), ) require.Nil(t, err) @@ -154,6 +157,7 @@ func TestRequestMinorityProofReturnLivenessBond(t *testing.T) { blockID, &metadata.TaikoDataBlockMetadataLegacy{}, header, + time.Now(), ) require.Nil(t, err) diff --git a/packages/taiko-client/prover/proof_producer/optimistic_producer.go b/packages/taiko-client/prover/proof_producer/optimistic_producer.go index 79a5b4d1d51..2dac584b870 100644 --- a/packages/taiko-client/prover/proof_producer/optimistic_producer.go +++ b/packages/taiko-client/prover/proof_producer/optimistic_producer.go @@ -3,6 +3,7 @@ package producer import ( "context" "math/big" + "time" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" @@ -21,6 +22,7 @@ func (o *OptimisticProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, + firstRequestTime time.Time, ) (*ProofWithHeader, error) { log.Info( "Request optimistic proof", @@ -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(), firstRequestTime) } func (o *OptimisticProofProducer) RequestCancel( diff --git a/packages/taiko-client/prover/proof_producer/optimistic_producer_test.go b/packages/taiko-client/prover/proof_producer/optimistic_producer_test.go index d45055a0ebd..f5d756fff6d 100644 --- a/packages/taiko-client/prover/proof_producer/optimistic_producer_test.go +++ b/packages/taiko-client/prover/proof_producer/optimistic_producer_test.go @@ -43,6 +43,7 @@ func TestOptimisticRequestProof(t *testing.T) { blockID, &metadata.TaikoDataBlockMetadataLegacy{}, header, + time.Now(), ) require.Nil(t, err) @@ -80,6 +81,7 @@ func TestProofCancel(t *testing.T) { blockID, &metadata.TaikoDataBlockMetadataLegacy{}, header, + time.Now(), ) require.Nil(t, err) } diff --git a/packages/taiko-client/prover/proof_producer/proof_producer.go b/packages/taiko-client/prover/proof_producer/proof_producer.go index d88b47c0a42..7ecbc871730 100644 --- a/packages/taiko-client/prover/proof_producer/proof_producer.go +++ b/packages/taiko-client/prover/proof_producer/proof_producer.go @@ -4,6 +4,7 @@ import ( "context" "errors" "math/big" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -62,6 +63,7 @@ type ProofProducer interface { blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, + firstRequestTime time.Time, ) (*ProofWithHeader, error) RequestCancel( ctx context.Context, diff --git a/packages/taiko-client/prover/proof_producer/sgx_producer.go b/packages/taiko-client/prover/proof_producer/sgx_producer.go index dacf2b8ea62..c216cb46e13 100644 --- a/packages/taiko-client/prover/proof_producer/sgx_producer.go +++ b/packages/taiko-client/prover/proof_producer/sgx_producer.go @@ -79,6 +79,7 @@ func (s *SGXProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, + firstRequestTime time.Time, ) (*ProofWithHeader, error) { log.Info( "Request sgx proof from raiko-host service", @@ -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(), firstRequestTime) } - proof, err := s.callProverDaemon(ctx, opts) + proof, err := s.callProverDaemon(ctx, opts, firstRequestTime) if err != nil { return nil, err } @@ -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, + firstRequestTime time.Time, +) ([]byte, error) { var ( proof []byte - start = time.Now() ) ctx, cancel := rpc.CtxWithTimeoutOrDefault(ctx, s.RaikoRequestTimeout) @@ -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(firstRequestTime), "producer", "SGXProofProducer", ) return nil, errProofGenerating @@ -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(firstRequestTime), "producer", "SGXProofProducer", ) diff --git a/packages/taiko-client/prover/proof_producer/sgx_producer_test.go b/packages/taiko-client/prover/proof_producer/sgx_producer_test.go index 9c19b03009c..6b68cd57e09 100644 --- a/packages/taiko-client/prover/proof_producer/sgx_producer_test.go +++ b/packages/taiko-client/prover/proof_producer/sgx_producer_test.go @@ -41,6 +41,7 @@ func TestSGXProducerRequestProof(t *testing.T) { blockID, &metadata.TaikoDataBlockMetadataLegacy{}, header, + time.Now(), ) require.Nil(t, err) diff --git a/packages/taiko-client/prover/proof_producer/zkvm_producer.go b/packages/taiko-client/prover/proof_producer/zkvm_producer.go index 238976ab3d7..3f8757ac010 100644 --- a/packages/taiko-client/prover/proof_producer/zkvm_producer.go +++ b/packages/taiko-client/prover/proof_producer/zkvm_producer.go @@ -67,6 +67,7 @@ func (s *ZKvmProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, + firstRequestTime time.Time, ) (*ProofWithHeader, error) { log.Info( "Request zk proof from raiko-host service", @@ -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(), firstRequestTime) } - proof, err := s.callProverDaemon(ctx, opts) + proof, err := s.callProverDaemon(ctx, opts, firstRequestTime) if err != nil { return nil, err } @@ -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, + firstRequestTime time.Time, +) ([]byte, error) { var ( proof []byte - start = time.Now() ) zkCtx, zkCancel := rpc.CtxWithTimeoutOrDefault(ctx, s.RaikoRequestTimeout) @@ -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(firstRequestTime), "producer", "ZKvmProofProducer", ) diff --git a/packages/taiko-client/prover/proof_submitter/proof_submitter.go b/packages/taiko-client/prover/proof_submitter/proof_submitter.go index a4d3b77c851..c4040bcbb06 100644 --- a/packages/taiko-client/prover/proof_submitter/proof_submitter.go +++ b/packages/taiko-client/prover/proof_submitter/proof_submitter.go @@ -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 From cafcd3145abbd8dfb5564581164b4b7ec6df3719 Mon Sep 17 00:00:00 2001 From: Gavin Yu Date: Mon, 26 Aug 2024 14:41:35 +0800 Subject: [PATCH 2/3] Update packages/taiko-client/prover/proof_producer/sgx_producer.go Co-authored-by: David --- packages/taiko-client/prover/proof_producer/sgx_producer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taiko-client/prover/proof_producer/sgx_producer.go b/packages/taiko-client/prover/proof_producer/sgx_producer.go index c216cb46e13..0b2614fd4e5 100644 --- a/packages/taiko-client/prover/proof_producer/sgx_producer.go +++ b/packages/taiko-client/prover/proof_producer/sgx_producer.go @@ -79,7 +79,7 @@ func (s *SGXProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, - firstRequestTime time.Time, + requestAt time.Time, ) (*ProofWithHeader, error) { log.Info( "Request sgx proof from raiko-host service", From 54c0df1fcbedbb0984fb45699301548f189f83dc Mon Sep 17 00:00:00 2001 From: gavin Date: Mon, 26 Aug 2024 14:43:19 +0800 Subject: [PATCH 3/3] rename --- .../prover/proof_producer/guardian_producer.go | 4 ++-- .../prover/proof_producer/optimistic_producer.go | 4 ++-- .../prover/proof_producer/proof_producer.go | 2 +- .../taiko-client/prover/proof_producer/sgx_producer.go | 10 +++++----- .../prover/proof_producer/zkvm_producer.go | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/taiko-client/prover/proof_producer/guardian_producer.go b/packages/taiko-client/prover/proof_producer/guardian_producer.go index 6455bdd6ab6..fb3c45865e0 100644 --- a/packages/taiko-client/prover/proof_producer/guardian_producer.go +++ b/packages/taiko-client/prover/proof_producer/guardian_producer.go @@ -37,7 +37,7 @@ func (g *GuardianProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, - firstRequestTime time.Time, + requestAt time.Time, ) (*ProofWithHeader, error) { log.Info( "Request guardian proof", @@ -58,7 +58,7 @@ func (g *GuardianProofProducer) RequestProof( }, nil } - return g.DummyProofProducer.RequestProof(opts, blockID, meta, header, g.Tier(), firstRequestTime) + return g.DummyProofProducer.RequestProof(opts, blockID, meta, header, g.Tier(), requestAt) } func (g *GuardianProofProducer) RequestCancel( diff --git a/packages/taiko-client/prover/proof_producer/optimistic_producer.go b/packages/taiko-client/prover/proof_producer/optimistic_producer.go index 2dac584b870..b97feef14e4 100644 --- a/packages/taiko-client/prover/proof_producer/optimistic_producer.go +++ b/packages/taiko-client/prover/proof_producer/optimistic_producer.go @@ -22,7 +22,7 @@ func (o *OptimisticProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, - firstRequestTime time.Time, + requestAt time.Time, ) (*ProofWithHeader, error) { log.Info( "Request optimistic proof", @@ -32,7 +32,7 @@ func (o *OptimisticProofProducer) RequestProof( "hash", header.Hash(), ) - return o.DummyProofProducer.RequestProof(opts, blockID, meta, header, o.Tier(), firstRequestTime) + return o.DummyProofProducer.RequestProof(opts, blockID, meta, header, o.Tier(), requestAt) } func (o *OptimisticProofProducer) RequestCancel( diff --git a/packages/taiko-client/prover/proof_producer/proof_producer.go b/packages/taiko-client/prover/proof_producer/proof_producer.go index 7ecbc871730..fbcbf3e144a 100644 --- a/packages/taiko-client/prover/proof_producer/proof_producer.go +++ b/packages/taiko-client/prover/proof_producer/proof_producer.go @@ -63,7 +63,7 @@ type ProofProducer interface { blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, - firstRequestTime time.Time, + requestAt time.Time, ) (*ProofWithHeader, error) RequestCancel( ctx context.Context, diff --git a/packages/taiko-client/prover/proof_producer/sgx_producer.go b/packages/taiko-client/prover/proof_producer/sgx_producer.go index 0b2614fd4e5..3ae67cff2bc 100644 --- a/packages/taiko-client/prover/proof_producer/sgx_producer.go +++ b/packages/taiko-client/prover/proof_producer/sgx_producer.go @@ -90,10 +90,10 @@ func (s *SGXProofProducer) RequestProof( ) if s.Dummy { - return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier(), firstRequestTime) + return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier(), requestAt) } - proof, err := s.callProverDaemon(ctx, opts, firstRequestTime) + proof, err := s.callProverDaemon(ctx, opts, requestAt) if err != nil { return nil, err } @@ -121,7 +121,7 @@ func (s *SGXProofProducer) RequestCancel( func (s *SGXProofProducer) callProverDaemon( ctx context.Context, opts *ProofRequestOptions, - firstRequestTime time.Time, + requestAt time.Time, ) ([]byte, error) { var ( proof []byte @@ -140,7 +140,7 @@ func (s *SGXProofProducer) callProverDaemon( log.Info( "Proof generating", "height", opts.BlockID, - "time", time.Since(firstRequestTime), + "time", time.Since(requestAt), "producer", "SGXProofProducer", ) return nil, errProofGenerating @@ -157,7 +157,7 @@ func (s *SGXProofProducer) callProverDaemon( log.Info( "Proof generated", "height", opts.BlockID, - "time", time.Since(firstRequestTime), + "time", time.Since(requestAt), "producer", "SGXProofProducer", ) diff --git a/packages/taiko-client/prover/proof_producer/zkvm_producer.go b/packages/taiko-client/prover/proof_producer/zkvm_producer.go index 3f8757ac010..f842981a37c 100644 --- a/packages/taiko-client/prover/proof_producer/zkvm_producer.go +++ b/packages/taiko-client/prover/proof_producer/zkvm_producer.go @@ -67,7 +67,7 @@ func (s *ZKvmProofProducer) RequestProof( blockID *big.Int, meta metadata.TaikoBlockMetaData, header *types.Header, - firstRequestTime time.Time, + requestAt time.Time, ) (*ProofWithHeader, error) { log.Info( "Request zk proof from raiko-host service", @@ -79,10 +79,10 @@ func (s *ZKvmProofProducer) RequestProof( ) if s.Dummy { - return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier(), firstRequestTime) + return s.DummyProofProducer.RequestProof(opts, blockID, meta, header, s.Tier(), requestAt) } - proof, err := s.callProverDaemon(ctx, opts, firstRequestTime) + proof, err := s.callProverDaemon(ctx, opts, requestAt) if err != nil { return nil, err } @@ -110,7 +110,7 @@ func (s *ZKvmProofProducer) RequestCancel( func (s *ZKvmProofProducer) callProverDaemon( ctx context.Context, opts *ProofRequestOptions, - firstRequestTime time.Time, + requestAt time.Time, ) ([]byte, error) { var ( proof []byte @@ -136,7 +136,7 @@ func (s *ZKvmProofProducer) callProverDaemon( log.Info( "Proof generated", "height", opts.BlockID, - "time", time.Since(firstRequestTime), + "time", time.Since(requestAt), "producer", "ZKvmProofProducer", )