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

updated core enums in state changes. #6495

Merged
merged 22 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion factory/status/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package status

import (
"github.com/multiversx/mx-chain-core-go/core"

"github.com/multiversx/mx-chain-go/epochStart"
outportDriverFactory "github.com/multiversx/mx-chain-go/outport/factory"
"github.com/multiversx/mx-chain-go/p2p"
Expand Down Expand Up @@ -30,7 +31,7 @@ func ComputeConnectedPeers(
computeConnectedPeers(appStatusHandler, netMessenger, suffix)
}

// MakeHostDriversArgs -
// MakerHostDriversArgs -
cristure marked this conversation as resolved.
Show resolved Hide resolved
func (scf *statusComponentsFactory) MakeHostDriversArgs() ([]outportDriverFactory.ArgsHostDriverFactory, error) {
return scf.makeHostDriversArgs()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-communication-go v1.1.0
github.com/multiversx/mx-chain-core-go v1.2.23-0.20240918093335-b9e28fbed67c
github.com/multiversx/mx-chain-core-go v1.2.23-0.20240924120353-a1e60f8d53f0
github.com/multiversx/mx-chain-crypto-go v1.2.12
github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9
github.com/multiversx/mx-chain-logger-go v1.0.15
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ 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.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE=
github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
github.com/multiversx/mx-chain-core-go v1.2.23-0.20240918093335-b9e28fbed67c h1:wPqkaTaiSnMXXGmnqJNtn+xMZUoJEAw16QgtrlUGSgk=
github.com/multiversx/mx-chain-core-go v1.2.23-0.20240918093335-b9e28fbed67c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-core-go v1.2.23-0.20240924120353-a1e60f8d53f0 h1:5Bm6Hg5jO+OuwtRfmwQc8XGmw0z7tQJHIcrZ8IaBtQ4=
github.com/multiversx/mx-chain-core-go v1.2.23-0.20240924120353-a1e60f8d53f0/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4=
github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 h1:VJOigTM9JbjFdy9ICVhsDfM9YQkFqMigAaQCHaM0iwY=
Expand Down
40 changes: 20 additions & 20 deletions state/accountsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ func (adb *AccountsDB) GetCode(codeHash []byte) []byte {
return nil
}

stateChange := &stateChange.StateChange{
Type: "read",
sc := &stateChange.StateChange{
Type: stateChange.Read,
MainTrieKey: codeHash,
MainTrieVal: val,
Operation: "getCode",
Operation: stateChange.GetCode,
DataTrieChanges: nil,
}
adb.stateChangesCollector.AddStateChange(stateChange)
adb.stateChangesCollector.AddStateChange(sc)

err = adb.marshaller.Unmarshal(&codeEntry, val)
if err != nil {
Expand Down Expand Up @@ -285,15 +285,15 @@ func (adb *AccountsDB) SaveAccount(account vmcommon.AccountHandler) error {
return err
}

stateChange := &stateChange.StateChange{
Type: "write",
sc := &stateChange.StateChange{
Type: stateChange.Write,
MainTrieKey: account.AddressBytes(),
MainTrieVal: marshalledAccount,
DataTrieChanges: newDataTrieValues,
Operation: "saveAccount",
Operation: stateChange.SaveAccount,
}

adb.stateChangesCollector.AddSaveAccountStateChange(oldAccount, account, stateChange)
adb.stateChangesCollector.AddSaveAccountStateChange(oldAccount, account, sc)

return nil
}
Expand Down Expand Up @@ -373,10 +373,10 @@ func (adb *AccountsDB) updateOldCodeEntry(oldCodeHash []byte) (*CodeEntry, error
}

sc := &stateChange.StateChange{
Type: "read",
Type: stateChange.Read,
MainTrieKey: oldCodeHash,
MainTrieVal: nil,
Operation: "getCode",
Operation: stateChange.GetCode,
DataTrieChanges: nil,
}
adb.stateChangesCollector.AddStateChange(sc)
Expand All @@ -393,10 +393,10 @@ func (adb *AccountsDB) updateOldCodeEntry(oldCodeHash []byte) (*CodeEntry, error
}

sc1 := &stateChange.StateChange{
Type: "write",
Type: stateChange.Write,
MainTrieKey: oldCodeHash,
MainTrieVal: nil,
Operation: "writeCode",
Operation: stateChange.WriteCode,
DataTrieChanges: nil,
}
adb.stateChangesCollector.AddStateChange(sc1)
Expand All @@ -411,10 +411,10 @@ func (adb *AccountsDB) updateOldCodeEntry(oldCodeHash []byte) (*CodeEntry, error
}

sc = &stateChange.StateChange{
Type: "write",
Type: stateChange.Write,
MainTrieKey: oldCodeHash,
MainTrieVal: codeEntryBytes,
Operation: "writeCode",
Operation: stateChange.WriteCode,
DataTrieChanges: nil,
}
adb.stateChangesCollector.AddStateChange(sc)
Expand Down Expand Up @@ -445,10 +445,10 @@ func (adb *AccountsDB) updateNewCodeEntry(newCodeHash []byte, newCode []byte) er
}

sc := &stateChange.StateChange{
Type: "write",
Type: stateChange.Write,
MainTrieKey: newCodeHash,
MainTrieVal: codeEntryBytes,
Operation: "writeCode",
Operation: stateChange.WriteCode,
DataTrieChanges: nil,
}
adb.stateChangesCollector.AddStateChange(sc)
Expand Down Expand Up @@ -654,9 +654,9 @@ func (adb *AccountsDB) removeDataTrie(baseAcc baseAccountHandler) error {
adb.journalize(entry)

sc := &stateChange.StateChange{
Type: "write",
Type: stateChange.Write,
MainTrieKey: baseAcc.AddressBytes(),
Operation: "removeDataTrie",
Operation: stateChange.RemoveDataTrie,
DataTrieChanges: nil,
}
adb.stateChangesCollector.AddStateChange(sc)
Expand Down Expand Up @@ -720,10 +720,10 @@ func (adb *AccountsDB) getAccount(address []byte, mainTrie common.Trie) (vmcommo
}

stateChange := &stateChange.StateChange{
Type: "read",
Type: stateChange.Read,
MainTrieKey: address,
MainTrieVal: val,
Operation: "getAccount",
Operation: stateChange.GetAccount,
DataTrieChanges: nil,
}
adb.stateChangesCollector.AddStateChange(stateChange)
Expand Down
4 changes: 2 additions & 2 deletions state/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ type StateChangesCollector interface {

// StateChange defines the behaviour of a state change holder
type StateChange interface {
GetType() string
GetType() data.ActionType
GetIndex() int32
GetTxHash() []byte
GetMainTrieKey() []byte
GetMainTrieVal() []byte
GetOperation() string
GetOperation() data.Operation
GetDataTrieChanges() []*data.DataTrieChange

SetTxHash(txHash []byte)
Expand Down
15 changes: 8 additions & 7 deletions state/stateChanges/dataAnalysisCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (

data "github.com/multiversx/mx-chain-core-go/data/stateChange"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/storage/mock"
"github.com/multiversx/mx-chain-go/testscommon/state"
"github.com/stretchr/testify/require"
)

func TestNewDataAnalysisCollector(t *testing.T) {
Expand Down Expand Up @@ -41,13 +42,13 @@ func TestDataAnalysisStateChangesCollector_AddStateChange(t *testing.T) {
require.Equal(t, 0, len(dsc.stateChanges))

dsc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
})
dsc.AddStateChange(&data.StateChange{
Type: "read",
Type: data.Read,
})
dsc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
})

require.Equal(t, 3, len(dsc.stateChanges))
Expand All @@ -66,7 +67,7 @@ func TestDataAnalysisStateChangesCollector_AddSaveAccountStateChange(t *testing.
nil,
&state.UserAccountStub{},
&data.StateChange{
Type: "saveAccount",
Type: data.Write,
Index: 2,
TxHash: []byte("txHash1"),
MainTrieKey: []byte("key1"),
Expand Down Expand Up @@ -102,7 +103,7 @@ func TestDataAnalysisStateChangesCollector_AddSaveAccountStateChange(t *testing.
&state.UserAccountStub{},
nil,
&data.StateChange{
Type: "saveAccount",
Type: data.Write,
Index: 2,
TxHash: []byte("txHash1"),
MainTrieKey: []byte("key1"),
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestDataAnalysisStateChangesCollector_AddSaveAccountStateChange(t *testing.
},
},
&data.StateChange{
Type: "saveAccount",
Type: data.Write,
Index: 2,
TxHash: []byte("txHash1"),
MainTrieKey: []byte("key1"),
Expand Down
5 changes: 3 additions & 2 deletions state/stateChanges/writeCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

data "github.com/multiversx/mx-chain-core-go/data/stateChange"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-go/state"
logger "github.com/multiversx/mx-chain-logger-go"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"

"github.com/multiversx/mx-chain-go/state"
)

var log = logger.GetOrCreate("state/stateChanges")
Expand Down Expand Up @@ -42,7 +43,7 @@ func (scc *stateChangesCollector) AddStateChange(stateChange state.StateChange)
defer scc.stateChangesMut.Unlock()

// TODO: add custom type for stateChange type
if stateChange.GetType() == "write" {
if stateChange.GetType() == data.Write {
scc.stateChanges = append(scc.stateChanges, stateChange)
}
}
Expand Down
33 changes: 17 additions & 16 deletions state/stateChanges/writeCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (

data "github.com/multiversx/mx-chain-core-go/data/stateChange"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-go/state"
"github.com/stretchr/testify/assert"

"github.com/multiversx/mx-chain-go/state"

"github.com/stretchr/testify/require"
)

func getDefaultStateChange() *data.StateChange {
return &data.StateChange{
Type: "write",
Type: data.Write,
}
}

Expand Down Expand Up @@ -52,7 +53,7 @@ func TestStateChangesCollector_GetStateChanges(t *testing.T) {
numStateChanges := 10
for i := 0; i < numStateChanges; i++ {
scc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
MainTrieKey: []byte(strconv.Itoa(i)),
})
}
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestStateChangesCollector_GetStateChanges(t *testing.T) {
numStateChanges := 10
for i := 0; i < numStateChanges; i++ {
scc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
MainTrieKey: []byte(strconv.Itoa(i)),
})
}
Expand All @@ -107,7 +108,7 @@ func TestStateChangesCollector_AddTxHashToCollectedStateChanges(t *testing.T) {
scc.AddTxHashToCollectedStateChanges([]byte("txHash0"), &transaction.Transaction{})

stateChange := &data.StateChange{
Type: "write",
Type: data.Write,
MainTrieKey: []byte("mainTrieKey"),
MainTrieVal: []byte("mainTrieVal"),
DataTrieChanges: []*data.DataTrieChange{{Key: []byte("dataTrieKey"), Val: []byte("dataTrieVal")}},
Expand Down Expand Up @@ -262,7 +263,7 @@ func TestStateChangesCollector_GetStateChangesForTx(t *testing.T) {
numStateChanges := 10
for i := 0; i < numStateChanges; i++ {
scc.AddStateChange(&data.StateChange{
Type: "write",
Type: data.Write,
// distribute evenly based on parity of the index
TxHash: []byte(fmt.Sprintf("hash%d", i%2)),
})
Expand All @@ -277,20 +278,20 @@ func TestStateChangesCollector_GetStateChangesForTx(t *testing.T) {
require.Equal(t, stateChangesForTx, map[string]*data.StateChanges{
"hash0": {
[]*data.StateChange{
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: "write", TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
{Type: data.Write, TxHash: []byte("hash0")},
},
},
"hash1": {
[]*data.StateChange{
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: "write", TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
{Type: data.Write, TxHash: []byte("hash1")},
},
},
})
Expand Down
12 changes: 6 additions & 6 deletions state/trackableDataTrie/trackableDataTrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ func (tdt *trackableDataTrie) RetrieveValue(key []byte) ([]byte, uint32, error)

log.Trace("retrieve value from trie", "key", key, "value", val, "account", tdt.identifier)

stateChange := &stateChange.StateChange{
Type: "read",
sc := &stateChange.StateChange{
Type: stateChange.Read,
MainTrieKey: tdt.identifier,
MainTrieVal: nil,
DataTrieChanges: []*stateChange.DataTrieChange{
{
Type: "read",
Type: stateChange.Read,
Key: key,
Val: val,
},
},
}
tdt.stateChangesCollector.AddStateChange(stateChange)
tdt.stateChangesCollector.AddStateChange(sc)

return val, depth, nil
}
Expand Down Expand Up @@ -292,7 +292,7 @@ func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]*stateChange.Dat
if wasDeleted {
deletedKeys = append(deletedKeys,
&stateChange.DataTrieChange{
Type: "write",
Type: stateChange.Write,
Key: []byte(key),
Val: nil,
},
Expand Down Expand Up @@ -323,7 +323,7 @@ func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]*stateChange.Dat
}

newData[dataEntry.index] = &stateChange.DataTrieChange{
Type: "write",
Type: stateChange.Write,
Key: dataTrieKey,
Val: dataTrieVal,
}
Expand Down
Loading