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

Change receivers ids relayed v3 and multi transfer integration #6302

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5
github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,20 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e h1:Tsmwhu+UleE+l3buPuqXSKTqfu5FbPmzQ4MjMoUvCWA=
github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e/go.mod h1:2yXl18wUbuV3cRZr7VHxM1xo73kTaC1WUcu2kx8R034=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b h1:bmN8RtaWC/7lQenavRVVY5NrAPOdh3N9tGyxqVrx2qU=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d h1:2x1arnxYt28ZlDAZj61dzmG4NqoUmAZbe3pTFsBZHek=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554/go.mod h1:yMq9q5VdN7jBaErRGQ0T8dkZwbBtfQYmqGbD/Ese1us=
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a h1:zn8wCK9Hyge0hm76hUUWhuFkpjitj3P+gjpiTdgU150=
github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a/go.mod h1:rEQ0HPBp0Rg7in8TrC+vncV03yyWWTSTur2sbVGUtUw=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 h1:hFEcbGBtXu8UyB9BMhmAIH2R8BtV/NOq/rsxespLCN8=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5 h1:xx0KtuMO7WizDrBarwozOQDUu69E9KLU7/FDj336uLw=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo=
github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 h1:5/h1i7Xd/JH9CiO3ZqvzAjdze+mAbar5sWkh2UqfLgI=
github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1/go.mod h1:N3Oa8QeeHlSip4nbESQpVSLgi/WxtgIwvqfXIZm6gDs=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b h1:puYO0lUyPGA5kZqsiDjGa+daDGQwj9xFs0S5urhZjU8=
Expand Down
12 changes: 1 addition & 11 deletions node/external/transactionAPI/unmarshaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,10 @@ func (tu *txUnmarshaller) unmarshalTransaction(txBytes []byte, txType transactio
}
apiTx = tu.prepareUnsignedTx(&tx)
}
if err != nil {
return nil, err
}

isRelayedV3 := len(apiTx.InnerTransactions) > 0
if isRelayedV3 {
apiTx.Operation = operationTransfer

rcvsShardIDs := make(map[uint32]struct{})
for _, innerTx := range apiTx.InnerTransactions {
apiTx.Receivers = append(apiTx.Receivers, innerTx.Receiver)

Expand All @@ -106,12 +101,7 @@ func (tu *txUnmarshaller) unmarshalTransaction(txBytes []byte, txType transactio
continue
}

rcvShardID := tu.shardCoordinator.ComputeId(rcvBytes)
rcvsShardIDs[rcvShardID] = struct{}{}
}

for rcvShard := range rcvsShardIDs {
apiTx.ReceiversShardIDs = append(apiTx.ReceiversShardIDs, rcvShard)
apiTx.ReceiversShardIDs = append(apiTx.ReceiversShardIDs, tu.shardCoordinator.ComputeId(rcvBytes))
}

apiTx.IsRelayed = true
Expand Down
27 changes: 26 additions & 1 deletion outport/process/alteredaccounts/tokensProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
outportcore "github.com/multiversx/mx-chain-core-go/data/outport"
"github.com/multiversx/mx-chain-go/sharding"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)

const (
Expand Down Expand Up @@ -116,7 +117,7 @@ func (tp *tokensProcessor) processMultiTransferEvent(event data.EventHandler, ma
// N = len(topics)
// i := 0; i < N-1; i+=3
// {
// topics[i] --- token identifier
// topics[i] --- token identifier or EGLD token identifier
// topics[i+1] --- token nonce
// topics[i+2] --- transferred value
// }
Expand All @@ -133,6 +134,12 @@ func (tp *tokensProcessor) processMultiTransferEvent(event data.EventHandler, ma
for i := 0; i < numOfTopics-1; i += 3 {
tokenID := topics[i]
nonceBigInt := big.NewInt(0).SetBytes(topics[i+1])

if string(tokenID) == vmcommon.EGLDIdentifier {
tp.processNativeEGLDTransferWithMultiTransfer(destinationAddress, markedAlteredAccounts)
return
}

// process event for the sender address
tp.processEsdtDataForAddress(address, nonceBigInt, string(tokenID), markedAlteredAccounts, false)

Expand Down Expand Up @@ -177,6 +184,24 @@ func (tp *tokensProcessor) processEsdtDataForAddress(
}
}

func (tp *tokensProcessor) processNativeEGLDTransferWithMultiTransfer(address []byte, markedAlteredAccounts map[string]*markedAlteredAccount) {
if !tp.isSameShard(address) {
return
}

addressStr := string(address)
_, addressAlreadySelected := markedAlteredAccounts[addressStr]
if addressAlreadySelected {
markedAlteredAccounts[addressStr].balanceChanged = true
return
}

markedAlteredAccounts[addressStr] = &markedAlteredAccount{
balanceChanged: true,
}

}

func (tp *tokensProcessor) isSameShard(address []byte) bool {
return tp.shardCoordinator.SelfId() == tp.shardCoordinator.ComputeId(address)
}
36 changes: 36 additions & 0 deletions outport/process/alteredaccounts/tokensProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-go/process/mock"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -61,3 +62,38 @@ func TestTokenProcessorProcessEventMultiTransferV2(t *testing.T) {
require.Equal(t, markedAccount, markedAccounts["addr"])
require.Equal(t, markedAccount, markedAccounts["receiver"])
}

func TestTokenProcessorProcessEventMultiTransferV2WithEGLD(t *testing.T) {
t.Parallel()

tp := newTokensProcessor(&mock.ShardCoordinatorStub{})

markedAccounts := make(map[string]*markedAlteredAccount)
tp.processEvent(&transaction.Event{
Identifier: []byte(core.BuiltInFunctionMultiESDTNFTTransfer),
Address: []byte("addr"),
Topics: [][]byte{[]byte("token1"), big.NewInt(0).Bytes(), []byte("2"), []byte(vmcommon.EGLDIdentifier), big.NewInt(0).Bytes(), []byte("3"), []byte("receiver")},
}, markedAccounts)

require.Equal(t, 2, len(markedAccounts))
markedAccount1 := &markedAlteredAccount{
tokens: map[string]*markedAlteredAccountToken{
"token1": {
identifier: "token1",
nonce: 0,
},
},
}
require.Equal(t, markedAccount1, markedAccounts["addr"])

markedAccount2 := &markedAlteredAccount{
balanceChanged: true,
tokens: map[string]*markedAlteredAccountToken{
"token1": {
identifier: "token1",
nonce: 0,
},
},
}
require.Equal(t, markedAccount2, markedAccounts["receiver"])
}
Loading