Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nil dereferencing, upgrade retry log info #915

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions app/clients/evm/client_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ package evm
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"math/big"
"reflect"
"runtime"
"strings"

log "github.com/sirupsen/logrus"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -72,6 +76,7 @@ func (cp *ClientPool) getClient(idx int) (client.EVM, config.Evm) {

func (cp *ClientPool) retryOperation(operation func(client.EVM) (interface{}, error)) (interface{}, error) {
var err error
operationName := getOperationName(operation)
for i := 0; i < cp.retries; i++ {
client, clientConfig := cp.getClient(i)
result, e := operation(client)
Expand All @@ -82,7 +87,7 @@ func (cp *ClientPool) retryOperation(operation func(client.EVM) (interface{}, er
cp.logger.WithFields(log.Fields{
"nodeUrl": clientConfig.NodeUrl,
"retries": i,
}).Warn("retry operation failed")
}).Warnf("retry operation [%s] failed", operationName)
err = e
}

Expand Down Expand Up @@ -357,3 +362,13 @@ func (cp *ClientPool) BlockConfirmations() uint64 {
func (cp *ClientPool) GetBlockTimestamp(blockNumber *big.Int) uint64 {
return cp.clients[0].GetBlockTimestamp(blockNumber)
}

// getOperationName finds function name using reflexion
func getOperationName(operation func(client.EVM) (interface{}, error)) string {
rv := reflect.ValueOf(operation)
operationPtr := rv.Pointer()
operationObj := runtime.FuncForPC(operationPtr)
operationNameArgs := strings.Split(operationObj.Name(), ".")
operationName := operationNameArgs[len(operationNameArgs)-2]
return operationName
}
5 changes: 3 additions & 2 deletions app/services/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package assets
import (
"errors"
"fmt"
"github.com/limechain/hedera-eth-bridge-validator/app/helper/fee"
"math/big"
"regexp"
"strconv"

"github.com/limechain/hedera-eth-bridge-validator/app/helper/fee"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/gookit/event"
Expand Down Expand Up @@ -550,7 +551,7 @@ func initialize(networks map[uint64]*parser.Network, bridgeAccountId string, Hed
if exist {
tokenFeeData, err := routerClient.TokenFeeData(&bind.CallOpts{}, common.HexToAddress(nativeAsset))
if err != nil {
log.Fatalf("Failed to get fee persentage from router contact for asset [%s]. Error: [%s]", nativeAsset, err)
log.Fatalf("Failed to get fee percentage from router contact for asset [%s]. Error: [%s]", nativeAsset, err)
}
feePercentage = tokenFeeData.ServiceFeePercentage.Int64()
}
Expand Down
Loading