Skip to content

Commit

Permalink
fix process-status for relayed v3 of type move balance
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Nov 22, 2024
1 parent 9c7ed13 commit eb1c68f
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
91 changes: 91 additions & 0 deletions process/testdata/relayedV3MoveBalanceOk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"transaction": {
"type": "normal",
"processingTypeOnSource": "RelayedTxV3",
"processingTypeOnDestination": "RelayedTxV3",
"hash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3",
"nonce": 0,
"round": 4,
"epoch": 0,
"value": "1000000000000000000",
"receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg",
"sender": "erd10vn8cuug0wx6anj84g7ukzlm06fullcjadetvmusqzv039x04f3supvc4v",
"gasPrice": 1000000000,
"gasLimit": 300000,
"gasUsed": 300000,
"signature": "0ba816dd7d6f9f5b05b3ef6f4ea46caf3d6869ebd890510b7801067dd5179fe4c6f5b128d7538eed0414cfd3380c54810709a984bd6d53ab56f71b7f91533206",
"sourceShard": 1,
"destinationShard": 1,
"blockNonce": 4,
"blockHash": "1eb5515921d9f53aa23d7f6d5ef088d4df335fb237e90a46b111c4f299fba0a7",
"notarizedAtSourceInMetaNonce": 6,
"NotarizedAtSourceInMetaHash": "b65de97cd422f5d1a14ede7ac16da42e0de979ad0818c91a57d423fed8cd37b8",
"notarizedAtDestinationInMetaNonce": 6,
"notarizedAtDestinationInMetaHash": "b65de97cd422f5d1a14ede7ac16da42e0de979ad0818c91a57d423fed8cd37b8",
"miniblockType": "TxBlock",
"miniblockHash": "3cba328024e2fa1f5be2aea6413b5f2b3f7d20ba426cc7cd0c5ff4df32968a38",
"hyperblockNonce": 6,
"hyperblockHash": "b65de97cd422f5d1a14ede7ac16da42e0de979ad0818c91a57d423fed8cd37b8",
"timestamp": 1732283756,
"smartContractResults": [
{
"hash": "08f9e753dca6fff9237ef168912f8c6c407b9c8d2c0163a2d72b6ad7b5e7619b",
"nonce": 0,
"value": 1000000000000000000,
"receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg",
"sender": "erd10vn8cuug0wx6anj84g7ukzlm06fullcjadetvmusqzv039x04f3supvc4v",
"relayerAddress": "erd15uchpdmkn90qxd9add6npnst3mckkapkq7zmn5l8rlkwnvk7k0ese9q8z5",
"relayedValue": 0,
"prevTxHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3",
"originalTxHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3",
"gasLimit": 200000,
"gasPrice": 1000000000,
"callType": 0,
"operation": "transfer"
}
],
"status": "success",
"operation": "transfer",
"initiallyPaidFee": "300000000000000",
"fee": "300000000000000",
"isRelayed": true,
"relayerAddress": "erd15uchpdmkn90qxd9add6npnst3mckkapkq7zmn5l8rlkwnvk7k0ese9q8z5",
"relayerSignature": "62e1ed470dd07a7fe513cf9e93652bf8d27127d1a8fb12724dd45e2a7fcb3311071bc0f54856718fc07c42b11be7b357a5538c39864fa337f73cfa0ca2aed50e",
"chainID": "chain",
"version": 2,
"options": 0
},
"scrs": [
{
"type": "unsigned",
"processingTypeOnSource": "MoveBalance",
"processingTypeOnDestination": "MoveBalance",
"hash": "08f9e753dca6fff9237ef168912f8c6c407b9c8d2c0163a2d72b6ad7b5e7619b",
"nonce": 0,
"round": 4,
"epoch": 0,
"value": "1000000000000000000",
"receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg",
"sender": "erd10vn8cuug0wx6anj84g7ukzlm06fullcjadetvmusqzv039x04f3supvc4v",
"gasPrice": 1000000000,
"gasLimit": 200000,
"gasUsed": 50000,
"previousTransactionHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3",
"originalTransactionHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3",
"sourceShard": 1,
"destinationShard": 1,
"blockNonce": 4,
"blockHash": "1eb5515921d9f53aa23d7f6d5ef088d4df335fb237e90a46b111c4f299fba0a7",
"miniblockType": "SmartContractResultBlock",
"miniblockHash": "aada9d10986b36e44feb55aba48518172b53e320e40cae3c22b40964a0cd8aec",
"timestamp": 1732283756,
"status": "success",
"operation": "transfer",
"fee": "0",
"callType": "directCall",
"relayerAddress": "erd15uchpdmkn90qxd9add6npnst3mckkapkq7zmn5l8rlkwnvk7k0ese9q8z5",
"relayedValue": "0",
"options": 0
}
]
}
17 changes: 17 additions & 0 deletions process/transactionProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
moveBalanceDescriptor = "MoveBalance"
relayedV1TransactionDescriptor = "RelayedTx"
relayedV2TransactionDescriptor = "RelayedTxV2"
relayedV3TransactionDescriptor = "RelayedTxV3"
emptyDataStr = ""
)

Expand Down Expand Up @@ -511,6 +512,12 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran
}
}

if checkIfRelayedV3Notarized(tx) {
return &data.ProcessStatusResponse{
Status: string(tx.Status),
}
}

return &data.ProcessStatusResponse{
Status: string(transaction.TxStatusPending),
}
Expand Down Expand Up @@ -590,6 +597,16 @@ func checkIfMoveBalanceNotarized(tx *transaction.ApiTransactionResult) bool {
return isMoveBalance
}

func checkIfRelayedV3Notarized(tx *transaction.ApiTransactionResult) bool {
isNotarized := tx.NotarizedAtSourceInMetaNonce > 0 && tx.NotarizedAtDestinationInMetaNonce > 0
if !isNotarized {
return false
}
isRelayedV3 := tx.ProcessingTypeOnSource == relayedV3TransactionDescriptor && tx.ProcessingTypeOnDestination == relayedV3TransactionDescriptor

return isRelayedV3
}

func (tp *TransactionProcessor) addMissingLogsOnProcessingExceptions(
tx *transaction.ApiTransactionResult,
allLogs []*transaction.ApiLogs,
Expand Down
42 changes: 42 additions & 0 deletions process/transactionProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2151,3 +2151,45 @@ func TestCheckIfFailed(t *testing.T) {
require.True(t, ok)
require.True(t, strings.Contains(str, "storage decode error: input too short"))
}

func TestTransactionProcessor_GetProcessedStatusIntraShardRelayedV3WithMoveBalance(t *testing.T) {
txWithSCRs := loadJsonIntoTxAndScrs(t, "./testdata/relayedV3MoveBalanceOk.json")

processorStub := &mock.ProcessorStub{
GetShardIDsCalled: func() []uint32 {
return []uint32{1} // force everything intra-shard for test setup simplicity
},
ComputeShardIdCalled: func(addressBuff []byte) (uint32, error) {
return 1, nil
},
GetObserversCalled: func(shardId uint32, dataAvailability data.ObserverDataAvailabilityType) ([]*data.NodeData, error) {
return []*data.NodeData{
{
Address: "test",
ShardId: 1,
},
}, nil
},
CallGetRestEndPointCalled: func(address string, path string, value interface{}) (int, error) {
valueC, ok := value.(*data.GetTransactionResponse)
if !ok {
return http.StatusOK, nil
}
valueC.Data.Transaction = *txWithSCRs.SCRs[0]

return http.StatusOK, nil
},
}
tp, _ := process.NewTransactionProcessor(
processorStub,
testPubkeyConverter,
hasher,
marshalizer,
funcNewTxCostHandler,
logsMerger,
false,
)

status := tp.ComputeTransactionStatus(txWithSCRs.Transaction, true)
require.Equal(t, string(transaction.TxStatusSuccess), status.Status)
}

0 comments on commit eb1c68f

Please sign in to comment.