From f82da242c92fb5ab0e972c095357fb41362d3c6f Mon Sep 17 00:00:00 2001 From: Alex <71931113+af-afk@users.noreply.github.com> Date: Fri, 10 May 2024 17:10:00 +0100 Subject: [PATCH] Make some changes for fault tolerance (#2642) --- .../main.go | 13 +++++++++-- .../main.go | 2 +- .../main.go | 23 ++++++++++++++++++- common/ethereum/applications/lifi/lifi.go | 19 +++++++++++++-- .../failsafe/transaction_hash_index.go | 8 +++++-- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/cmd/microservice-ethereum-application-server/main.go b/cmd/microservice-ethereum-application-server/main.go index a152074e5..216ea27dc 100644 --- a/cmd/microservice-ethereum-application-server/main.go +++ b/cmd/microservice-ethereum-application-server/main.go @@ -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!" @@ -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, ) diff --git a/cmd/microservice-ethereum-create-transaction-lootboxes/main.go b/cmd/microservice-ethereum-create-transaction-lootboxes/main.go index 22eca440c..fe6bd5fca 100644 --- a/cmd/microservice-ethereum-create-transaction-lootboxes/main.go +++ b/cmd/microservice-ethereum-create-transaction-lootboxes/main.go @@ -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 diff --git a/cmd/microservice-ethereum-worker-server/main.go b/cmd/microservice-ethereum-worker-server/main.go index f4c917ba9..7a095bd24 100644 --- a/cmd/microservice-ethereum-worker-server/main.go +++ b/cmd/microservice-ethereum-worker-server/main.go @@ -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( @@ -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 { diff --git a/common/ethereum/applications/lifi/lifi.go b/common/ethereum/applications/lifi/lifi.go index cbcca4f40..4bd709840 100644 --- a/common/ethereum/applications/lifi/lifi.go +++ b/common/ethereum/applications/lifi/lifi.go @@ -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) @@ -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 } @@ -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) @@ -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 } diff --git a/lib/databases/postgres/failsafe/transaction_hash_index.go b/lib/databases/postgres/failsafe/transaction_hash_index.go index 92884ba7d..33a6f0aae 100644 --- a/lib/databases/postgres/failsafe/transaction_hash_index.go +++ b/lib/databases/postgres/failsafe/transaction_hash_index.go @@ -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(` @@ -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( @@ -53,5 +53,9 @@ func CommitTransactionHashIndex(transactionHash ethereum.Hash, logIndex misc.Big k.Payload = err }) + + return false } + + return true }