diff --git a/vms/evm/subscriber.go b/vms/evm/subscriber.go index 196303af..605999de 100644 --- a/vms/evm/subscriber.go +++ b/vms/evm/subscriber.go @@ -6,7 +6,6 @@ package evm import ( "context" "fmt" - "math/big" "time" "github.com/ava-labs/avalanchego/ids" @@ -47,79 +46,6 @@ func NewSubscriber( } } -// Process logs from the given block height to the latest block. Limits the -// number of blocks retrieved in a single eth_getLogs request to -// `MaxBlocksPerRequest`; if processing more than that, multiple eth_getLogs -// requests will be made. -// Writes true to the done channel when finished, or false if an error occurs -func (s *subscriber) ProcessFromHeight(height *big.Int, done chan bool) { - defer close(done) - s.logger.Info( - "Processing historical logs", - zap.String("fromBlockHeight", height.String()), - zap.String("blockchainID", s.blockchainID.String()), - ) - if height == nil { - s.logger.Error("Cannot process logs from nil height") - done <- false - return - } - - // Grab the latest block before filtering logs so we don't miss any before updating the db - latestBlockHeight, err := s.ethClient.BlockNumber(context.Background()) - if err != nil { - s.logger.Error( - "Failed to get latest block", - zap.String("blockchainID", s.blockchainID.String()), - zap.Error(err), - ) - done <- false - return - } - - bigLatestBlockHeight := big.NewInt(0).SetUint64(latestBlockHeight) - - //nolint:lll - for fromBlock := big.NewInt(0).Set(height); fromBlock.Cmp(bigLatestBlockHeight) <= 0; fromBlock.Add(fromBlock, big.NewInt(MaxBlocksPerRequest)) { - toBlock := big.NewInt(0).Add(fromBlock, big.NewInt(MaxBlocksPerRequest-1)) - - // clamp to latest known block because we've already subscribed - // to new blocks and we don't want to double-process any blocks - // created after that subscription but before the determination - // of this "latest" - if toBlock.Cmp(bigLatestBlockHeight) > 0 { - toBlock.Set(bigLatestBlockHeight) - } - - err = s.processBlockRange(fromBlock, toBlock) - if err != nil { - s.logger.Error("Failed to process block range", zap.Error(err)) - done <- false - return - } - } - done <- true -} - -// Process Warp messages from the block range [fromBlock, toBlock], inclusive -func (s *subscriber) processBlockRange( - fromBlock, toBlock *big.Int, -) error { - for i := fromBlock.Int64(); i <= toBlock.Int64(); i++ { - header, err := s.ethClient.HeaderByNumber(context.Background(), big.NewInt(i)) - if err != nil { - s.logger.Error( - "Failed to get header by number", - zap.String("blockchainID", s.blockchainID.String()), - zap.Error(err), - ) - return err - } - s.headers <- header - } - return nil -} - // Loops forever iff maxResubscribeAttempts == 0 func (s *subscriber) Subscribe(maxResubscribeAttempts int) error { // Retry subscribing until successful. Attempt to resubscribe maxResubscribeAttempts times