Skip to content

Commit

Permalink
small fix + fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Oct 29, 2024
1 parent 905bd78 commit a36e68c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@
[EpochStartConfig]
GenesisEpoch = 0
MinRoundsBetweenEpochs = 20
RoundsPerEpoch = 200
RoundsPerEpoch = 20
# Min and Max ShuffledOutRestartThreshold represents the minimum and maximum duration of an epoch (in percentage) after a node which
# has been shuffled out has to restart its process in order to start in a new shard
MinShuffledOutRestartThreshold = 0.05
Expand Down
4 changes: 2 additions & 2 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
UnJailCleanupEnableEpoch = 4

# FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled
FixRelayedBaseCostEnableEpoch = 4
FixRelayedBaseCostEnableEpoch = 1

# MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled
MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 9999999
Expand All @@ -334,7 +334,7 @@
FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 4

# RelayedTransactionsV3 represents the epoch when the relayed transactions v3 will be enabled
RelayedTransactionsV3 = 5
RelayedTransactionsV3 = 1

# BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers
BLSMultiSignerEnableEpoch = [
Expand Down
15 changes: 10 additions & 5 deletions process/transaction/baseProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ func (txProc *baseTxProcessor) checkTxValues(
txFee = txProc.economicsFee.ComputeTxFee(tx)
}

feePayer, err := txProc.getFeePayer(tx, acntSnd)
feePayer, isRelayedV3, err := txProc.getFeePayer(tx, acntSnd)
if err != nil {
return err
}

// early exit for relayed v3, the cost will be compared with the sender balance
if isRelayedV3 {
return nil
}

if feePayer.GetBalance().Cmp(txFee) < 0 {
return fmt.Errorf("%w, has: %s, wanted: %s",
process.ErrInsufficientFee,
Expand All @@ -182,17 +187,17 @@ func (txProc *baseTxProcessor) checkTxValues(
func (txProc *baseTxProcessor) getFeePayer(
tx *transaction.Transaction,
acntSnd state.UserAccountHandler,
) (state.UserAccountHandler, error) {
) (state.UserAccountHandler, bool, error) {
if !isRelayedTxV3(tx) {
return acntSnd, nil
return acntSnd, false, nil
}

acntRelayer, _, err := txProc.getAccounts(tx.RelayerAddr, tx.RelayerAddr)
if err != nil {
return nil, err
return nil, true, err
}

return acntRelayer, nil
return acntRelayer, true, nil
}

func (txProc *baseTxProcessor) computeInnerTxFee(tx *transaction.Transaction) *big.Int {
Expand Down
13 changes: 5 additions & 8 deletions process/transaction/shardProcess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2718,25 +2718,19 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) {

t.Run("should work", func(t *testing.T) {
txCopy := *tx
txCopy.Nonce = acntSrc.GetNonce()
returnCode, err := txProc.ProcessTransaction(&txCopy)
assert.NoError(t, err)
assert.Equal(t, vmcommon.Ok, returnCode)
})
t.Run("getAccounts error should error", func(t *testing.T) {
tx.Nonce++
txCopy := *tx
txCopy.RelayerAddr = []byte("newR") // same length as sender
returnCode, err := txProc.ProcessTransaction(&txCopy)
assert.Error(t, err)
assert.Equal(t, vmcommon.Ok, returnCode)
})
t.Run("flag not active should error", func(t *testing.T) {
argsCopy := args
argsCopy.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub()
txProcLocal, _ := txproc.NewTxProcessor(argsCopy)
require.NotNil(t, txProcLocal)

txCopy := *tx
txCopy.Nonce = acntSrc.GetNonce()
returnCode, err := txProcLocal.ProcessTransaction(&txCopy)
assert.Equal(t, process.ErrFailedTransaction, err)
assert.Equal(t, vmcommon.UserError, returnCode)
Expand All @@ -2752,6 +2746,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) {
require.NotNil(t, txProcLocal)

txCopy := *tx
txCopy.Nonce = acntSrc.GetNonce()
returnCode, err := txProcLocal.ProcessTransaction(&txCopy)
assert.Equal(t, process.ErrFailedTransaction, err)
assert.Equal(t, vmcommon.UserError, returnCode)
Expand Down Expand Up @@ -2783,12 +2778,14 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) {
require.NotNil(t, txProcLocal)

txCopy := *tx
txCopy.Nonce = acntSrc.GetNonce()
returnCode, err := txProcLocal.ProcessTransaction(&txCopy)
assert.Equal(t, process.ErrFailedTransaction, err)
assert.Equal(t, vmcommon.UserError, returnCode)
})
t.Run("insufficient gas limit should error", func(t *testing.T) {
txCopy := *tx
txCopy.Nonce = acntSrc.GetNonce()
argsCopy := args
argsCopy.EconomicsFee = &economicsmocks.EconomicsHandlerStub{
ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 {
Expand Down

0 comments on commit a36e68c

Please sign in to comment.