Skip to content
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

Link inner txs to results #6529

Open
wants to merge 13 commits into
base: rc/v1.7.next1
Choose a base branch
from
17 changes: 9 additions & 8 deletions process/smartContract/processorV2/processV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,16 +1412,17 @@ func (sc *scProcessor) isCrossShardESDTTransfer(sender []byte, receiver []byte,
func (sc *scProcessor) getOriginalTxHashIfIntraShardRelayedSCR(
tx data.TransactionHandler,
txHash []byte,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which txHash is this, is it the hash of the tx given as argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the hash of the initial SCR, which is the tx param

) ([]byte, []byte, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: use a struct for the return values

) ([]byte, []byte, bool, bool) {
relayedSCR, isRelayed := isRelayedTx(tx)
if !isRelayed {
return txHash, txHash, isRelayed
return txHash, txHash, isRelayed, false // we don't care if it is intra-shard as it is not relayed anyway
}

sndShardID := sc.shardCoordinator.ComputeId(relayedSCR.SndAddr)
rcvShardID := sc.shardCoordinator.ComputeId(relayedSCR.RcvAddr)
if sndShardID != rcvShardID {
return txHash, relayedSCR.OriginalTxHash, isRelayed
isIntraShard := sndShardID == rcvShardID
if !isIntraShard {
return txHash, relayedSCR.OriginalTxHash, isRelayed, isIntraShard
}

// At this point, the relayedSCR is from a relayed intra-shard transaction
Expand All @@ -1430,10 +1431,10 @@ func (sc *scProcessor) getOriginalTxHashIfIntraShardRelayedSCR(
// In this case, we can use the scr hash, as intra shard scr was added with this flag
// even for intra-shard sc calls
if !bytes.Equal(relayedSCR.PrevTxHash, relayedSCR.OriginalTxHash) {
return txHash, relayedSCR.OriginalTxHash, isRelayed
return txHash, relayedSCR.OriginalTxHash, isRelayed, isIntraShard
}

return relayedSCR.OriginalTxHash, relayedSCR.OriginalTxHash, isRelayed
return relayedSCR.OriginalTxHash, relayedSCR.OriginalTxHash, isRelayed, isIntraShard
}

// ProcessIfError creates a smart contract result, consumes the gas and returns the value to the user
Expand Down Expand Up @@ -1523,8 +1524,8 @@ func (sc *scProcessor) processIfErrorWithAddedLogs(acntSnd state.UserAccountHand
processIfErrorLogs = append(processIfErrorLogs, failureContext.logs...)
}

logsTxHash, originalTxHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash)
shouldAddIntraShardScrForRelayedInner := isRelayed && !bytes.Equal(logsTxHash, originalTxHash)
logsTxHash, originalTxHash, isRelayed, isIntraShard := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash)
shouldAddIntraShardScrForRelayedInner := isRelayed && isIntraShard && !bytes.Equal(logsTxHash, originalTxHash)
if shouldAddIntraShardScrForRelayedInner {
err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}, failureContext.txHash)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions process/smartContract/processorV2/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4084,25 +4084,28 @@ func TestProcessGetOriginalTxHashForRelayedIntraShard(t *testing.T) {
scrHash := []byte("hash")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a bad naming for the relay tx hash? or this really represents the scr hash?

Copy link
Collaborator Author

@sstanculeanu sstanculeanu Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is the hash of the provided scr


// scr not relayed
hashForLogSave, scrHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash)
hashForLogSave, scrHash, isRelayed, isIntraShard := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash)
assert.Equal(t, scrHash, hashForLogSave)
assert.Equal(t, scrHash, scrHash)
assert.False(t, isRelayed)
assert.False(t, isIntraShard)

scr.OriginalTxHash = []byte("originalHash")
scr.PrevTxHash = []byte("originalHash")
scr.RelayerAddr = bytes.Repeat([]byte{1}, 32)
scr.SndAddr = bytes.Repeat([]byte{1}, 32)
scr.RcvAddr = bytes.Repeat([]byte{1}, 32)
hashForLogSave, originalTxHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash)
hashForLogSave, originalTxHash, isRelayed, isIntraShard := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash)
assert.Equal(t, scr.OriginalTxHash, hashForLogSave)
assert.Equal(t, scr.OriginalTxHash, originalTxHash)
assert.True(t, isRelayed)
assert.True(t, isIntraShard)

scr.RcvAddr = bytes.Repeat([]byte{2}, 32)
hashForLogSave, originalTxHash, _ = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash)
hashForLogSave, originalTxHash, _, isIntraShard = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash)
assert.Equal(t, scrHash, hashForLogSave)
assert.Equal(t, scr.OriginalTxHash, originalTxHash)
assert.False(t, isIntraShard)
}

func TestProcess_createCompletedTxEvent(t *testing.T) {
Expand Down
Loading