Use pointer receiver type because of atomic.Value
#9667
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One line summary: We must use pointer receiver type for tx methods because if not, value receivers will copy the struct containing
atomic.Value
field, which is prohibited to be copied.TransactionMisc
struct is embedded to to every tx type, so we must use pointer receiver for every tx methods.For more context, struct
TransactionMisc
is defined as below:TransactionMisc
is embedded to structAccessListTx
,BlobTx
,BlobTxWrapper
,DynamicFeeTransaction
,CommonTx
,LegacyTx
. Methods for these structs tend to use value receiver, not a pointer receiver.When value receiver method is used, the program copies the struct value and uses it.
TransactionMisc
is embedded, so its fieldshash
andfrom
are also copied.However these fields' types are
atomic.Value
, which are not allowed to be copied after first use. This guideline is also mentioned at Google's golang style guide.Therefore we must use pointer receiver to avoid synchronization issues. Also, using pointer receivers may be more efficient if receiver is large struct.