Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Proof Cleaning #105

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a return for this err?

Copy link
Contributor Author

@ToniRamirezM ToniRamirezM Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function does not return error. The idea is if it fails here, do another iteration of the loop.

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
Loading