Skip to content

Commit

Permalink
Merge pull request #133 from InjectiveLabs/fix/logging-and-redundant-…
Browse files Browse the repository at this point in the history
…code

chore: remove obsolete auto sync and improve error logs
  • Loading branch information
dbrajovic authored Jan 17, 2025
2 parents ab785ab + c62d464 commit 8cc2efd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 42 deletions.
10 changes: 5 additions & 5 deletions orchestrator/ethereum/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (n *network) GetSendToCosmosEvents(startBlock, endBlock uint64) ([]*peggyev
}, nil, nil, nil)
if err != nil {
if !isUnknownBlockErr(err) {
return nil, errors.Wrap(err, "failed to scan past SendToCosmos events from Ethereum")
return nil, errors.Wrapf(err, "failed to scan past SendToCosmos events from Ethereum (%d - %d)", startBlock, endBlock)
} else if iter == nil {
return nil, errors.New("no iterator returned")
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (n *network) GetSendToInjectiveEvents(startBlock, endBlock uint64) ([]*pegg
}, nil, nil, nil)
if err != nil {
if !isUnknownBlockErr(err) {
return nil, errors.Wrap(err, "failed to scan past SendToCosmos events from Ethereum")
return nil, errors.Wrapf(err, "failed to scan past SendToInjectiveEvent events from Ethereum (%d - %d)", startBlock, endBlock)
} else if iter == nil {
return nil, errors.New("no iterator returned")
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func (n *network) GetPeggyERC20DeployedEvents(startBlock, endBlock uint64) ([]*p
}, nil)
if err != nil {
if !isUnknownBlockErr(err) {
return nil, errors.Wrap(err, "failed to scan past TransactionBatchExecuted events from Ethereum")
return nil, errors.Wrapf(err, "failed to scan past ERC20DeployedEvent events from Ethereum (%d - %d)", startBlock, endBlock)
} else if iter == nil {
return nil, errors.New("no iterator returned")
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func (n *network) GetValsetUpdatedEvents(startBlock, endBlock uint64) ([]*peggye
}, nil)
if err != nil {
if !isUnknownBlockErr(err) {
return nil, errors.Wrap(err, "failed to scan past ValsetUpdatedEvent events from Ethereum")
return nil, errors.Wrapf(err, "failed to scan past ValsetUpdatedEvent events from Ethereum (%d - %d)", startBlock, endBlock)
} else if iter == nil {
return nil, errors.New("no iterator returned")
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func (n *network) GetTransactionBatchExecutedEvents(startBlock, endBlock uint64)
}, nil, nil)
if err != nil {
if !isUnknownBlockErr(err) {
return nil, errors.Wrap(err, "failed to scan past TransactionBatchExecuted events from Ethereum")
return nil, errors.Wrapf(err, "failed to scan past TransactionBatchExecuted events from Ethereum (%d - %d)", startBlock, endBlock)
} else if iter == nil {
return nil, errors.New("no iterator returned")
}
Expand Down
42 changes: 5 additions & 37 deletions orchestrator/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ const (
// the oracle loop can potentially run longer than defaultLoopDur due to a surge of events. This usually happens
// when there are more than ~50 events to claim in a single run.
defaultBlocksToSearch uint64 = 2000

// Auto re-sync to catch up the validator's last observed event nonce. Reasons why event nonce fall behind:
// 1. It takes some time for events to be indexed on Ethereum. So if peggo queried events immediately as block produced, there is a chance the event is missed.
// We need to re-scan this block to ensure events are not missed due to indexing delay.
// 2. if validator was in UnBonding state, the claims broadcasted in last iteration are failed.
// 3. if infura call failed while filtering events, the peggo missed to broadcast claim events occured in last iteration.
resyncInterval = 24 * time.Hour
)

// runOracle is responsible for making sure that Ethereum events are retrieved from the Ethereum blockchain
Expand Down Expand Up @@ -138,12 +131,6 @@ func (l *oracle) observeEthEvents(ctx context.Context) error {
l.Log().WithFields(log.Fields{"claims": len(newEvents), "eth_block_start": l.lastObservedEthHeight, "eth_block_end": latestHeight}).Infoln("sent new event claims to Injective")
l.lastObservedEthHeight = latestHeight

if time.Since(l.lastResyncWithInjective) >= resyncInterval {
if err := l.autoResync(ctx); err != nil {
return err
}
}

return nil
}

Expand All @@ -154,27 +141,27 @@ func (l *oracle) getEthEvents(ctx context.Context, startBlock, endBlock uint64)

oldDepositEvents, err := l.ethereum.GetSendToCosmosEvents(startBlock, endBlock)
if err != nil {
return errors.Wrap(err, "failed to get SendToCosmos events")
return err
}

depositEvents, err := l.ethereum.GetSendToInjectiveEvents(startBlock, endBlock)
if err != nil {
return errors.Wrap(err, "failed to get SendToInjective events")
return err
}

withdrawalEvents, err := l.ethereum.GetTransactionBatchExecutedEvents(startBlock, endBlock)
if err != nil {
return errors.Wrap(err, "failed to get TransactionBatchExecuted events")
return err
}

erc20DeploymentEvents, err := l.ethereum.GetPeggyERC20DeployedEvents(startBlock, endBlock)
if err != nil {
return errors.Wrap(err, "failed to get ERC20Deployed events")
return err
}

valsetUpdateEvents, err := l.ethereum.GetValsetUpdatedEvents(startBlock, endBlock)
if err != nil {
return errors.Wrap(err, "failed to get ValsetUpdated events")
return err
}

for _, e := range oldDepositEvents {
Expand Down Expand Up @@ -278,25 +265,6 @@ func (l *oracle) sendNewEventClaims(ctx context.Context, events []event) error {
return nil
}

func (l *oracle) autoResync(ctx context.Context) error {
var height uint64
fn := func() (err error) {
height, err = l.getLastClaimBlockHeight(ctx, l.injective)
return
}

if err := l.retry(ctx, fn); err != nil {
return err
}

l.Log().WithFields(log.Fields{"last_resync": l.lastResyncWithInjective.String(), "last_claimed_eth_height": height}).Infoln("auto resyncing with last claimed event on Injective")

l.lastObservedEthHeight = height
l.lastResyncWithInjective = time.Now()

return nil
}

func (l *oracle) sendEthEventClaim(ctx context.Context, ev event) error {
switch e := ev.(type) {
case *oldDeposit:
Expand Down

0 comments on commit 8cc2efd

Please sign in to comment.