-
Notifications
You must be signed in to change notification settings - Fork 199
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
base: rc/v1.7.next1
Are you sure you want to change the base?
Changes from 1 commit
cf76a45
e9c5ae2
c5d7285
06fb526
11c3a2d
072a375
be94f0e
0585d97
5aa4fb6
9894635
0543e9b
6280d4c
5389337
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1412,16 +1412,17 @@ func (sc *scProcessor) isCrossShardESDTTransfer(sender []byte, receiver []byte, | |
func (sc *scProcessor) getOriginalTxHashIfIntraShardRelayedSCR( | ||
tx data.TransactionHandler, | ||
txHash []byte, | ||
) ([]byte, []byte, bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
|
@@ -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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4084,25 +4084,28 @@ func TestProcessGetOriginalTxHashForRelayedIntraShard(t *testing.T) { | |
scrHash := []byte("hash") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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