fix contract-watcher processing (#531)

Co-authored-by: walker-16 <agpazos85@gmail.com>
This commit is contained in:
ftocal 2023-07-13 12:06:46 -03:00 committed by GitHub
parent 55d4b352ca
commit 50774265ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 25 deletions

View File

@ -211,7 +211,7 @@ func newWatchersForMainnet() *watchersConfig {
evm: 1000, evm: 1000,
solana: 3, solana: 3,
terra: 10, terra: 10,
aptos: 3, aptos: 20,
oasis: 3, oasis: 3,
moonbeam: 5, moonbeam: 5,
celo: 3, celo: 3,

View File

@ -88,7 +88,7 @@ func (w *AptosWatcher) Start(ctx context.Context) error {
w.logger.Error("cannot get latest block", zap.Error(err)) w.logger.Error("cannot get latest block", zap.Error(err))
} }
maxBlocks := uint64(w.sizeBlocks) maxBlocks := uint64(w.sizeBlocks)
w.logger.Info("current block", zap.Uint64("current", currentBlock), zap.Uint64("last", lastBlock)) w.logger.Debug("current block", zap.Uint64("current", currentBlock), zap.Uint64("last", lastBlock))
w.metrics.SetLastBlock(w.chainID, lastBlock) w.metrics.SetLastBlock(w.chainID, lastBlock)
if currentBlock < lastBlock { if currentBlock < lastBlock {
totalBlocks := (lastBlock-currentBlock)/maxBlocks + 1 totalBlocks := (lastBlock-currentBlock)/maxBlocks + 1
@ -98,13 +98,13 @@ func (w *AptosWatcher) Start(ctx context.Context) error {
if toBlock > lastBlock { if toBlock > lastBlock {
toBlock = lastBlock toBlock = lastBlock
} }
w.logger.Info("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
w.processBlock(ctx, fromBlock, toBlock, true) w.processBlock(ctx, fromBlock, toBlock, true)
w.logger.Info("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
} }
// process all the blocks between current and last block. // process all the blocks between current and last block.
} else { } else {
w.logger.Info("waiting for new blocks") w.logger.Debug("waiting for new blocks")
select { select {
case <-ctx.Done(): case <-ctx.Done():
w.wg.Done() w.wg.Done()
@ -112,7 +112,9 @@ func (w *AptosWatcher) Start(ctx context.Context) error {
case <-time.After(time.Duration(w.waitSeconds) * time.Second): case <-time.After(time.Duration(w.waitSeconds) * time.Second):
} }
} }
currentBlock = lastBlock if lastBlock > currentBlock {
currentBlock = lastBlock
}
} }
} }
} }

View File

@ -81,19 +81,20 @@ func (w *EvmStandarWatcher) Start(ctx context.Context) error {
if err != nil { if err != nil {
w.logger.Error("cannot get latest block", zap.Error(err)) w.logger.Error("cannot get latest block", zap.Error(err))
} }
w.logger.Info("current block", zap.Uint64("current", currentBlock), zap.Uint64("last", lastBlock)) w.logger.Debug("current block", zap.Uint64("current", currentBlock), zap.Uint64("last", lastBlock))
w.metrics.SetLastBlock(w.chainID, lastBlock) w.metrics.SetLastBlock(w.chainID, lastBlock)
if currentBlock < lastBlock { if currentBlock < lastBlock {
totalBlocks := getTotalBlocks(lastBlock, currentBlock, w.maxBlocks) totalBlocks := getTotalBlocks(lastBlock, currentBlock, w.maxBlocks)
for i := uint64(0); i < totalBlocks; i++ { for i := uint64(0); i < totalBlocks; i++ {
fromBlock, toBlock := getPage(currentBlock, i, w.maxBlocks, lastBlock) fromBlock, toBlock := getPage(currentBlock, i, w.maxBlocks, lastBlock)
w.logger.Info("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
w.processBlock(ctx, fromBlock, toBlock, true) w.processBlock(ctx, fromBlock, toBlock, true)
w.logger.Info("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
} }
// process all the blocks between current and last block. // process all the blocks between current and last block.
} else { } else {
w.logger.Info("waiting for new blocks") w.logger.Debug("waiting for new blocks")
select { select {
case <-ctx.Done(): case <-ctx.Done():
w.wg.Done() w.wg.Done()
@ -101,7 +102,9 @@ func (w *EvmStandarWatcher) Start(ctx context.Context) error {
case <-time.After(time.Duration(w.waitSeconds) * time.Second): case <-time.After(time.Duration(w.waitSeconds) * time.Second):
} }
} }
currentBlock = lastBlock if lastBlock > currentBlock {
currentBlock = lastBlock
}
} }
} }

View File

@ -91,13 +91,13 @@ func (w *EVMWatcher) Start(ctx context.Context) error {
if toBlock > lastBlock { if toBlock > lastBlock {
toBlock = lastBlock toBlock = lastBlock
} }
w.logger.Info("processing blocks", zap.Int64("from", fromBlock), zap.Int64("to", toBlock)) w.logger.Debug("processing blocks", zap.Int64("from", fromBlock), zap.Int64("to", toBlock))
w.processBlock(ctx, fromBlock, toBlock, true) w.processBlock(ctx, fromBlock, toBlock, true)
w.logger.Info("blocks processed", zap.Int64("from", fromBlock), zap.Int64("to", toBlock)) w.logger.Debug("blocks processed", zap.Int64("from", fromBlock), zap.Int64("to", toBlock))
} }
// process all the blocks between current and last block. // process all the blocks between current and last block.
} else { } else {
w.logger.Info("waiting for new blocks") w.logger.Debug("waiting for new blocks")
select { select {
case <-ctx.Done(): case <-ctx.Done():
w.wg.Done() w.wg.Done()
@ -105,7 +105,9 @@ func (w *EVMWatcher) Start(ctx context.Context) error {
case <-time.After(time.Duration(w.waitSeconds) * time.Second): case <-time.After(time.Duration(w.waitSeconds) * time.Second):
} }
} }
currentBlock = lastBlock if lastBlock > currentBlock {
currentBlock = lastBlock
}
} }
} }

View File

@ -142,7 +142,7 @@ func (w *SolanaWatcher) Start(ctx context.Context) error {
maxBlocks := uint64(w.sizeBlocks) maxBlocks := uint64(w.sizeBlocks)
w.metrics.SetLastBlock(w.chainID, lastBlock) w.metrics.SetLastBlock(w.chainID, lastBlock)
if currentBlock < lastBlock { if currentBlock < lastBlock {
w.logger.Info("current block", zap.Uint64("current", currentBlock), zap.Uint64("last", lastBlock)) w.logger.Debug("current block", zap.Uint64("current", currentBlock), zap.Uint64("last", lastBlock))
totalBlocks := (lastBlock-currentBlock)/maxBlocks + 1 totalBlocks := (lastBlock-currentBlock)/maxBlocks + 1
for i := 0; i < int(totalBlocks); i++ { for i := 0; i < int(totalBlocks); i++ {
fromBlock := currentBlock + uint64(i)*maxBlocks fromBlock := currentBlock + uint64(i)*maxBlocks
@ -150,13 +150,13 @@ func (w *SolanaWatcher) Start(ctx context.Context) error {
if toBlock > lastBlock { if toBlock > lastBlock {
toBlock = lastBlock toBlock = lastBlock
} }
w.logger.Info("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
w.processBlock(ctx, fromBlock, toBlock, true) w.processBlock(ctx, fromBlock, toBlock, true)
w.logger.Info("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
} }
// process all the blocks between current and last block. // process all the blocks between current and last block.
} else { } else {
w.logger.Info("waiting for new blocks") w.logger.Debug("waiting for new blocks")
select { select {
case <-ctx.Done(): case <-ctx.Done():
w.wg.Done() w.wg.Done()
@ -164,7 +164,9 @@ func (w *SolanaWatcher) Start(ctx context.Context) error {
case <-time.After(time.Duration(w.waitSeconds) * time.Second): case <-time.After(time.Duration(w.waitSeconds) * time.Second):
} }
} }
currentBlock = lastBlock if lastBlock > currentBlock {
currentBlock = lastBlock
}
} }
} }
} }

View File

@ -99,7 +99,7 @@ func (w *TerraWatcher) Start(ctx context.Context) error {
w.metrics.SetLastBlock(w.chainID, uint64(lastBlock)) w.metrics.SetLastBlock(w.chainID, uint64(lastBlock))
// check if there are new blocks to process. // check if there are new blocks to process.
if currentBlock < lastBlock { if currentBlock < lastBlock {
w.logger.Info("processing blocks", zap.Int64("from", currentBlock), zap.Int64("to", lastBlock)) w.logger.Debug("processing blocks", zap.Int64("from", currentBlock), zap.Int64("to", lastBlock))
for block := currentBlock; block <= lastBlock; block++ { for block := currentBlock; block <= lastBlock; block++ {
w.processBlock(ctx, block) w.processBlock(ctx, block)
// update block watcher // update block watcher
@ -119,7 +119,9 @@ func (w *TerraWatcher) Start(ctx context.Context) error {
case <-time.After(time.Duration(w.waitSeconds) * time.Second): case <-time.After(time.Duration(w.waitSeconds) * time.Second):
} }
} }
currentBlock = lastBlock if lastBlock > currentBlock {
currentBlock = lastBlock
}
} }
} }
} }
@ -128,7 +130,7 @@ func (w *TerraWatcher) Backfill(ctx context.Context, fromBlock uint64, toBlock u
totalBlocks := getTotalBlocks(toBlock, fromBlock, pageSize) totalBlocks := getTotalBlocks(toBlock, fromBlock, pageSize)
for i := uint64(0); i < totalBlocks; i++ { for i := uint64(0); i < totalBlocks; i++ {
fromBlock, toBlock := getPage(fromBlock, i, pageSize, toBlock) fromBlock, toBlock := getPage(fromBlock, i, pageSize, toBlock)
w.logger.Info("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("processing blocks", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
for block := fromBlock; block <= toBlock; block++ { for block := fromBlock; block <= toBlock; block++ {
w.processBlock(ctx, int64(block)) w.processBlock(ctx, int64(block))
if persistBlock { if persistBlock {
@ -141,7 +143,7 @@ func (w *TerraWatcher) Backfill(ctx context.Context, fromBlock uint64, toBlock u
w.repository.UpdateWatcherBlock(ctx, w.chainID, watcherBlock) w.repository.UpdateWatcherBlock(ctx, w.chainID, watcherBlock)
} }
} }
w.logger.Info("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock)) w.logger.Debug("blocks processed", zap.Uint64("from", fromBlock), zap.Uint64("to", toBlock))
} }
} }

View File

@ -39,4 +39,6 @@ spec:
- --vaa-payload-parser-timeout - --vaa-payload-parser-timeout
- "{{ .VAA_PAYLOAD_PARSER_TIMEOUT }}" - "{{ .VAA_PAYLOAD_PARSER_TIMEOUT }}"
- --page-size - --page-size
- "50" - "50"
- --start-time
- "2018-01-01T00:00:00Z"