From 84426bb4955b55af61fad238bed59d7f51b68260 Mon Sep 17 00:00:00 2001 From: Seri Choi Date: Wed, 12 Feb 2025 09:51:24 -0500 Subject: [PATCH] clean up --- pkg/indexer/indexer.go | 6 ++---- pkg/pipeline/pipeline.go | 24 ++++-------------------- pkg/storage/storage.go | 2 -- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/pkg/indexer/indexer.go b/pkg/indexer/indexer.go index 9b28a00e..f2bd6ff8 100644 --- a/pkg/indexer/indexer.go +++ b/pkg/indexer/indexer.go @@ -156,10 +156,7 @@ func (idx *Indexer) ParseInterestingTransactionsAndLogs(ctx context.Context, fet return parsedTransactions, nil } -// or should this be in transactionLogs.go? -// why do we need ctx context.Context and do we need it here? -func (idx *Indexer) IndexContractUpgrade(fetchedBlock *fetcher.FetchedBlock, upgradedLog *storage.TransactionLog) { - blockNumber := fetchedBlock.Block.Number.Value() +func (idx *Indexer) IndexContractUpgrade(ctx context.Context, blockNumber uint64, upgradedLog *storage.TransactionLog) error { // the new address that the contract points to newProxiedAddress := "" @@ -202,6 +199,7 @@ func (idx *Indexer) IndexContractUpgrade(fetchedBlock *fetcher.FetchedBlock, upg return } idx.Logger.Sugar().Infow("Upgraded proxy contract", zap.String("contractAddress", upgradedLog.Address), zap.String("proxyContractAddress", newProxiedAddress)) + return nil } func (idx *Indexer) IndexFetchedBlock(fetchedBlock *fetcher.FetchedBlock) (*storage.Block, bool, error) { diff --git a/pkg/pipeline/pipeline.go b/pkg/pipeline/pipeline.go index 58b78477..988e4317 100644 --- a/pkg/pipeline/pipeline.go +++ b/pkg/pipeline/pipeline.go @@ -118,7 +118,6 @@ func (p *Pipeline) RunForFetchedBlock(ctx context.Context, block *fetcher.Fetche // With only interesting transactions/logs parsed, insert them into the database indexedTransactions := make([]*storage.Transaction, 0) indexedTransactionLogs := make([]*storage.TransactionLog, 0) - contractUpgradedLogs := make([]*storage.TransactionLog, 0) blockFetchTime = time.Now() for _, pt := range parsedTransactions { transactionTime := time.Now() @@ -162,13 +161,6 @@ func (p *Pipeline) RunForFetchedBlock(ctx context.Context, block *fetcher.Fetche zap.String("transactionHash", indexedTransaction.TransactionHash), zap.Uint64("logIndex", log.LogIndex), ) - // block-lake/internal/indexer/indexer.go - // find contract upgraded logs here? - if log.EventName == "Upgraded" { - contractUpgradedLogs = append(contractUpgradedLogs, log) - // or maybe don't make it into a list and upgrade here directly - // idx.IndexContractUpgrade(blockNumber, log, reindexContract) - } if err := p.stateManager.HandleLogStateChange(indexedLog); err != nil { p.Logger.Sugar().Errorw("Failed to handle log state change", @@ -189,6 +181,10 @@ func (p *Pipeline) RunForFetchedBlock(ctx context.Context, block *fetcher.Fetche ) return err } + + if log.EventName == "Upgraded" { + p.Indexer.IndexContractUpgrade(ctx, blockNumber, log) + } } p.Logger.Sugar().Debugw("Handled log state changes", zap.Uint64("blockNumber", blockNumber), @@ -200,18 +196,6 @@ func (p *Pipeline) RunForFetchedBlock(ctx context.Context, block *fetcher.Fetche zap.Uint64("blockNumber", blockNumber), zap.Int64("indexTime", time.Since(blockFetchTime).Milliseconds()), ) - - if len(contractUpgradedLogs) > 0 { - p.Logger.Sugar().Debugw("Found contract upgrade logs", - zap.Uint64("blockNumber", blockNumber), - zap.String("transactionHash", indexedTransaction.TransactionHash), - zap.Uint64("count", len(contractUpgradedLogs)), - ) - if err := p.Indexer.IndexContractUpgrades(block.Block.Number.Value()); err != nil { - p.Logger.Sugar().Errorw("Failed to index contract upgrades", zap.Uint64("blockNumber", block.Block.Number.Value()), zap.Error(err)) - return err - } - } if block.Block.Number.Value()%3600 == 0 { p.Logger.Sugar().Infow("Indexing OperatorRestakedStrategies", zap.Uint64("blockNumber", block.Block.Number.Value())) diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index dfc02ae6..4bb22a92 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -71,8 +71,6 @@ type BatchTransaction struct { BytecodeHash string } -// do i need to add type here? - type OperatorRestakedStrategies struct { AvsDirectoryAddress string BlockNumber uint64