-
Notifications
You must be signed in to change notification settings - Fork 204
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
State changes outport #6429
State changes outport #6429
Conversation
There are somethings that need to be addressed. Mainly about coupling |
e95122d
to
f492061
Compare
… into state-changes-outport # Conflicts: # epochStart/metachain/systemSCs_test.go # go.mod # go.sum # process/transaction/shardProcess.go # state/accountsDB.go # state/accountsDBApi.go # state/interface.go
…nto state-changes-outport # Conflicts: # epochStart/metachain/systemSCs_test.go # process/transaction/shardProcess.go # state/accountsDB.go # state/interface.go # state/stateChanges/writeCollector.go
go.mod
Outdated
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-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this indexer downgrade correct? @miiu96
@@ -134,6 +139,9 @@ func (odp *outportDataProvider) PrepareOutportSaveBlockData(arg ArgPrepareOutpor | |||
return nil, err | |||
} | |||
|
|||
stateChanges := odp.stateChangesCollector.GetStateChangesForTxs() | |||
odp.stateChangesCollector.Reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the reset on the commit block, after the indexing part.
Otherwise, in case there is no client for the outport block, you would not end up in this method and the reset would not be done.
state/accountsDB.go
Outdated
baseNewAcc, newAccOk := newAcc.(baseAccountHandler) | ||
baseOldAccount, _ := oldAcc.(baseAccountHandler) | ||
|
||
if !newAccOk { | ||
return nil, nil | ||
return make([]*stateChange.DataTrieChange, 0), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required because of a panic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly, I don't remember. Reverted to the previous implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BeniaminDrasovean can you check if this change would be problematic?
do we need to change the test instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok both ways.
state/accountsDB.go
Outdated
@@ -918,7 +918,8 @@ func (adb *AccountsDB) commit() ([]byte, error) { | |||
return nil, err | |||
} | |||
|
|||
adb.stateChangesCollector.Reset() | |||
//TODO: discuss the workflow. If reset here, the outport driver won't be able to pick up the changes. | |||
//adb.stateChangesCollector.Reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the reset in the processor (shardProcessor & metaProcessor) in the CommitBlock, after calling sp.indexBlockIfNeeded(bodyHandler, headerHash, headerHandler, lastBlockHeader)
on shardProcessor, and
after calling mp.indexBlock(header, headerHash, body, lastMetaBlock, notarizedHeadersHashes, rewardsTxs)
on metaProcessor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to remove also the commented code after we agree on the workflow.
state/stateChanges/writeCollector.go
Outdated
@@ -136,6 +103,47 @@ func (scc *stateChangesCollector) getStateChangesForTxs() ([]StateChangesForTx, | |||
return stateChangesForTxs, nil | |||
} | |||
|
|||
// GetStateChangesForTxs will retrieve the state changes linked with the tx hash. | |||
func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.StateChanges { | |||
scc.stateChangesMut.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a RLock would be sufficient, as you are just reading the state changes not modifying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are actually appending to the map in case the hash is already present. Can be seen at state/stateChanges/writeCollector.go:130
state/accountsDB.go
Outdated
baseNewAcc, newAccOk := newAcc.(baseAccountHandler) | ||
baseOldAccount, _ := oldAcc.(baseAccountHandler) | ||
|
||
if !newAccOk { | ||
return nil, nil | ||
return make([]*stateChange.DataTrieChange, 0), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BeniaminDrasovean can you check if this change would be problematic?
do we need to change the test instead?
state/accountsDB.go
Outdated
@@ -918,7 +918,8 @@ func (adb *AccountsDB) commit() ([]byte, error) { | |||
return nil, err | |||
} | |||
|
|||
adb.stateChangesCollector.Reset() | |||
//TODO: discuss the workflow. If reset here, the outport driver won't be able to pick up the changes. | |||
//adb.stateChangesCollector.Reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to remove also the commented code after we agree on the workflow.
state/stateChanges/writeCollector.go
Outdated
}, | ||
} | ||
} else { | ||
stateChangesForTxs[txHash].StateChanges = append(sc.StateChanges, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we should not append to the sc.StateChanges, but to the stateChangesForTxs[txHash].StateChanges
then we can have the RWMutex as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add some unit tests for GetStateChangesForTxs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sc is assigned that exact value in the if statement above.
if sc, ok := stateChangesForTxs[txHash]; !ok {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it is very confusing as it is. Will use the same variable name for both.
@@ -7,3 +7,6 @@ var ErrHostIsClosed = errors.New("server is closed") | |||
|
|||
// ErrNilHost signals that a nil host has been provided | |||
var ErrNilHost = errors.New("nil host provided") | |||
|
|||
// ErrNilStateChangesCollector signals that a nil state change collector has been provided. | |||
var ErrNilStateChangesCollector = errors.New("nil state changes collector provided") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is used here: state/accountsDB.go:163
state/accountsDB.go
Outdated
baseNewAcc, newAccOk := newAcc.(baseAccountHandler) | ||
baseOldAccount, _ := oldAcc.(baseAccountHandler) | ||
|
||
if !newAccOk { | ||
return nil, nil | ||
return make([]*stateChange.DataTrieChange, 0), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok both ways.
"github.com/multiversx/mx-chain-go/state/stateChanges" | ||
) | ||
|
||
type StateChangesCollectorStub struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
process/block/metablock_test.go
Outdated
@@ -919,6 +920,9 @@ func TestMetaProcessor_CommitBlockStorageFailsForHeaderShouldNotReturnError(t *t | |||
return &block.Header{}, []byte("hash"), nil | |||
} | |||
arguments.BlockTracker = blockTrackerMock | |||
arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{ | |||
ResetCalled: func() {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that the resetCalled is empty, is this any different from the default implementation in StateChangesCollectorStub?
otherwise I think it can be removed here and just have
arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{}
same for line 1057
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
state/accountsDB.go
Outdated
if check.IfNil(args.StateChangesCollector) { | ||
return ErrNilStateChangesCollector | ||
} | ||
if check.IfNil(args.StateChangesCollector) { return ErrNilStateChangesCollector } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you reformat this line? (the return on the next line, like in previous checks)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
Reasoning behind the pull request
Proposed changes
Driver
interface that will send the state changes collected.Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
feat
branch created?feat
branch merging, do all satellite projects have a proper tag insidego.mod
?