-
Notifications
You must be signed in to change notification settings - Fork 221
Fixes synchronized state #7579
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
Fixes synchronized state #7579
Changes from all commits
2aecc3c
a5a995d
2e952e4
84604d5
b3ba86d
5e79fb6
9f6edb1
410de51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,9 +21,10 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-core-go/data/typeConverters" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-core-go/hashing" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-core-go/marshal" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-go/process/asyncExecution/queue" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| logger "github.com/multiversx/mx-chain-logger-go" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-go/process/asyncExecution/queue" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-go/common" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-go/consensus" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/multiversx/mx-chain-go/dataRetriever" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1051,42 +1052,12 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(syncingNonce uint64) error { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| currentHeader := boot.getCurrentBlock() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| currentHeaderHash := boot.getCurrentBlockHash() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecResult, err := process.GetPrevBlockLastExecutionResult(boot.chainHandler) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecResultsHandler, err := common.ExtractBaseExecutionResultHandler(lastExecResult) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutionResultHeaderNonce, err := boot.getExecutionResultHeaderNonceForSyncStart(syncingNonce, currentHeader, currentHeaderHash) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug("prepareForSyncIfNeeded", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "syncingNonce", syncingNonce, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "currHeader nonce", currentHeader.GetNonce(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "currHeader hash", currentHeaderHash, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "lastExecRes nonce", lastExecResultsHandler.GetHeaderNonce(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "lastExecRes hash", lastExecResultsHandler.GetHeaderHash(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "lastExecRes rootHash", lastExecResultsHandler.GetRootHash(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutedHash := lastExecResultsHandler.GetHeaderHash() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutedHeader, err := boot.getHeader(lastExecutedHash) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| rootHash := lastExecResultsHandler.GetRootHash() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| txPool := boot.poolsHolder.Transactions() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| err = txPool.OnExecutedBlock(lastExecutedHeader, rootHash) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| txPool.ResetTracker() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutedNonce := lastExecutedHeader.GetNonce() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if syncingNonce == lastExecutedNonce+2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if syncingNonce == lastExecutionResultHeaderNonce+2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // the ideal/most common case: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // the previous block was already processed, its nonce should have been syncingNonce-1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // and it notarized its previous block, which should have had nonce equal to syncingNonce-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1120,7 +1091,7 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(syncingNonce uint64) error { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // if there are multiple headers in between the syncing header and the last one executed, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // add them into the queue and pool | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for i := lastExecutedNonce + 1; i < syncingNonce; i++ { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for i := lastExecutionResultHeaderNonce + 1; i < syncingNonce; i++ { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| hdr, hdrHash, errGetHdr := boot.getHeaderFromPoolWithNonce(i) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if errGetHdr != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug("prepareForSyncIfNeeded: failed to get header with nonce", "nonce", i, "error", errGetHdr) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1132,7 +1103,7 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(syncingNonce uint64) error { | |||||||||||||||||||||||||||||||||||||||||||||||||
| return errGetBody | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| err := boot.saveProposedTxsToPool(hdr, body) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| err = boot.saveProposedTxsToPool(hdr, body) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1160,6 +1131,58 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(syncingNonce uint64) error { | |||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| func (boot *baseBootstrap) getExecutionResultHeaderNonceForSyncStart( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| syncingNonce uint64, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| currentHeader data.HeaderHandler, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| currentHeaderHash []byte, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) (uint64, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1134
to
+1138
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastNotarizedExecResult, err := process.GetPrevBlockLastExecutionResult(boot.chainHandler) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0, err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastNotarizedExecResultsHandler, err := common.ExtractBaseExecutionResultHandler(lastNotarizedExecResult) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0, err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug("getExecutionResultHeaderNonceForSyncStart", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "syncingNonce", syncingNonce, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "currHeader nonce", currentHeader.GetNonce(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "currHeader hash", currentHeaderHash, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "lastNotarizedExecRes nonce", lastNotarizedExecResultsHandler.GetHeaderNonce(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "lastNotarizedExecRes hash", lastNotarizedExecResultsHandler.GetHeaderHash(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "lastNotarizedExecRes rootHash", lastNotarizedExecResultsHandler.GetRootHash(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastNotarizedExecutedHash := lastNotarizedExecResultsHandler.GetHeaderHash() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| lastNotarizedExecutedHeader, err := boot.getHeader(lastNotarizedExecutedHash) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0, err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| rootHash := lastNotarizedExecResultsHandler.GetRootHash() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| txPool := boot.poolsHolder.Transactions() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| err = txPool.OnExecutedBlock(lastNotarizedExecutedHeader, rootHash) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| txPool.ResetTracker() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0, err | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutionResultNonce := lastNotarizedExecutedHeader.GetNonce() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // in case there is a more recent execution result available, use it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutionResult := boot.chainHandler.GetLastExecutionResult() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any chance that this happens right before we call txPool.OnExecutedBlock on L1167? would that be an ambiguous case where tx pool has last executed different than what this method returns?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that can happen. The onExecute needs to be done with the latest notarized execution result not with the last available execution result. The last notarized execution result cannot change for the node if the node is not committing a new block that has passed consensus, either on the consensus flow, or on the sync flow. This here is preceding the sync flow. |
||||||||||||||||||||||||||||||||||||||||||||||||||
| if !check.IfNil(lastExecutionResult) && lastExecutionResult.GetHeaderNonce() > lastExecutionResultNonce { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutionResultNonce = lastExecutionResult.GetHeaderNonce() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug("getExecutionResultHeaderNonceForSyncStart", "lastExecutionResultNonce", lastExecutionResultNonce) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return lastExecutionResultNonce, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1173
to
+1183
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| lastExecutionResultNonce := lastNotarizedExecutedHeader.GetNonce() | |
| // in case there is a more recent execution result available, use it | |
| lastExecutionResult := boot.chainHandler.GetLastExecutionResult() | |
| if !check.IfNil(lastExecutionResult) && lastExecutionResult.GetHeaderNonce() > lastExecutionResultNonce { | |
| lastExecutionResultNonce = lastExecutionResult.GetHeaderNonce() | |
| } | |
| log.Debug("getExecutionResultHeaderNonceForSyncStart", "lastExecutionResultNonce", lastExecutionResultNonce) | |
| return lastExecutionResultNonce, nil | |
| // executionResultHeaderNonce starts from the last notarized executed header | |
| // and may be updated to a more recent execution result header nonce if available. | |
| executionResultHeaderNonce := lastNotarizedExecutedHeader.GetNonce() | |
| // in case there is a more recent execution result available, use it | |
| lastExecutionResult := boot.chainHandler.GetLastExecutionResult() | |
| if !check.IfNil(lastExecutionResult) && lastExecutionResult.GetHeaderNonce() > executionResultHeaderNonce { | |
| executionResultHeaderNonce = lastExecutionResult.GetHeaderNonce() | |
| } | |
| log.Debug("getExecutionResultHeaderNonceForSyncStart", "executionResultHeaderNonce", executionResultHeaderNonce) | |
| return executionResultHeaderNonce, 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.
i do not think you need this line. Inside the for, it would be enough.