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

Added missing fields on the transaction/pool by-sender request #6039

Merged
merged 7 commits into from
Mar 14, 2024

Conversation

sstanculeanu
Copy link
Collaborator

@sstanculeanu sstanculeanu commented Mar 11, 2024

Reasoning behind the pull request

  • missing fields in response of /transaction/pool by sender

Proposed changes

  • added new fields which can be requested: guardian, guardiansignature, signature, sendershard, receivershard and wildcard * which will return all fields as in the next picture
    image

Testing procedure

  • will be tested with proxy branch support_for_tx_pool_wild_card
  • standard system test + scenario:
    • add 2 transactions in pool for a sender, one guarded and another one not guarded. Then check /transaction/pool?by-sender=erd1....&fields= with the new fields.
    • also check that a combination of fields and wildcard is not possible. Eg fields=nonce,*

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.93%. Comparing base (164da49) to head (6d6332c).

Additional details and impacted files
@@                Coverage Diff                @@
##           rc/v1.7.next1    #6039      +/-   ##
=================================================
+ Coverage          79.88%   79.93%   +0.04%     
=================================================
  Files                731      731              
  Lines              96234    96250      +16     
=================================================
+ Hits               76874    76934      +60     
+ Misses             13966    13927      -39     
+ Partials            5394     5389       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iulianpascalau iulianpascalau self-requested a review March 11, 2024 15:12
iulianpascalau
iulianpascalau previously approved these changes Mar 11, 2024
@sstanculeanu sstanculeanu changed the title Added guardian as field on the transaction/pool by-sender request Added missing fields on the transaction/pool by-sender request Mar 11, 2024
iulianpascalau
iulianpascalau previously approved these changes Mar 11, 2024
}
return ph
}

func shouldConsiderField(parametersMap map[string]struct{}, field string) bool {
_, has := parametersMap[field]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slight optimization:

_, hasWildCard := parametersMap[wildCard]
if hasWildCard {
    return true
}

_, has := parametersMap[field]
return has

bogdan-rosianu
bogdan-rosianu previously approved these changes Mar 12, 2024
bogdan-rosianu
bogdan-rosianu previously approved these changes Mar 12, 2024
return tx
}

func (atp *apiTransactionProcessor) getFieldGettersForTx(wrappedTx *txcache.WrappedTransaction) map[string]func() interface{} {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is sub-optimal. Working with function pointers is also a little bit messy.
Why not further simplify?

func (atp *apiTransactionProcessor) extractRequestedTxInfo(wrappedTx *txcache.WrappedTransaction, requestedFieldsHandler fieldsHandler) common.Transaction {
	fieldGetters := atp.getFieldGettersForTx(wrappedTx)
	tx := common.Transaction{
		TxFields: make(map[string]interface{}),
	}

	for field, value := range fieldGetters {
		if requestedFieldsHandler.IsFieldSet(field) {
			tx.TxFields[field] = value
		}
	}

	return tx
}

func (atp *apiTransactionProcessor) getFieldGettersForTx(wrappedTx *txcache.WrappedTransaction) map[string]interface{} {
	var fieldGetters = map[string]interface{}{
		hashField:        hex.EncodeToString(wrappedTx.TxHash),
		nonceField:       wrappedTx.Tx.GetNonce(),
		senderField:      atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetSndAddr(), log),
		receiverField:    atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetRcvAddr(), log),
		gasLimitField:    wrappedTx.Tx.GetGasLimit(),
		gasPriceField:    wrappedTx.Tx.GetGasPrice(),
		rcvUsernameField: wrappedTx.Tx.GetRcvUserName(),
		dataField:        wrappedTx.Tx.GetData(),
		valueField:       getTxValue(wrappedTx),
		senderShardID:    wrappedTx.SenderShardID,
		receiverShardID:  wrappedTx.ReceiverShardID,
	}

	guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler)
	if isGuardedTx {
		fieldGetters[signatureField] = hex.EncodeToString(guardedTx.GetSignature())
		fieldGetters[guardianField] = atp.addressPubKeyConverter.SilentEncode(guardedTx.GetGuardianAddr(), log)
		fieldGetters[guardianSignatureField] = hex.EncodeToString(guardedTx.GetGuardianSignature())
	}

	return fieldGetters
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed

@sstanculeanu sstanculeanu merged commit 1d25207 into rc/v1.7.next1 Mar 14, 2024
8 checks passed
@sstanculeanu sstanculeanu deleted the guardian_in_response_of_tx_pool_request branch March 14, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants