Skip to content

Commit

Permalink
updated core enums in state changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure committed Sep 24, 2024
1 parent 9f68130 commit ea2cf1a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
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 -
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
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
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

0 comments on commit ea2cf1a

Please sign in to comment.