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

Migrate data trie #4962

Merged
merged 7 commits into from
Mar 8, 2023
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
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ESDTNFTAddUri = 500000
ESDTNFTUpdateAttributes = 500000
ESDTNFTMultiTransfer = 1000000
TrieLoadPerNode = 20000
TrieStorePerNode = 50000

[MetaChainSystemSCsCost]
Stake = 5000000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ESDTNFTAddUri = 500000
ESDTNFTUpdateAttributes = 500000
ESDTNFTMultiTransfer = 1000000
TrieLoadPerNode = 20000
TrieStorePerNode = 50000

[MetaChainSystemSCsCost]
Stake = 5000000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ESDTNFTAddUri = 500000
ESDTNFTUpdateAttributes = 500000
ESDTNFTMultiTransfer = 1000000
TrieLoadPerNode = 20000
TrieStorePerNode = 50000

[MetaChainSystemSCsCost]
Stake = 5000000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ESDTNFTAddUri = 50000
ESDTNFTUpdateAttributes = 50000
ESDTNFTMultiTransfer = 200000
TrieLoadPerNode = 20000
TrieStorePerNode = 50000

[MetaChainSystemSCsCost]
Stake = 5000000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ESDTNFTAddUri = 50000
ESDTNFTUpdateAttributes = 50000
ESDTNFTMultiTransfer = 200000
TrieLoadPerNode = 20000
TrieStorePerNode = 50000

[MetaChainSystemSCsCost]
Stake = 5000000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV6.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ESDTNFTAddUri = 50000
ESDTNFTUpdateAttributes = 50000
ESDTNFTMultiTransfer = 200000
TrieLoadPerNode = 20000
TrieStorePerNode = 50000

[MetaChainSystemSCsCost]
Stake = 5000000
Expand Down
2 changes: 2 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV7.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
ESDTNFTUpdateAttributes = 50000
ESDTNFTMultiTransfer = 200000
MultiESDTNFTTransfer = 200000 # should be the same value with the ESDTNFTMultiTransfer
TrieLoadPerNode = 20000
TrieStorePerNode = 50000

[MetaChainSystemSCsCost]
Stake = 5000000
Expand Down
2 changes: 1 addition & 1 deletion common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Trie interface {

// TrieLeafParser is used to parse trie leaves
type TrieLeafParser interface {
ParseLeaf(key []byte, val []byte, version TrieNodeVersion) (core.KeyValueHolder, error)
ParseLeaf(key []byte, val []byte, version core.TrieNodeVersion) (core.KeyValueHolder, error)
IsInterfaceNil() bool
}

Expand Down
18 changes: 0 additions & 18 deletions common/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
)

// TrieNodeVersion defines the version of the trie node
type TrieNodeVersion uint8

const (
// NotSpecified means that the value is not populated or is not important
NotSpecified TrieNodeVersion = iota

// AutoBalanceEnabled is used for data tries, and only after the activation of AutoBalanceDataTriesEnableEpoch flag
AutoBalanceEnabled
)

// TrieData holds the data that will be inserted into the trie
type TrieData struct {
Key []byte
Value []byte
Version TrieNodeVersion
}

// EmptyTrieHash returns the value with empty trie hash
var EmptyTrieHash = make([]byte, 32)

Expand Down
6 changes: 6 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,9 @@ var ErrNilPersistentHandler = errors.New("nil persistent handler")

// ErrNilGenesisNodesSetupHandler signals that a nil genesis nodes setup handler has been provided
var ErrNilGenesisNodesSetupHandler = errors.New("nil genesis nodes setup handler")

// ErrInvalidTrieNodeVersion signals that an invalid trie node version has been provided
var ErrInvalidTrieNodeVersion = errors.New("invalid trie node version")

// ErrNilTrieMigrator signals that a nil trie migrator has been provided
var ErrNilTrieMigrator = errors.New("nil trie migrator")
3 changes: 2 additions & 1 deletion genesis/mock/userAccountMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"math/big"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/common"
)

Expand Down Expand Up @@ -141,7 +142,7 @@ func (uam *UserAccountMock) GetUserName() []byte {
}

// SaveDirtyData -
func (uam *UserAccountMock) SaveDirtyData(_ common.Trie) ([]common.TrieData, error) {
func (uam *UserAccountMock) SaveDirtyData(_ common.Trie) ([]core.TrieData, error) {
return nil, nil
}

Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ require (
github.com/google/gops v0.3.18
github.com/gorilla/websocket v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.1.33
github.com/multiversx/mx-chain-core-go v1.1.35-0.20230302100006-5230818062e9
github.com/multiversx/mx-chain-crypto-go v1.2.5
github.com/multiversx/mx-chain-es-indexer-go v1.3.12
github.com/multiversx/mx-chain-logger-go v1.0.11
github.com/multiversx/mx-chain-p2p-go v1.0.13
github.com/multiversx/mx-chain-storage-go v1.0.7
github.com/multiversx/mx-chain-vm-common-go v1.3.37
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.50
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.51
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.77
github.com/multiversx/mx-chain-vm-common-go v1.3.38-0.20230302100330-6d0ec8963a31
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.51-0.20230302102214-94d6f0ba4d00
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.52-0.20230302101124-e32ddf31fbb9
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.78-0.20230302100627-28a21440e662
github.com/pelletier/go-toml v1.9.3
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil v3.21.11+incompatible
Expand Down
22 changes: 10 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,8 @@ github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXS
github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI=
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-core-go v1.1.30/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-core-go v1.1.31/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-core-go v1.1.33 h1:qk+TlaOhHpu+9VncL3yowjY4KU8uJ0oSdPfU7SgVDnk=
github.com/multiversx/mx-chain-core-go v1.1.33/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-core-go v1.1.35-0.20230302100006-5230818062e9 h1:ffKx/z2aFBzaUs10z5W/9pBsYxeY43UvYui3z4iYPRs=
github.com/multiversx/mx-chain-core-go v1.1.35-0.20230302100006-5230818062e9/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-crypto-go v1.2.5 h1:tuq3BUNMhKud5DQbZi9DiVAAHUXypizy8zPH0NpTGZk=
github.com/multiversx/mx-chain-crypto-go v1.2.5/go.mod h1:teqhNyWEqfMPgNn8sgWXlgtJ1a36jGCnhs/tRpXW6r4=
github.com/multiversx/mx-chain-es-indexer-go v1.3.12 h1:b7B8KMrCHM0Ghh4W0s1jXLI5MknEAOo7ZChFAwUUYpY=
Expand All @@ -623,15 +622,14 @@ github.com/multiversx/mx-chain-p2p-go v1.0.13/go.mod h1:j9Ueo2ptCnL7TQvQg6KS/KWA
github.com/multiversx/mx-chain-storage-go v1.0.7 h1:UqLo/OLTD3IHiE/TB/SEdNRV1GG2f1R6vIP5ehHwCNw=
github.com/multiversx/mx-chain-storage-go v1.0.7/go.mod h1:gtKoV32Cg2Uy8deHzF8Ud0qAl0zv92FvWgPSYIP0Zmg=
github.com/multiversx/mx-chain-vm-common-go v1.3.34/go.mod h1:sZ2COLCxvf2GxAAJHGmGqWybObLtFuk2tZUyGqnMXE8=
github.com/multiversx/mx-chain-vm-common-go v1.3.36/go.mod h1:sZ2COLCxvf2GxAAJHGmGqWybObLtFuk2tZUyGqnMXE8=
github.com/multiversx/mx-chain-vm-common-go v1.3.37 h1:KeK6JCjeNUOHC5Z12/CTQIa8Z1at0dnnL9hY1LNrHS8=
github.com/multiversx/mx-chain-vm-common-go v1.3.37/go.mod h1:sZ2COLCxvf2GxAAJHGmGqWybObLtFuk2tZUyGqnMXE8=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.50 h1:ScUq7/wq78vthMTQ6v5Ux1DvSMQMHxQ2Sl7aPP26q1w=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.50/go.mod h1:e3uYdgoKzs3puaznbmSjDcRisJc5Do4tpg7VqyYwoek=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.51 h1:axtp5/mpA+xYJ1cu4KtAGETV4t6v6/tNfQh0HCclBYY=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.51/go.mod h1:oKj32V2nkd+KGNOL6emnwVkDRPpciwHHDqBmeorcL8k=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.77 h1:3Yh4brS5/Jye24l5AKy+Q6Yci6Rv55pHyj9/GR3AYos=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.77/go.mod h1:3IaAOHc1JfxL5ywQZIrcaHQu5+CVdZNDaoY64NGOtUE=
github.com/multiversx/mx-chain-vm-common-go v1.3.38-0.20230302100330-6d0ec8963a31 h1:CN5jVyk8LsvOJ5htRcxPD8+lF77S1p++3HlGSbG4Lu8=
github.com/multiversx/mx-chain-vm-common-go v1.3.38-0.20230302100330-6d0ec8963a31/go.mod h1:y/pwzZF5saK3GIdseiyCOqoq5OdKIOIKu9tQiIWh7BY=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.51-0.20230302102214-94d6f0ba4d00 h1:qnoFnrRAX3BsMBLDnxkdi/F+hOiyzZqn/VeCOXfiLhg=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.51-0.20230302102214-94d6f0ba4d00/go.mod h1:pIsa9gzTMRy6/hAbcH/4aC5VulmZO/pY7l7MXRISGBk=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.52-0.20230302101124-e32ddf31fbb9 h1:6r6wWBHiD2D5PDobyxL3W+xIso/pan+k59T+l9YOS+0=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.52-0.20230302101124-e32ddf31fbb9/go.mod h1:LwEnuDYX6Y0KU3z5F+/sp9zcJo5+3lU9aTRH7an4G5I=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.78-0.20230302100627-28a21440e662 h1:m7MajpOJsSKLxBhh6u+9BzC1O6Lpu7VYr79JkD3u8WY=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.78-0.20230302100627-28a21440e662/go.mod h1:fQzZWMzInDYOQkeGA+um/8odZiAfPs3qgj6/Hfzsin0=
github.com/multiversx/mx-components-big-int v0.1.1 h1:695mYPKYOrmGEGgRH4/pZruDoe3CPP1LHrBxKfvj5l4=
github.com/multiversx/mx-components-big-int v0.1.1/go.mod h1:0QrcFdfeLgJ/am10HGBeH0G0DNF+0Qx1E4DS/iozQls=
github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM=
Expand Down
16 changes: 8 additions & 8 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ func TestNode_GetKeyValuePairs(t *testing.T) {
GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error {
go func() {
suffix := append(k1, acc.AddressBytes()...)
trieLeaf, _ := tlp.ParseLeaf(k1, append(v1, suffix...), common.NotSpecified)
trieLeaf, _ := tlp.ParseLeaf(k1, append(v1, suffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf

suffix = append(k2, acc.AddressBytes()...)
trieLeaf2, _ := tlp.ParseLeaf(k2, append(v2, suffix...), common.NotSpecified)
trieLeaf2, _ := tlp.ParseLeaf(k2, append(v2, suffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf2
close(leavesChannels.LeavesChan)
close(leavesChannels.ErrChan)
Expand Down Expand Up @@ -940,13 +940,13 @@ func TestNode_GetAllIssuedESDTs(t *testing.T) {
&trieMock.TrieStub{
GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error {
go func() {
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), common.NotSpecified)
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf

trieLeaf, _ = tlp.ParseLeaf(sftToken, append(sftMarshalledData, sftSuffix...), common.NotSpecified)
trieLeaf, _ = tlp.ParseLeaf(sftToken, append(sftMarshalledData, sftSuffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf

trieLeaf, _ = tlp.ParseLeaf(nftToken, append(nftMarshalledData, nftSuffix...), common.NotSpecified)
trieLeaf, _ = tlp.ParseLeaf(nftToken, append(nftMarshalledData, nftSuffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf
close(leavesChannels.LeavesChan)
close(leavesChannels.ErrChan)
Expand Down Expand Up @@ -1032,7 +1032,7 @@ func TestNode_GetESDTsWithRole(t *testing.T) {
&trieMock.TrieStub{
GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error {
go func() {
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), common.NotSpecified)
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf
close(leavesChannels.LeavesChan)
close(leavesChannels.ErrChan)
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func TestNode_GetESDTsRoles(t *testing.T) {
&trieMock.TrieStub{
GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error {
go func() {
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), common.NotSpecified)
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf
close(leavesChannels.LeavesChan)
close(leavesChannels.ErrChan)
Expand Down Expand Up @@ -1177,7 +1177,7 @@ func TestNode_GetNFTTokenIDsRegisteredByAddress(t *testing.T) {
&trieMock.TrieStub{
GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error {
go func() {
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), common.NotSpecified)
trieLeaf, _ := tlp.ParseLeaf(esdtToken, append(marshalledData, esdtSuffix...), core.NotSpecified)
leavesChannels.LeavesChan <- trieLeaf
close(leavesChannels.LeavesChan)
close(leavesChannels.ErrChan)
Expand Down
2 changes: 2 additions & 0 deletions process/gasCost.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type BuiltInCost struct {
ESDTNFTAddUri uint64
ESDTNFTUpdateAttributes uint64
ESDTNFTMultiTransfer uint64
TrieLoadPerNode uint64
TrieStorePerNode uint64
}

// GasCost holds all the needed gas costs for system smart contracts
Expand Down
4 changes: 3 additions & 1 deletion process/smartContract/builtInFunctions/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func fillGasMapBuiltInCosts(value uint64) map[string]uint64 {
gasMap["ESDTNFTAddUri"] = value
gasMap["ESDTNFTUpdateAttributes"] = value
gasMap["ESDTNFTMultiTransfer"] = value
gasMap["TrieLoadPerNode"] = value
gasMap["TrieStorePerNode"] = value

return gasMap
}
Expand Down Expand Up @@ -161,7 +163,7 @@ func TestCreateBuiltInFunctionContainer(t *testing.T) {
args := createMockArguments()
builtInFuncFactory, err := CreateBuiltInFunctionsFactory(args)
assert.Nil(t, err)
assert.Equal(t, len(builtInFuncFactory.BuiltInFunctionContainer().Keys()), 31)
assert.Equal(t, 32, len(builtInFuncFactory.BuiltInFunctionContainer().Keys()))

err = builtInFuncFactory.SetPayableHandler(&testscommon.BlockChainHookStub{})
assert.Nil(t, err)
Expand Down
3 changes: 3 additions & 0 deletions state/accountsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ func (adb *AccountsDB) saveDataTrie(accountHandler baseAccountHandler) error {
}
adb.journalize(entry)

//TODO in order to avoid recomputing the root hash after every transaction for the same data trie,
// benchmark if it is better to cache the account and compute the rootHash only when the state is committed.
// For this to work, LoadAccount should check that cache first, and only after load from the trie.
rootHash, err := accountHandler.DataTrie().RootHash()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions state/accountsDB_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func TestAccountsDB_SaveAccountSavesCodeAndDataTrieForUserAccount(t *testing.T)
GetCalled: func(_ []byte) ([]byte, uint32, error) {
return nil, 0, nil
},
UpdateWithVersionCalled: func(key, value []byte, version common.TrieNodeVersion) error {
UpdateWithVersionCalled: func(key, value []byte, version core.TrieNodeVersion) error {
return nil
},
RootCalled: func() (i []byte, err error) {
Expand Down Expand Up @@ -851,7 +851,7 @@ func TestAccountsDB_CommitShouldCallCommitFromTrie(t *testing.T) {
GetCalled: func(_ []byte) ([]byte, uint32, error) {
return []byte("doge"), 0, nil
},
UpdateWithVersionCalled: func(key, value []byte, version common.TrieNodeVersion) error {
UpdateWithVersionCalled: func(key, value []byte, version core.TrieNodeVersion) error {
return nil
},
CommitCalled: func() error {
Expand Down
3 changes: 2 additions & 1 deletion state/baseAccount.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package state

import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/common"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
Expand Down Expand Up @@ -53,7 +54,7 @@ func (ba *baseAccount) SaveKeyValue(key []byte, value []byte) error {
}

// SaveDirtyData triggers SaveDirtyData form the underlying trackableDataTrie
func (ba *baseAccount) SaveDirtyData(trie common.Trie) ([]common.TrieData, error) {
func (ba *baseAccount) SaveDirtyData(trie common.Trie) ([]core.TrieData, error) {
if check.IfNil(ba.dataTrieTracker) {
return nil, ErrNilTrackableDataTrie
}
Expand Down
15 changes: 12 additions & 3 deletions state/disabled/disabledTrackableDataTrie.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package disabled

import "github.com/multiversx/mx-chain-go/common"
import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/common"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)

type disabledTrackableDataTrie struct {
}
Expand Down Expand Up @@ -30,8 +34,13 @@ func (dtdt *disabledTrackableDataTrie) DataTrie() common.DataTrieHandler {
}

// SaveDirtyData does nothing for this implementation
func (dtdt *disabledTrackableDataTrie) SaveDirtyData(_ common.Trie) ([]common.TrieData, error) {
return make([]common.TrieData, 0), nil
func (dtdt *disabledTrackableDataTrie) SaveDirtyData(_ common.Trie) ([]core.TrieData, error) {
return make([]core.TrieData, 0), nil
}

// MigrateDataTrieLeaves does nothing for this implementation
func (dtdt *disabledTrackableDataTrie) MigrateDataTrieLeaves(_ core.TrieNodeVersion, _ core.TrieNodeVersion, _ vmcommon.DataTrieMigrator) error {
return nil
}

// IsInterfaceNil returns true if there is no value under the interface
Expand Down
24 changes: 21 additions & 3 deletions state/export_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package state

import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/common"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
Expand Down Expand Up @@ -79,11 +80,28 @@ func EmptyErrChanReturningHadContained(errChan chan error) bool {
}

// DirtyData -
func (tdaw *trackableDataTrie) DirtyData() map[string][]byte {
return tdaw.dirtyData
type DirtyData struct {
iulianpascalau marked this conversation as resolved.
Show resolved Hide resolved
Value []byte
OldVersion core.TrieNodeVersion
NewVersion core.TrieNodeVersion
}

// DirtyData -
func (tdaw *trackableDataTrie) DirtyData() map[string]DirtyData {
iulianpascalau marked this conversation as resolved.
Show resolved Hide resolved
dd := make(map[string]DirtyData, len(tdaw.dirtyData))

for key, value := range tdaw.dirtyData {
dd[key] = DirtyData{
Value: value.value,
OldVersion: value.oldVersion.version,
NewVersion: value.newVersion,
}
}

return dd
}

// SaveDirtyData -
func (a *userAccount) SaveDirtyData(trie common.Trie) ([]common.TrieData, error) {
func (a *userAccount) SaveDirtyData(trie common.Trie) ([]core.TrieData, error) {
return a.dataTrieTracker.SaveDirtyData(trie)
}
Loading