Skip to content

Commit

Permalink
Improve logs and fix RPC call for witness (#90)
Browse files Browse the repository at this point in the history
* feat: improve logs and fix witness RPC call
  • Loading branch information
ToniRamirezM authored Jun 26, 2024
1 parent ae50924 commit 17f0213
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,23 @@ func (a *Aggregator) handleReceivedDataStream(entry *datastreamer.FileEntry, cli
}
}

// If the batch is marked as Invalid in the DS we enforce retrieve the data from L1
if a.cfg.UseL1BatchData || a.currentStreamBatch.Type == datastream.BatchType_BATCH_TYPE_INVALID {
a.currentStreamBatch.BatchL2Data = virtualBatch.BatchL2Data
} else {
// Encode batch
if a.currentStreamBatch.Type != datastream.BatchType_BATCH_TYPE_INVALID {
batchl2Data, err = state.EncodeBatchV2(&a.currentStreamBatchRaw)
if err != nil {
log.Errorf("Error encoding batch: %v", err)
return err
}
}

// If the batch is marked as Invalid in the DS we enforce retrieve the data from L1
if a.cfg.UseL1BatchData || a.currentStreamBatch.Type == datastream.BatchType_BATCH_TYPE_INVALID {
a.currentStreamBatch.BatchL2Data = virtualBatch.BatchL2Data
} else {
a.currentStreamBatch.BatchL2Data = batchl2Data
}

// Compare BatchL2Data from L1 and DataStream
if common.Bytes2Hex(batchl2Data) != common.Bytes2Hex(virtualBatch.BatchL2Data) {
log.Warnf("BatchL2Data from L1 and data stream are different for batch %d", a.currentStreamBatch.BatchNumber)

Expand Down Expand Up @@ -1577,16 +1582,19 @@ func getWitness(batchNumber uint64, URL string, fullWitness bool) ([]byte, error
var response rpc.Response
var err error

witnessType := "trimmed"
if fullWitness {
response, err = rpc.JSONRPCCall(URL, "zkevm_getBatchWitness", "1", batchNumber, "full")
if err != nil {
return nil, err
}
} else {
response, err = rpc.JSONRPCCall(URL, "zkevm_getBatchWitness", "batch-1", batchNumber)
if err != nil {
return nil, err
}
witnessType = "full"
}

response, err = rpc.JSONRPCCall(URL, "zkevm_getBatchWitness", batchNumber, witnessType)
if err != nil {
return nil, err
}

// Check if the response is an error
if response.Error != nil {
return nil, fmt.Errorf("error from witness for batch %d: %v", batchNumber, response.Error)
}

err = json.Unmarshal(response.Result, &witness)
Expand Down

0 comments on commit 17f0213

Please sign in to comment.