Skip to content

Commit e3109b6

Browse files
authored
Merge pull request #7346 from multiversx/fix-tx-endpoint-tx-type-relayed
Fix processing type field transaction endpoint
2 parents dd4170a + 0348e97 commit e3109b6

File tree

12 files changed

+123
-43
lines changed

12 files changed

+123
-43
lines changed

factory/disabled/txCoordinator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func (txCoordinator *TxCoordinator) ComputeTransactionType(_ data.TransactionHan
2929
return 0, 0, false
3030
}
3131

32+
// ComputeTransactionTypeInEpoch does nothing as it is disabled
33+
func (txCoordinator *TxCoordinator) ComputeTransactionTypeInEpoch(_ data.TransactionHandler, _ uint32) (process.TransactionType, process.TransactionType, bool) {
34+
return 0, 0, false
35+
}
36+
3237
// RequestMiniBlocksAndTransactions does nothing as it is disabled
3338
func (txCoordinator *TxCoordinator) RequestMiniBlocksAndTransactions(_ data.HeaderHandler) {
3439
}

integrationTests/chainSimulator/relayedTx/relayedTx_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,53 @@ func TestRelayedTransactionFeeField(t *testing.T) {
12371237
})
12381238
}
12391239

1240+
func TestRelayedTxCheckTxProcessingTypeAfterRelayedV1Disabled(t *testing.T) {
1241+
if testing.Short() {
1242+
t.Skip("this is not a short test")
1243+
}
1244+
1245+
const RelayedV1DisableEpoch = 3
1246+
1247+
cs := startChainSimulator(t, func(cfg *config.Configs) {
1248+
cfg.EpochConfig.EnableEpochs.RelayedTransactionsV1V2DisableEpoch = RelayedV1DisableEpoch
1249+
})
1250+
defer cs.Close()
1251+
1252+
initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10))
1253+
relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
1254+
require.NoError(t, err)
1255+
1256+
snd, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
1257+
require.NoError(t, err)
1258+
1259+
rcv, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0))
1260+
require.NoError(t, err)
1261+
1262+
err = cs.GenerateBlocks(1)
1263+
require.Nil(t, err)
1264+
1265+
userTx := generateTransaction(snd.Bytes, 0, rcv.Bytes, oneEGLD, "d", minGasLimit+gasPerDataByte)
1266+
buff, err := json.Marshal(userTx)
1267+
require.NoError(t, err)
1268+
1269+
txData := []byte("relayedTx@" + hex.EncodeToString(buff))
1270+
gasLimit := minGasLimit + len(txData)*gasPerDataByte + int(userTx.GasLimit)
1271+
relayedTx := generateTransaction(relayer.Bytes, 0, snd.Bytes, big.NewInt(0), string(txData), uint64(gasLimit))
1272+
1273+
result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx)
1274+
require.NoError(t, err)
1275+
require.Equal(t, process.RelayedTx.String(), result.ProcessingTypeOnSource)
1276+
require.Equal(t, process.RelayedTx.String(), result.ProcessingTypeOnSource)
1277+
1278+
err = cs.GenerateBlocksUntilEpochIsReached(RelayedV1DisableEpoch)
1279+
require.NoError(t, err)
1280+
1281+
result, err = cs.GetNodeHandler(0).GetFacadeHandler().GetTransaction(result.Hash, true)
1282+
require.NoError(t, err)
1283+
require.Equal(t, process.RelayedTx.String(), result.ProcessingTypeOnSource)
1284+
require.Equal(t, process.RelayedTx.String(), result.ProcessingTypeOnSource)
1285+
}
1286+
12401287
func TestRegularMoveBalanceWithRefundReceipt(t *testing.T) {
12411288
if testing.Short() {
12421289
t.Skip("this is not a short test")

integrationTests/mock/transactionCoordinatorMock.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type TransactionCoordinatorMock struct {
3434
GetAllIntermediateTxsCalled func() map[block.Type]map[string]data.TransactionHandler
3535
AddTxsFromMiniBlocksCalled func(miniBlocks block.MiniBlockSlice)
3636
AddTransactionsCalled func(txHandlers []data.TransactionHandler, blockType block.Type)
37+
ComputeTransactionTypeInEpochCalled func(tx data.TransactionHandler, epoch uint32) (process.TransactionType, process.TransactionType, bool)
3738
}
3839

3940
// GetAllCurrentLogs -
@@ -63,6 +64,15 @@ func (tcm *TransactionCoordinatorMock) ComputeTransactionType(tx data.Transactio
6364
return tcm.ComputeTransactionTypeCalled(tx)
6465
}
6566

67+
// ComputeTransactionTypeInEpoch -
68+
func (tcm *TransactionCoordinatorMock) ComputeTransactionTypeInEpoch(tx data.TransactionHandler, epoch uint32) (process.TransactionType, process.TransactionType, bool) {
69+
if tcm.ComputeTransactionTypeInEpochCalled == nil {
70+
return process.MoveBalance, process.MoveBalance, false
71+
}
72+
73+
return tcm.ComputeTransactionTypeInEpochCalled(tx, epoch)
74+
}
75+
6676
// RequestMiniBlocksAndTransactions -
6777
func (tcm *TransactionCoordinatorMock) RequestMiniBlocksAndTransactions(header data.HeaderHandler) {
6878
if tcm.RequestMiniBlocksAndTransactionsCalled == nil {

node/external/transactionAPI/apiTransactionProcessor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (atp *apiTransactionProcessor) PopulateComputedFields(tx *transaction.ApiTr
189189
}
190190

191191
func (atp *apiTransactionProcessor) populateComputedFieldsProcessingType(tx *transaction.ApiTransactionResult) {
192-
typeOnSource, typeOnDestination, _ := atp.txTypeHandler.ComputeTransactionType(tx.Tx)
192+
typeOnSource, typeOnDestination, _ := atp.txTypeHandler.ComputeTransactionTypeInEpoch(tx.Tx, tx.Epoch)
193193
tx.ProcessingTypeOnSource = typeOnSource.String()
194194
tx.ProcessingTypeOnDestination = typeOnDestination.String()
195195
}

node/external/transactionAPI/apiTransactionProcessor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ func TestApiTransactionProcessor_GetTransactionPopulatesComputedFields(t *testin
13371337
})
13381338

13391339
t.Run("ProcessingType", func(t *testing.T) {
1340-
txTypeHandler.ComputeTransactionTypeCalled = func(data.TransactionHandler) (process.TransactionType, process.TransactionType, bool) {
1340+
txTypeHandler.ComputeTransactionTypeInEpochCalled = func(data.TransactionHandler, uint32) (process.TransactionType, process.TransactionType, bool) {
13411341
return process.MoveBalance, process.SCDeployment, false
13421342
}
13431343

@@ -1350,7 +1350,7 @@ func TestApiTransactionProcessor_GetTransactionPopulatesComputedFields(t *testin
13501350
})
13511351

13521352
t.Run("ProcessingType (with relayed v3)", func(t *testing.T) {
1353-
txTypeHandler.ComputeTransactionTypeCalled = func(data.TransactionHandler) (process.TransactionType, process.TransactionType, bool) {
1353+
txTypeHandler.ComputeTransactionTypeInEpochCalled = func(data.TransactionHandler, uint32) (process.TransactionType, process.TransactionType, bool) {
13541354
return process.MoveBalance, process.SCDeployment, true
13551355
}
13561356

@@ -1394,7 +1394,7 @@ func TestApiTransactionProcessor_PopulateComputedFields(t *testing.T) {
13941394
require.Nil(t, err)
13951395
require.NotNil(t, processor)
13961396

1397-
txTypeHandler.ComputeTransactionTypeCalled = func(data.TransactionHandler) (process.TransactionType, process.TransactionType, bool) {
1397+
txTypeHandler.ComputeTransactionTypeInEpochCalled = func(data.TransactionHandler, uint32) (process.TransactionType, process.TransactionType, bool) {
13981398
return process.MoveBalance, process.SCDeployment, false
13991399
}
14001400

process/coordinator/transactionType.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,19 @@ func NewTxTypeHandler(
7676
return tc, nil
7777
}
7878

79+
// ComputeTransactionTypeInEpoch calculates the transaction type based on the provided epoch
80+
func (tth *txTypeHandler) ComputeTransactionTypeInEpoch(tx data.TransactionHandler, epoch uint32) (process.TransactionType, process.TransactionType, bool) {
81+
return tth.computeTransactionType(tx, epoch)
82+
}
83+
7984
// ComputeTransactionType calculates the transaction type
8085
func (tth *txTypeHandler) ComputeTransactionType(tx data.TransactionHandler) (process.TransactionType, process.TransactionType, bool) {
86+
currentEpoch := tth.enableEpochsHandler.GetCurrentEpoch()
87+
88+
return tth.computeTransactionType(tx, currentEpoch)
89+
}
90+
91+
func (tth *txTypeHandler) computeTransactionType(tx data.TransactionHandler, epoch uint32) (process.TransactionType, process.TransactionType, bool) {
8192
err := tth.checkTxValidity(tx)
8293
if err != nil {
8394
return process.InvalidTransaction, process.InvalidTransaction, false
@@ -99,7 +110,7 @@ func (tth *txTypeHandler) ComputeTransactionType(tx data.TransactionHandler) (pr
99110
funcName, args := tth.getFunctionFromArguments(tx.GetData())
100111
isBuiltInFunction := tth.isBuiltInFunctionCall(funcName)
101112
if isBuiltInFunction {
102-
if tth.isSCCallAfterBuiltIn(funcName, args, tx) {
113+
if tth.isSCCallAfterBuiltIn(funcName, args, tx, epoch) {
103114
return process.BuiltInFunctionCall, process.SCInvoking, isRelayedV3
104115
}
105116

@@ -114,11 +125,11 @@ func (tth *txTypeHandler) ComputeTransactionType(tx data.TransactionHandler) (pr
114125
return process.MoveBalance, process.MoveBalance, isRelayedV3
115126
}
116127

117-
if tth.isRelayedTransactionV1(funcName) {
128+
if tth.isRelayedTransactionV1(funcName, epoch) {
118129
return process.RelayedTx, process.RelayedTx, isRelayedV3 // this should never be reached with both relayed v1 and relayed v3
119130
}
120131

121-
if tth.isRelayedTransactionV2(funcName) {
132+
if tth.isRelayedTransactionV2(funcName, epoch) {
122133
return process.RelayedTxV2, process.RelayedTxV2, isRelayedV3 // this should never be reached with both relayed v2 and relayed v3
123134
}
124135

@@ -143,8 +154,8 @@ func isCallOfType(tx data.TransactionHandler, callType vm.CallType) bool {
143154
return scr.CallType == callType
144155
}
145156

146-
func (tth *txTypeHandler) isSCCallAfterBuiltIn(function string, args [][]byte, tx data.TransactionHandler) bool {
147-
isTransferAndAsyncCallbackFixFlagSet := tth.enableEpochsHandler.IsFlagEnabled(common.ESDTMetadataContinuousCleanupFlag)
157+
func (tth *txTypeHandler) isSCCallAfterBuiltIn(function string, args [][]byte, tx data.TransactionHandler, epoch uint32) bool {
158+
isTransferAndAsyncCallbackFixFlagSet := tth.enableEpochsHandler.IsFlagEnabledInEpoch(common.ESDTMetadataContinuousCleanupFlag, epoch)
148159
if isTransferAndAsyncCallbackFixFlagSet && isCallOfType(tx, vm.AsynchronousCallBack) {
149160
return true
150161
}
@@ -184,17 +195,17 @@ func (tth *txTypeHandler) isBuiltInFunctionCall(functionName string) bool {
184195
return function.IsActive()
185196
}
186197

187-
func (tth *txTypeHandler) isRelayedTransactionV1(functionName string) bool {
188-
areRelayedDisabled := tth.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV1V2DisableFlag)
198+
func (tth *txTypeHandler) isRelayedTransactionV1(functionName string, epoch uint32) bool {
199+
areRelayedDisabled := tth.enableEpochsHandler.IsFlagEnabledInEpoch(common.RelayedTransactionsV1V2DisableFlag, epoch)
189200
if areRelayedDisabled {
190201
return false
191202
}
192203

193204
return functionName == core.RelayedTransaction
194205
}
195206

196-
func (tth *txTypeHandler) isRelayedTransactionV2(functionName string) bool {
197-
areRelayedDisabled := tth.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV1V2DisableFlag)
207+
func (tth *txTypeHandler) isRelayedTransactionV2(functionName string, epoch uint32) bool {
208+
areRelayedDisabled := tth.enableEpochsHandler.IsFlagEnabledInEpoch(common.RelayedTransactionsV1V2DisableFlag, epoch)
198209
if areRelayedDisabled {
199210
return false
200211
}

process/coordinator/transactionType_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,11 @@ func TestTxTypeHandler_ComputeTransactionDisabledRelayed(t *testing.T) {
491491
tx.Value = big.NewInt(45)
492492

493493
arg := createMockArguments()
494-
arg.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV1V2DisableFlag)
494+
arg.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{
495+
IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool {
496+
return true
497+
},
498+
}
495499
arg.PubkeyConverter = &testscommon.PubkeyConverterStub{
496500
LenCalled: func() int {
497501
return len(tx.RcvAddr)

process/disabled/txTypeHandler.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

process/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type SmartContractProcessorFacade interface {
7171
// TxTypeHandler is an interface to calculate the transaction type
7272
type TxTypeHandler interface {
7373
ComputeTransactionType(tx data.TransactionHandler) (TransactionType, TransactionType, bool)
74+
ComputeTransactionTypeInEpoch(tx data.TransactionHandler, epoch uint32) (TransactionType, TransactionType, bool)
7475
IsInterfaceNil() bool
7576
}
7677

testscommon/scProcessorMock.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ type SCProcessorMock struct {
1818
ProcessIfErrorCalled func(acntSnd state.UserAccountHandler, txHash []byte, tx data.TransactionHandler, returnCode string, returnMessage []byte, snapshot int, gasLocked uint64) error
1919
IsPayableCalled func(sndAddress, recvAddress []byte) (bool, error)
2020
CheckBuiltinFunctionIsExecutableCalled func(expectedBuiltinFunction string, tx data.TransactionHandler) error
21+
ComputeTransactionTypeInEpochCalled func(tx data.TransactionHandler, epoch uint32) (process.TransactionType, process.TransactionType, bool)
22+
}
23+
24+
// ComputeTransactionTypeInEpoch -
25+
func (sc *SCProcessorMock) ComputeTransactionTypeInEpoch(tx data.TransactionHandler, epoch uint32) (process.TransactionType, process.TransactionType, bool) {
26+
if sc.ComputeTransactionTypeInEpochCalled == nil {
27+
return process.MoveBalance, process.MoveBalance, false
28+
}
29+
30+
return sc.ComputeTransactionTypeInEpochCalled(tx, epoch)
2131
}
2232

2333
// IsPayable -

0 commit comments

Comments
 (0)