Skip to content

Commit

Permalink
Make some changes for fault tolerance (#2642)
Browse files Browse the repository at this point in the history
  • Loading branch information
af-afk authored May 10, 2024
1 parent dcf6d18 commit f82da24
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
13 changes: 11 additions & 2 deletions cmd/microservice-ethereum-application-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ func main() {
volume = feeData.Volume
)

log.Debugf(
"Got the application data %v for the transaction hash %v, and the fee %v, and the volume %v",
appData,
transfer.TransactionHash,
fee,
volume,
)


if err != nil {
log.Fatal(func(k *log.Log) {
k.Message = "Failed to get the application fee for an application transfer!"
Expand All @@ -198,10 +207,10 @@ func main() {
utility, _ := utilities[normalisedAddress]

// we set the decorator if there's an app fee
if fee == nil {
if volume == nil {
log.App(func(k *log.Log) {
k.Format(
"Skipping an application transfer for transaction %#v and application %#v!",
"Skipping an application transfer for transaction %#v, and application %#v! .Volume was nil!",
transactionHash.String(),
transfer.Application,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func main() {

func protocolAllowed(application applications.Application) bool {
switch application {
case applications.ApplicationUniswapV3, applications.ApplicationTraderJoe, applications.ApplicationCamelotV3, applications.ApplicationJumper:
case applications.ApplicationUniswapV3, applications.ApplicationTraderJoe, applications.ApplicationCamelotV3, applications.ApplicationJumper, applications.ApplicationLifi:
return true
default:
return false
Expand Down
23 changes: 22 additions & 1 deletion cmd/microservice-ethereum-worker-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,22 @@ func main() {

// if the amount transferred was exactly 0, then we skip to the next transfer

log.Debugf(
"Transaction hash %v log index %v has a decorator that's nil? %v",
transfer.TransactionHash,
logIndex,
transfer.Decorator == nil,
)

if d := transfer.Decorator; d != nil {
log.Debugf(
"Transaction hash %v log index %v has a decorator volume %v",
transfer.TransactionHash,
logIndex,
transfer.Decorator.Volume,
)
}

if isDecoratedTransferZeroVolume(transfer) {
log.App(func(k *log.Log) {
k.Format(
Expand Down Expand Up @@ -716,7 +732,12 @@ func main() {
// check if we've processed this before as a final failsafe before we submit
// the balls via a message and store an emission

failsafe.CommitTransactionHashIndex(transactionHash, *logIndex)
failsafeOk := failsafe.CommitTransactionHashIndex(transactionHash, *logIndex)

if !failsafeOk {
// the function should log itself
continue
}

for _, payoutDetails := range payouts {

Expand Down
19 changes: 17 additions & 2 deletions common/ethereum/applications/lifi/lifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ func genericSwapCompleted(transfer worker.EthereumApplicationTransfer, fluidToke

fluidTransferAmount := new(big.Rat)

log.Debugf(
"LiFiGenericSwapCompleted for transaction hash %v transfer from asset ID: %v, to asset id: %v, fluid token contract %v",
transfer.TransactionHash,
fromAssetId,
toAssetId,
fluidTokenContract,
)

switch fluidTokenContract {
case fromAssetId:
fluidTransferAmount.Set(fromAmount)
Expand All @@ -226,7 +234,7 @@ func genericSwapCompleted(transfer worker.EthereumApplicationTransfer, fluidToke
decimalsRat := new(big.Rat).SetFloat64(decimalsAdjusted)

feeData.Volume = new(big.Rat).Quo(fluidTransferAmount, decimalsRat)
feeData.Fee = new(big.Rat).SetInt64(0)
feeData.Fee = big.NewRat(0, 1)

return feeData, nil
}
Expand Down Expand Up @@ -296,6 +304,13 @@ func swappedGeneric(transfer worker.EthereumApplicationTransfer, fluidTokenContr

fluidTransferAmount := new(big.Rat)

log.Debugf(
"LiFiSwappedGeneric transfer for transaction hash %v from asset ID: %v, to asset id: %v",
transfer.TransactionHash,
fromAssetId,
toAssetId,
)

switch fluidTokenContract {
case fromAssetId:
fluidTransferAmount.Set(fromAmount)
Expand All @@ -319,7 +334,7 @@ func swappedGeneric(transfer worker.EthereumApplicationTransfer, fluidTokenContr
decimalsRat := new(big.Rat).SetFloat64(decimalsAdjusted)

feeData.Volume = new(big.Rat).Quo(fluidTransferAmount, decimalsRat)
feeData.Fee = new(big.Rat).SetInt64(0)
feeData.Fee = big.NewRat(0, 1)

return feeData, nil
}
Expand Down
8 changes: 6 additions & 2 deletions lib/databases/postgres/failsafe/transaction_hash_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// logIndex, and the worker ID, forming a composite primary key
// that guarantees uniqueness. Will Fatal if the insertion fails, with a
// reason. Useful for identifying duplication-related issues.
func CommitTransactionHashIndex(transactionHash ethereum.Hash, logIndex misc.BigInt) {
func CommitTransactionHashIndex(transactionHash ethereum.Hash, logIndex misc.BigInt) (success bool) {
postgresClient := postgres.Client()

statementText := fmt.Sprintf(`
Expand All @@ -41,7 +41,7 @@ func CommitTransactionHashIndex(transactionHash ethereum.Hash, logIndex misc.Big
_, err := postgresClient.Exec(statementText, transactionHash, logIndex, workerId)

if err != nil {
log.Fatal(func(k *log.Log) {
log.App(func(k *log.Log) {
k.Context = Context

k.Format(
Expand All @@ -53,5 +53,9 @@ func CommitTransactionHashIndex(transactionHash ethereum.Hash, logIndex misc.Big

k.Payload = err
})

return false
}

return true
}

0 comments on commit f82da24

Please sign in to comment.