Skip to content

Commit

Permalink
feat: Proof Cleaning (#105)
Browse files Browse the repository at this point in the history
* feat: proof cleaning

* feat: improve log
  • Loading branch information
ToniRamirezM authored Oct 4, 2024
1 parent 53f454e commit 34af8b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 42 deletions.
67 changes: 25 additions & 42 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
synclog "github.com/0xPolygonHermez/zkevm-synchronizer-l1/log"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/state/entities"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/synchronizer"
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/synchronizer/l1_check_block"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc"
Expand Down Expand Up @@ -991,7 +992,7 @@ func (a *Aggregator) settleDirect(

// process monitored batch verifications before starting a next cycle
a.ethTxManager.ProcessPendingMonitoredTxs(ctx, func(result ethtxtypes.MonitoredTxResult) {
a.handleMonitoredTxResult(result)
a.handleMonitoredTxResult(result, proof.BatchNumber, proof.BatchNumberFinal)
})

return true
Expand Down Expand Up @@ -1929,57 +1930,39 @@ func (hc *healthChecker) Watch(req *grpchealth.HealthCheckRequest, server grpche
})
}

func (a *Aggregator) handleMonitoredTxResult(result ethtxtypes.MonitoredTxResult) {
func (a *Aggregator) handleMonitoredTxResult(result ethtxtypes.MonitoredTxResult, firstBatch, lastBatch uint64) {
mTxResultLogger := ethtxmanager.CreateMonitoredTxResultLogger(result)
if result.Status == ethtxtypes.MonitoredTxStatusFailed {
mTxResultLogger.Fatal("failed to send batch verification, TODO: review this fatal and define what to do in this case")
}

// TODO: REVIEW THIS
// Wait for the transaction to be finalized, then we can safely delete all recursive
// proofs up to the last batch in this proof

/*
// monitoredIDFormat: "proof-from-%v-to-%v"
idSlice := strings.Split(result.ID, "-")
proofBatchNumberStr := idSlice[2]
proofBatchNumber, err := strconv.ParseUint(proofBatchNumberStr, encoding.Base10, 0)
if err != nil {
mTxResultLogger.Errorf("failed to read final proof batch number from monitored tx: %v", err)
}
proofBatchNumberFinalStr := idSlice[4]
proofBatchNumberFinal, err := strconv.ParseUint(proofBatchNumberFinalStr, encoding.Base10, 0)
if err != nil {
mTxResultLogger.Errorf("failed to read final proof batch number final from monitored tx: %v", err)
}
log := log.WithFields("txId", result.ID, "batches", fmt.Sprintf("%d-%d", proofBatchNumber, proofBatchNumberFinal))
log.Info("Final proof verified")
// wait for the synchronizer to catch up the verified batches
log.Debug("A final proof has been sent, waiting for the network to be synced")
for !a.isSynced(a.ctx, &proofBatchNumberFinal) {
log.Info("Waiting for synchronizer to sync...")
time.Sleep(a.cfg.RetryTime.Duration)
}
finaLizedBlockNumber, err := l1_check_block.L1FinalizedFetch.BlockNumber(a.ctx, a.etherman)
if err != nil {
mTxResultLogger.Errorf("failed to get finalized block number: %v", err)
}

// network is synced with the final proof, we can safely delete all recursive
// proofs up to the last synced batch
err = a.State.CleanupGeneratedProofs(a.ctx, proofBatchNumberFinal, nil)
for result.MinedAtBlockNumber.Uint64() > finaLizedBlockNumber {
select {
case <-a.ctx.Done():
return
case <-time.After(a.cfg.RetryTime.Duration):
finaLizedBlockNumber, err = l1_check_block.L1FinalizedFetch.BlockNumber(a.ctx, a.etherman)
if err != nil {
mTxResultLogger.Errorf("failed to get finalized block number: %v", err)
}
}
}

if err != nil {
log.Errorf("Failed to store proof aggregation result: %v", err)
}
*/
}
err = a.state.DeleteGeneratedProofs(a.ctx, firstBatch, lastBatch, nil)
if err != nil {
mTxResultLogger.Errorf("failed to delete generated proofs from %d to %d: %v", firstBatch, lastBatch, err)
}

/*
func buildMonitoredTxID(batchNumber, batchNumberFinal uint64) string {
return fmt.Sprintf(monitoredIDFormat, batchNumber, batchNumberFinal)
mTxResultLogger.Debugf("deleted generated proofs from %d to %d", firstBatch, lastBatch)
}
*/

func (a *Aggregator) cleanupLockedProofs() {
for {
Expand Down
1 change: 1 addition & 0 deletions aggregator/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type etherman interface {
) (to *common.Address, data []byte, err error)
GetLatestBlockHeader(ctx context.Context) (*types.Header, error)
GetBatchAccInputHash(ctx context.Context, batchNumber uint64) (common.Hash, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

// aggregatorTxProfitabilityChecker interface for different profitability
Expand Down

0 comments on commit 34af8b0

Please sign in to comment.