Skip to content

Commit

Permalink
fix: max backoff (#1153)
Browse files Browse the repository at this point in the history
* fix: max backoff

Signed-off-by: Ivan Ivanov <[email protected]>

* chore: go mod tidy

Signed-off-by: Ivan Ivanov <[email protected]>

* chore: fix docs

Signed-off-by: Ivan Ivanov <[email protected]>

---------

Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov authored Nov 22, 2024
1 parent 599cdb1 commit ab13404
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions account_balance_query_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func TestIntegrationAccountBalanceQueryWorksWithHollowAccountAlias(t *testing.T)
}

func TestIntegrationAccountBalanceQueryCanConnectToMainnetTls(t *testing.T) {
t.Skip("AccountBalanceQuery is throttled on mainnet")
t.Parallel()
client := ClientForMainnet()
client.SetTransportSecurity(true)
Expand Down
14 changes: 7 additions & 7 deletions executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"strconv"
"time"

"github.com/cenkalti/backoff/v4"

protobuf "google.golang.org/protobuf/proto"

"github.com/pkg/errors"
Expand Down Expand Up @@ -191,12 +189,9 @@ func (e *executable) getNodeAccountID() AccountID {
return e.nodeAccountIDs._GetCurrent().(AccountID)
}

// nolint
func _Execute(client *Client, e Executable) (interface{}, error) {
var maxAttempts int
backOff := backoff.NewExponentialBackOff()
backOff.InitialInterval = e.GetMinBackoff()
backOff.MaxInterval = e.GetMaxBackoff()
backOff.Multiplier = 2

if client.maxAttempts != nil {
maxAttempts = *client.maxAttempts
Expand All @@ -213,11 +208,16 @@ func _Execute(client *Client, e Executable) (interface{}, error) {
txLogger := e.getLogger(client.logger)
txID, msg := e.getTransactionIDAndMessage()

for attempt = int64(0); attempt < int64(maxAttempts); attempt, currentBackoff = attempt+1, currentBackoff*2 {
for attempt = int64(0); attempt < int64(maxAttempts); attempt++ {
var protoRequest interface{}
var node *_Node
var ok bool

// If this is not the first attempt, double the backoff time up to the max backoff time
if attempt > 0 && currentBackoff <= e.GetMaxBackoff() {
currentBackoff *= 2
}

if e.isTransaction() {
if attempt > 0 && len(e.GetNodeAccountIDs()) > 1 {
e.advanceRequest()
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/cenkalti/backoff/v4 v4.3.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/json-iterator/go v1.1.12
github.com/mitchellh/mapstructure v1.5.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurT
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
1 change: 0 additions & 1 deletion tck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ replace github.com/hashgraph/hedera-sdk-go/v2 => ../

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/creachadair/mds v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions tck/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurT
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creachadair/jrpc2 v1.1.2 h1:UOYMipEFYlwd5qmcvs9GZBurn3oXt1UDIX5JLjWWFzo=
github.com/creachadair/jrpc2 v1.1.2/go.mod h1:JcCe2Eny3lIvVwZLm92WXyU+tNUgTBWFCLMsfNkjEGk=
Expand Down

0 comments on commit ab13404

Please sign in to comment.