Skip to content

Commit

Permalink
Added getLogID function back to query/transaction to match the new style
Browse files Browse the repository at this point in the history
Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>
  • Loading branch information
NikolaMirchev committed Dec 18, 2023
1 parent 6e73369 commit a1addd7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 0 additions & 1 deletion account_allowance_delete_transaction_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestUnitAccountAllowanceDeleteTransactionCoverage(t *testing.T) {
SetRegenerateTransactionID(false).
Freeze()
require.NoError(t, err)

transaction.validateNetworkOnIDs(client)

_, err = transaction.Schedule()
Expand Down
19 changes: 10 additions & 9 deletions executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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()),
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package hedera
*/

import (
"fmt"
"time"

"github.com/hashgraph/hedera-protobufs-go/services"
Expand All @@ -37,6 +38,7 @@ type Query struct {
paymentTransactionIDs *_LockableSlice
maxQueryPayment Hbar
queryPayment Hbar
timestamp time.Time

paymentTransactions []*services.Transaction

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a1addd7

Please sign in to comment.