From 6dd8f22d0f124527c0ad0fbfd72cbc4c46558aec Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 20 Nov 2024 17:12:16 +0200 Subject: [PATCH 1/3] fix: max backoff Signed-off-by: Ivan Ivanov --- account_balance_query_e2e_test.go | 1 + executable.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/account_balance_query_e2e_test.go b/account_balance_query_e2e_test.go index 5e7f5c07c..a0646209a 100644 --- a/account_balance_query_e2e_test.go +++ b/account_balance_query_e2e_test.go @@ -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) diff --git a/executable.go b/executable.go index b46f3b73d..3cb44c5cd 100644 --- a/executable.go +++ b/executable.go @@ -23,11 +23,10 @@ package hedera import ( "context" "encoding/hex" + "fmt" "strconv" "time" - "github.com/cenkalti/backoff/v4" - protobuf "google.golang.org/protobuf/proto" "github.com/pkg/errors" @@ -191,12 +190,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 @@ -213,11 +209,17 @@ 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 attempt > 0 && currentBackoff <= e.GetMaxBackoff() { + fmt.Println("currentBackoff: ", currentBackoff) + fmt.Println("max backoff", e.GetMaxBackoff()) + fmt.Println("----") + currentBackoff *= 2 + } if e.isTransaction() { if attempt > 0 && len(e.GetNodeAccountIDs()) > 1 { e.advanceRequest() From 69021c1ba6f4b1197da567faa3a67000bd7ed14a Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 20 Nov 2024 17:15:03 +0200 Subject: [PATCH 2/3] chore: go mod tidy Signed-off-by: Ivan Ivanov --- go.mod | 1 - go.sum | 2 -- tck/go.mod | 1 - tck/go.sum | 2 -- 4 files changed, 6 deletions(-) diff --git a/go.mod b/go.mod index 0802b15cd..f1430d805 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 00095c7da..c164e80af 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/tck/go.mod b/tck/go.mod index 9d482a5b2..4db46cef7 100644 --- a/tck/go.mod +++ b/tck/go.mod @@ -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 diff --git a/tck/go.sum b/tck/go.sum index 1bb948b69..9001f6ab4 100644 --- a/tck/go.sum +++ b/tck/go.sum @@ -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= From ffd417fe98b886be344c0e5ad64d06d6a9f76a73 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 22 Nov 2024 09:10:07 +0200 Subject: [PATCH 3/3] chore: fix docs Signed-off-by: Ivan Ivanov --- executable.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/executable.go b/executable.go index 3cb44c5cd..b9c5b959a 100644 --- a/executable.go +++ b/executable.go @@ -23,7 +23,6 @@ package hedera import ( "context" "encoding/hex" - "fmt" "strconv" "time" @@ -214,12 +213,11 @@ func _Execute(client *Client, e Executable) (interface{}, error) { 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() { - fmt.Println("currentBackoff: ", currentBackoff) - fmt.Println("max backoff", e.GetMaxBackoff()) - fmt.Println("----") currentBackoff *= 2 } + if e.isTransaction() { if attempt > 0 && len(e.GetNodeAccountIDs()) > 1 { e.advanceRequest()