Skip to content

Commit

Permalink
guard against multiple deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 committed Jan 23, 2024
1 parent b0832e9 commit 6391083
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ func (ob *EVMChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint
}

// post to zetacore
guard := make(map[string]bool) // guard against multiple events in the same tx
beingScanned := uint64(0)
for _, event := range events {
// remember which block we are scanning (there could be multiple events in the same block)
Expand All @@ -1088,6 +1089,10 @@ func (ob *EVMChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint
"observeERC20Deposited: GetTransactionSender error for tx %s chain %d", tx.Hash().Hex(), ob.chain.ChainId)
return beingScanned - 1 // we have to re-scan from this block next time
}
if guard[event.Raw.TxHash.Hex()] {
ob.logger.ExternalChainWatcher.Warn().Msgf("more than one remote call event in a single tx %s; skip the rest", event.Raw.TxHash.Hex())
continue
}

msg := ob.GetInboundVoteMsgForDepositedEvent(event, sender)
if msg == nil {
Expand All @@ -1104,6 +1109,7 @@ func (ob *EVMChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint
"observeERC20Deposited: event detected in tx %s at height %d for chain %d, PostVoteInbound zeta tx: %s ballot %s",
event.Raw.TxHash.Hex(), event.Raw.BlockNumber, ob.chain.ChainId, zetaHash, ballot)
}
guard[event.Raw.TxHash.Hex()] = true
}
// successful processed all events in [startBlock, toBlock]
return toBlock
Expand Down

0 comments on commit 6391083

Please sign in to comment.