Skip to content

Commit

Permalink
delete moved code
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak committed Aug 21, 2024
1 parent 495cd08 commit f84439a
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions vms/evm/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package evm
import (
"context"
"fmt"
"math/big"
"time"

"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f84439a

Please sign in to comment.