Skip to content

Commit

Permalink
Merge pull request #6687 from multiversx/fix_receipts_hash_mismatch
Browse files Browse the repository at this point in the history
Fix receipts hash mismatch
  • Loading branch information
sstanculeanu authored Dec 20, 2024
2 parents e9c7ccb + 145806c commit 3b3e5cd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
38 changes: 37 additions & 1 deletion integrationTests/chainSimulator/relayedTx/relayedTx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func testRelayedV3MoveBalance(
result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx)
require.NoError(t, err)

if relayerShard == destinationShard {
isIntraShard := relayerShard == destinationShard
if isIntraShard {
require.NoError(t, cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx))
}

Expand Down Expand Up @@ -180,6 +181,10 @@ func testRelayedV3MoveBalance(

// check intra shard logs, should be none
require.Nil(t, result.Logs)

if extraGas && isIntraShard {
require.NotNil(t, result.Receipt)
}
}
}

Expand Down Expand Up @@ -824,6 +829,37 @@ func TestRelayedTransactionFeeField(t *testing.T) {
})
}

func TestRegularMoveBalanceWithRefundReceipt(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}

cs := startChainSimulator(t, func(cfg *config.Configs) {})
defer cs.Close()

initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10))

sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance)
require.NoError(t, err)

// generate one block so the minting has effect
err = cs.GenerateBlocks(1)
require.NoError(t, err)

senderNonce := uint64(0)

extraGas := uint64(minGasLimit)
gasLimit := minGasLimit + extraGas
tx := generateTransaction(sender.Bytes, senderNonce, sender.Bytes, oneEGLD, "", gasLimit)

result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlocksToGenerateWhenExecutingTx)
require.NoError(t, err)

require.NotNil(t, result.Receipt)
expectedGasRefunded := core.SafeMul(extraGas, minGasPrice/deductionFactor)
require.Equal(t, expectedGasRefunded.String(), result.Receipt.Value.String())
}

func startChainSimulator(
t *testing.T,
alterConfigsFunction func(cfg *config.Configs),
Expand Down
6 changes: 5 additions & 1 deletion process/transaction/shardProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,11 @@ func (txProc *txProcessor) processMoveBalance(
}
}

txHash := originalTxHash
txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx)
if err != nil {
return err
}

err = txProc.createReceiptWithReturnedGas(txHash, tx, feePayer, moveBalanceCost, totalCost, destShardTxType, isUserTxOfRelayed)
if err != nil {
return err
Expand Down

0 comments on commit 3b3e5cd

Please sign in to comment.