Skip to content

Commit 8593bb2

Browse files
committed
Merge branch 'feat/prover_metric' into feat/dyn_asset_loading
2 parents 3cbd07c + 6a9a34b commit 8593bb2

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

common/types/message/message.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ type BlockContextV2 struct {
135135
NumL1Msgs uint16 `json:"num_l1_msgs"`
136136
}
137137

138+
// Metric data carried with OpenVMProof
139+
type OpenVMProofStat struct {
140+
TotalCycle uint64 `json:"total_cycles"`
141+
ExecutionTimeMills uint64 `json:"execution_time_mills"`
142+
ProvingTimeMills uint64 `json:"proving_time_mills"`
143+
}
144+
138145
// Proof for flatten VM proof
139146
type OpenVMProof struct {
140-
Proof []byte `json:"proofs"`
141-
PublicValues []byte `json:"public_values"`
147+
Proof []byte `json:"proofs"`
148+
PublicValues []byte `json:"public_values"`
149+
Stat *OpenVMProofStat `json:"stat,omitempty"`
142150
}
143151

144152
// Proof for flatten EVM proof
@@ -150,7 +158,8 @@ type OpenVMEvmProof struct {
150158
// OpenVMChunkProof includes the proof info that are required for chunk verification and rollup.
151159
type OpenVMChunkProof struct {
152160
MetaData struct {
153-
ChunkInfo *ChunkInfo `json:"chunk_info"`
161+
ChunkInfo *ChunkInfo `json:"chunk_info"`
162+
TotalGasUsed uint64 `json:"chunk_total_gas"`
154163
} `json:"metadata"`
155164

156165
VmProof *OpenVMProof `json:"proof"`

coordinator/internal/logic/submitproof/proof_receiver.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ type ProofReceiverLogic struct {
7171
validateFailureProverTaskStatusNotOk prometheus.Counter
7272
validateFailureProverTaskTimeout prometheus.Counter
7373
validateFailureProverTaskHaveVerifier prometheus.Counter
74+
proverSpeed *prometheus.GaugeVec
75+
provingTime prometheus.Gauge
76+
evm_cycle_per_gas prometheus.Gauge
7477

7578
ChunkTask provertask.ProverTask
7679
BundleTask provertask.ProverTask
@@ -79,6 +82,7 @@ type ProofReceiverLogic struct {
7982

8083
// NewSubmitProofReceiverLogic create a proof receiver logic
8184
func NewSubmitProofReceiverLogic(cfg *config.ProverManager, chainCfg *params.ChainConfig, db *gorm.DB, vf *verifier.Verifier, reg prometheus.Registerer) *ProofReceiverLogic {
85+
8286
return &ProofReceiverLogic{
8387
chunkOrm: orm.NewChunk(db),
8488
batchOrm: orm.NewBatch(db),
@@ -133,6 +137,18 @@ func NewSubmitProofReceiverLogic(cfg *config.ProverManager, chainCfg *params.Cha
133137
Name: "coordinator_validate_failure_submit_have_been_verifier",
134138
Help: "Total number of submit proof validate failure proof have been verifier.",
135139
}),
140+
evm_cycle_per_gas: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
141+
Name: "evm_circuit_cycle_per_gas",
142+
Help: "VM cycles cost for a gas unit cost in evm execution",
143+
}),
144+
provingTime: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
145+
Name: "chunk_proving_time",
146+
Help: "Wall clock time for chunk proving in second",
147+
}),
148+
proverSpeed: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
149+
Name: "prover_speed",
150+
Help: "Cycle against running time of prover (in mhz)",
151+
}, []string{"type", "phase"}),
136152
}
137153
}
138154

@@ -204,12 +220,32 @@ func (m *ProofReceiverLogic) HandleZkProof(ctx *gin.Context, proofParameter coor
204220
return unmarshalErr
205221
}
206222
success, verifyErr = m.verifier.VerifyChunkProof(chunkProof, hardForkName)
223+
if stat := chunkProof.VmProof.Stat; stat != nil {
224+
if g, _ := m.proverSpeed.GetMetricWithLabelValues("chunk", "exec"); g != nil {
225+
g.Set(float64(stat.TotalCycle) / float64(stat.ExecutionTimeMills*1000))
226+
}
227+
if g, _ := m.proverSpeed.GetMetricWithLabelValues("chunk", "proving"); g != nil {
228+
g.Set(float64(stat.TotalCycle) / float64(stat.ProvingTimeMills*1000))
229+
}
230+
cycle_per_gas := float64(stat.TotalCycle) / float64(chunkProof.MetaData.TotalGasUsed)
231+
m.evm_cycle_per_gas.Set(cycle_per_gas)
232+
m.provingTime.Set(float64(stat.ProvingTimeMills) / 1000)
233+
}
234+
207235
case message.ProofTypeBatch:
208236
batchProof := &message.OpenVMBatchProof{}
209237
if unmarshalErr := json.Unmarshal([]byte(proofParameter.Proof), &batchProof); unmarshalErr != nil {
210238
return unmarshalErr
211239
}
212240
success, verifyErr = m.verifier.VerifyBatchProof(batchProof, hardForkName)
241+
if stat := batchProof.VmProof.Stat; stat != nil {
242+
if g, _ := m.proverSpeed.GetMetricWithLabelValues("batch", "exec"); g != nil {
243+
g.Set(float64(stat.TotalCycle) / float64(stat.ExecutionTimeMills*1000))
244+
}
245+
if g, _ := m.proverSpeed.GetMetricWithLabelValues("batch", "proving"); g != nil {
246+
g.Set(float64(stat.TotalCycle) / float64(stat.ProvingTimeMills*1000))
247+
}
248+
}
213249
case message.ProofTypeBundle:
214250
bundleProof := &message.OpenVMBundleProof{}
215251
if unmarshalErr := json.Unmarshal([]byte(proofParameter.Proof), &bundleProof); unmarshalErr != nil {

coordinator/test/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ func testTimeoutProof(t *testing.T) {
584584
err = chunkOrm.UpdateBatchHashInRange(context.Background(), 0, 100, batch.Hash)
585585
assert.NoError(t, err)
586586
encodeData, err := json.Marshal(message.OpenVMChunkProof{VmProof: &message.OpenVMProof{}, MetaData: struct {
587-
ChunkInfo *message.ChunkInfo `json:"chunk_info"`
587+
ChunkInfo *message.ChunkInfo `json:"chunk_info"`
588+
TotalGasUsed uint64 `json:"chunk_total_gas"`
588589
}{ChunkInfo: &message.ChunkInfo{}}})
589590
assert.NoError(t, err)
590591
assert.NotEmpty(t, encodeData)

crates/libzkp/src/proofs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub trait PersistableProof: Sized {
122122
pub struct ChunkProofMetadata {
123123
/// The chunk information describing the list of blocks contained within the chunk.
124124
pub chunk_info: ChunkInfo,
125+
/// Additional data for stat
126+
pub chunk_total_gas: u64,
125127
}
126128

127129
impl ProofMetadata for ChunkProofMetadata {

crates/libzkp/src/tasks.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ pub fn gen_universal_chunk_task(
4444
if let Some(interpreter) = interpreter {
4545
task.prepare_task_via_interpret(interpreter)?;
4646
}
47+
let chunk_total_gas = task.stats().total_gas_used;
4748
let chunk_info = task.precheck_and_build_metadata()?;
4849
let proving_task = task.try_into()?;
4950
let expected_pi_hash = chunk_info.pi_hash_by_fork(fork_name);
5051
Ok((
5152
expected_pi_hash,
52-
ChunkProofMetadata { chunk_info },
53+
ChunkProofMetadata {
54+
chunk_info,
55+
chunk_total_gas,
56+
},
5357
proving_task,
5458
))
5559
}

0 commit comments

Comments
 (0)