-
Notifications
You must be signed in to change notification settings - Fork 204
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
Accept relayed tx v3 with sender account non-existent #6677
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package dataValidators | |
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
|
@@ -76,14 +77,27 @@ func (txv *txValidator) CheckTxValidity(interceptedTx process.InterceptedTransac | |
return nil | ||
} | ||
|
||
// for relayed v3, we allow sender accounts that do not exist | ||
isRelayedV3 := common.IsRelayedTxV3(interceptedTx.Transaction()) | ||
hasValue := hasTxValue(interceptedTx) | ||
shouldAllowMissingSenderAccount := isRelayedV3 && !hasValue | ||
accountHandler, err := txv.getSenderAccount(interceptedTx) | ||
if err != nil { | ||
if err != nil && !shouldAllowMissingSenderAccount { | ||
return err | ||
} | ||
|
||
return txv.checkAccount(interceptedTx, accountHandler) | ||
} | ||
|
||
func hasTxValue(interceptedTx process.InterceptedTransactionHandler) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, we don't handle |
||
txValue := interceptedTx.Transaction().GetValue() | ||
if check.IfNilReflect(txValue) { | ||
return false | ||
} | ||
|
||
return big.NewInt(0).Cmp(txValue) < 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe directly use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushed |
||
} | ||
|
||
func (txv *txValidator) checkAccount( | ||
interceptedTx process.InterceptedTransactionHandler, | ||
accountHandler vmcommon.AccountHandler, | ||
|
@@ -149,7 +163,11 @@ func (txv *txValidator) checkBalance(interceptedTx process.InterceptedTransactio | |
} | ||
|
||
func (txv *txValidator) checkNonce(interceptedTx process.InterceptedTransactionHandler, accountHandler vmcommon.AccountHandler) error { | ||
accountNonce := accountHandler.GetNonce() | ||
accountNonce := uint64(0) | ||
if !check.IfNil(accountHandler) { | ||
accountNonce = accountHandler.GetNonce() | ||
} | ||
|
||
txNonce := interceptedTx.Nonce() | ||
lowerNonceInTx := txNonce < accountNonce | ||
veryHighNonceInTx := txNonce > accountNonce+uint64(txv.maxNonceDeltaAllowed) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check for
ErrAccountNotFound
(explicitly)? Just a question.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is necessary, as
ErrAccountNotFound
is the only one returned fromgetSenderAccount
method