From a1addd7d8aee6ea1bff21d4fbd0e27157f086a09 Mon Sep 17 00:00:00 2001 From: NikolaMirchev Date: Mon, 18 Dec 2023 16:44:47 +0200 Subject: [PATCH] Added getLogID function back to query/transaction to match the new style Signed-off-by: NikolaMirchev --- ..._allowance_delete_transaction_unit_test.go | 1 - executable.go | 19 ++++++++++--------- query.go | 10 ++++++++++ transaction.go | 5 +++++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/account_allowance_delete_transaction_unit_test.go b/account_allowance_delete_transaction_unit_test.go index 7468555e5..2fd201f98 100644 --- a/account_allowance_delete_transaction_unit_test.go +++ b/account_allowance_delete_transaction_unit_test.go @@ -44,7 +44,6 @@ func TestUnitAccountAllowanceDeleteTransactionCoverage(t *testing.T) { SetRegenerateTransactionID(false). Freeze() require.NoError(t, err) - transaction.validateNetworkOnIDs(client) _, err = transaction.Schedule() diff --git a/executable.go b/executable.go index d047ea11d..4e6057d7d 100644 --- a/executable.go +++ b/executable.go @@ -69,6 +69,7 @@ type Executable interface { isTransaction() bool getLogger(Logger) Logger getTransactionIDAndMessage() (string, string) + getLogID(Executable) string // This returns transaction creation timestamp + transaction name } type executable struct { @@ -237,15 +238,15 @@ func _Execute(client *Client, e Executable) (interface{}, error) { node._InUse() - txLogger.Trace("executing", "requestId", e.getName(), "nodeAccountID", node.accountID.String(), "nodeIPAddress", node.address._String(), "Request Proto", hex.EncodeToString(marshaledRequest)) + txLogger.Trace("executing", "requestId", e.getLogID(e), "nodeAccountID", node.accountID.String(), "nodeIPAddress", node.address._String(), "Request Proto", hex.EncodeToString(marshaledRequest)) if !node._IsHealthy() { - txLogger.Trace("node is unhealthy, waiting before continuing", "requestId", e.getName(), "delay", node._Wait().String()) - _DelayForAttempt(e.getName(), backOff.NextBackOff(), attempt, txLogger) + txLogger.Trace("node is unhealthy, waiting before continuing", "requestId", e.getLogID(e), "delay", node._Wait().String()) + _DelayForAttempt(e.getLogID(e), backOff.NextBackOff(), attempt, txLogger) continue } - txLogger.Trace("updating node account ID index", "requestId", e.getName()) + txLogger.Trace("updating node account ID index", "requestId", e.getLogID(e)) channel, err := node._GetChannel(txLogger) if err != nil { client.network._IncreaseBackoff(node) @@ -266,7 +267,7 @@ func _Execute(client *Client, e Executable) (interface{}, error) { ctx, cancel = context.WithDeadline(ctx, grpcDeadline) } - txLogger.Trace("executing gRPC call", "requestId", e.getName()) + txLogger.Trace("executing gRPC call", "requestId", e.getLogID(e)) var marshaledResponse []byte if method.query != nil { @@ -286,7 +287,7 @@ func _Execute(client *Client, e Executable) (interface{}, error) { } if err != nil { errPersistent = err - if _ExecutableDefaultRetryHandler(e.getName(), err, txLogger) { + if _ExecutableDefaultRetryHandler(e.getLogID(e), err, txLogger) { client.network._IncreaseBackoff(node) continue } @@ -307,7 +308,7 @@ func _Execute(client *Client, e Executable) (interface{}, error) { txLogger.Trace( msg, - "requestID", e.getName(), + "requestID", e.getLogID(e), "nodeID", node.accountID.String(), "nodeAddress", node.address._String(), "nodeIsHealthy", strconv.FormatBool(node._IsHealthy()), @@ -319,13 +320,13 @@ func _Execute(client *Client, e Executable) (interface{}, error) { switch e.shouldRetry(e, resp) { case executionStateRetry: errPersistent = statusError - _DelayForAttempt(e.getName(), backOff.NextBackOff(), attempt, txLogger) + _DelayForAttempt(e.getLogID(e), backOff.NextBackOff(), attempt, txLogger) continue case executionStateExpired: if e.isTransaction() { transaction := e.(TransactionInterface) if transaction.regenerateID(client) { - txLogger.Trace("received `TRANSACTION_EXPIRED` with transaction ID regeneration enabled; regenerating", "requestId", e.getName()) + txLogger.Trace("received `TRANSACTION_EXPIRED` with transaction ID regeneration enabled; regenerating", "requestId", e.getLogID(e)) continue } else { return TransactionResponse{}, statusError diff --git a/query.go b/query.go index 9a6be4320..ebbd35b13 100644 --- a/query.go +++ b/query.go @@ -21,6 +21,7 @@ package hedera */ import ( + "fmt" "time" "github.com/hashgraph/hedera-protobufs-go/services" @@ -37,6 +38,7 @@ type Query struct { paymentTransactionIDs *_LockableSlice maxQueryPayment Hbar queryPayment Hbar + timestamp time.Time paymentTransactions []*services.Transaction @@ -348,6 +350,14 @@ func (q *Query) getName() string { return "QueryInterface" } +func (q *Query) getLogID(queryInterface Executable) string { + timestamp := q.timestamp.UnixNano() + if q.paymentTransactionIDs._Length() > 0 && q.paymentTransactionIDs._GetCurrent().(TransactionID).ValidStart != nil { + timestamp = q.paymentTransactionIDs._GetCurrent().(TransactionID).ValidStart.UnixNano() + } + return fmt.Sprintf("%s:%d", queryInterface.getName(), timestamp) +} + //lint:ignore U1000 func (q *Query) buildQuery() *services.Query { return nil diff --git a/transaction.go b/transaction.go index 7815f89d4..b1d1d2221 100644 --- a/transaction.go +++ b/transaction.go @@ -4739,6 +4739,11 @@ func (tx *Transaction) getName() string { return "transaction" } +func (tx *Transaction) getLogID(transactionInterface Executable) string { + timestamp := tx.transactionIDs._GetCurrent().(TransactionID).ValidStart + return fmt.Sprintf("%s:%d", transactionInterface.getName(), timestamp.UnixNano()) +} + // Building empty object as "default" implementation. All inhertents must implement their own implementation. func (tx *Transaction) validateNetworkOnIDs(client *Client) error { return errors.New("Function not implemented")