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 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
TrieLoad = 20000
TrieStore = 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
TrieLoad = 20000
TrieStore = 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
TrieLoad = 20000
TrieStore = 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
TrieLoad = 20000
TrieStore = 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
TrieLoad = 20000
TrieStore = 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
TrieLoad = 20000
TrieStore = 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
TrieLoad = 20000
TrieStore = 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 @@ -52,7 +52,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 @@ -14,16 +14,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.32
github.com/multiversx/mx-chain-core-go v1.1.33-0.20230206103932-f75fdc49b589
github.com/multiversx/mx-chain-crypto-go v1.2.5
github.com/multiversx/mx-chain-es-indexer-go v1.3.9
github.com/multiversx/mx-chain-logger-go v1.0.11
github.com/multiversx/mx-chain-p2p-go v1.0.11
github.com/multiversx/mx-chain-storage-go v1.0.7
github.com/multiversx/mx-chain-vm-common-go v1.3.36
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.76
github.com/multiversx/mx-chain-vm-common-go v1.3.37-0.20230201122738-f39b966bf2fa
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.51-0.20230206095722-a555b1e34b3f
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.52-0.20230206101915-7f57684a299d
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.77-0.20230206101617-6e8b55fc941c
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
23 changes: 12 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,10 @@ 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.32 h1:7Es5r4go0jJt3eBuPGv4RnYeHX/GkISET32SO8xJF+w=
github.com/multiversx/mx-chain-core-go v1.1.32/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-core-go v1.1.31-0.20230126123346-463c70572646/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-core-go v1.1.31-0.20230201095335-e38593a5c058/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-core-go v1.1.33-0.20230206103932-f75fdc49b589 h1:GKnhUOmIank8MTE0lyJJnsOM5N4CdwUWbZKBQGzcC30=
github.com/multiversx/mx-chain-core-go v1.1.33-0.20230206103932-f75fdc49b589/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.9 h1:6AS3f158aJ1E6Pzs6jvyBUiCaq/5yof4lbkGdSTzJng=
Expand All @@ -610,14 +611,14 @@ github.com/multiversx/mx-chain-p2p-go v1.0.11/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 h1:9TViMK+vqTHss9cnGKtzOWzsxI/LWIetAYzrgf4H/w0=
github.com/multiversx/mx-chain-vm-common-go v1.3.36/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.76 h1:HFTf/GuLt68UiDKDZL3GD/YMFdDBaOv31OeP7n0ICQc=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.76/go.mod h1:iyAWamHL3voN/T2sjx7UZ8L4kXLImkgMNh27WUFFhxE=
github.com/multiversx/mx-chain-vm-common-go v1.3.37-0.20230201122738-f39b966bf2fa h1:eIZxAsqa0+Dbm2fKb/pi37ZaSjpO7xXkyozlbGPVnfM=
github.com/multiversx/mx-chain-vm-common-go v1.3.37-0.20230201122738-f39b966bf2fa/go.mod h1:ROgb1LcTeElW5RU06q9rzzORZFeZZLTwwc5hEeKWEHg=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.51-0.20230206095722-a555b1e34b3f h1:rpEKPTbOiW/T/NLvjPIICvspHGWkUE2pUSRIVJfSptw=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.51-0.20230206095722-a555b1e34b3f/go.mod h1:FKS+i+xfFaFVileWDZ3tpjVvI8zW8A7zil+p3DVDwdk=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.52-0.20230206101915-7f57684a299d h1:yh7LUt9PL8K/A904DDOBJo2oTZ+JxdTajZK/ER/kn5w=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.52-0.20230206101915-7f57684a299d/go.mod h1:O+xm1IseEfU/jbpzogwYoa8xK5dOrlG+o2hN7VlH2DI=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.77-0.20230206101617-6e8b55fc941c h1:CC3q+/1qPcgaQ0OdP8wRcQwktqrmN+h4tXShmvJhlgg=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.77-0.20230206101617-6e8b55fc941c/go.mod h1:m2zZvFXE0R1ALYrfQxyR8FpD6fhUceaxRofwF+NOnqw=
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
TrieLoad uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

a little bit misleading name. This is actually TrieLoadPerLeaf cost. Also the next Store cost.

Copy link
Contributor

Choose a reason for hiding this comment

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

same for TrieStorePerLeaf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to TrieLoadPerNode and TrieStorePerLoad

TrieStore 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["TrieLoad"] = value
gasMap["TrieStore"] = 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
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
23 changes: 20 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 @@ -78,12 +79,28 @@ func EmptyErrChanReturningHadContained(errChan chan error) bool {
return emptyErrChanReturningHadContained(errChan)
}

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][]byte {
return tdaw.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)
}