-
Notifications
You must be signed in to change notification settings - Fork 221
sync txs and miniblocks at bootstrap #7582
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
Changes from all commits
e21cf43
c61abe2
7ec25e8
5ac51d2
235f255
3b544b4
0b07f7e
49af3c3
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 |
|---|---|---|
|
|
@@ -23,7 +23,11 @@ import ( | |
| "github.com/multiversx/mx-chain-core-go/marshal" | ||
| logger "github.com/multiversx/mx-chain-logger-go" | ||
|
|
||
| "github.com/multiversx/mx-chain-go/epochStart" | ||
| "github.com/multiversx/mx-chain-go/epochStart/bootstrap/disabled" | ||
| "github.com/multiversx/mx-chain-go/process/asyncExecution/queue" | ||
| "github.com/multiversx/mx-chain-go/update" | ||
| updateSync "github.com/multiversx/mx-chain-go/update/sync" | ||
|
|
||
| "github.com/multiversx/mx-chain-go/common" | ||
| "github.com/multiversx/mx-chain-go/consensus" | ||
|
|
@@ -50,6 +54,7 @@ var _ closing.Closer = (*baseBootstrap)(nil) | |
| // sleepTime defines the time in milliseconds between each iteration made in syncBlocks method | ||
| const sleepTime = 50 * time.Millisecond | ||
| const minimumProcessWaitTime = time.Millisecond * 100 | ||
| const defaultTimeToWaitForRequestedData = 5 * time.Minute | ||
|
|
||
| // hdrInfo hold the data related to a header | ||
| type hdrInfo struct { | ||
|
|
@@ -146,6 +151,9 @@ type baseBootstrap struct { | |
| preparedForSyncAtBootstrap bool | ||
|
|
||
| repopulateTokensSupplies bool | ||
|
|
||
| miniBlocksSyncer epochStart.PendingMiniBlocksSyncHandler | ||
| txSyncer update.TransactionsSyncHandler | ||
| } | ||
|
|
||
| func (boot *baseBootstrap) getProcessWaitTime(round uint64) time.Duration { | ||
|
|
@@ -818,7 +826,7 @@ func (boot *baseBootstrap) prepareForSyncAtBoostrapIfNeeded() error { | |
| "currHeader nonce", currentHeader.GetNonce(), | ||
| ) | ||
|
|
||
| err := boot.prepareForSyncIfNeeded(syncingNonce) | ||
| err := boot.prepareForSyncIfNeeded(syncingNonce, true) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -990,7 +998,7 @@ func (boot *baseBootstrap) prepareForLegacySyncIfNeeded() error { | |
| // Finally, if everything works, the block will be committed and added into the processing queue. | ||
| // And all this mechanism will be reiterated for the next block. | ||
| func (boot *baseBootstrap) syncBlockV3(body data.BodyHandler, header data.HeaderHandler) error { | ||
| err := boot.prepareForSyncIfNeeded(header.GetNonce()) | ||
| err := boot.prepareForSyncIfNeeded(header.GetNonce(), false) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -1045,7 +1053,38 @@ func (boot *baseBootstrap) syncBlockV3(body data.BodyHandler, header data.Header | |
| return nil | ||
| } | ||
|
|
||
| func (boot *baseBootstrap) prepareForSyncIfNeeded(syncingNonce uint64) error { | ||
| func (boot *baseBootstrap) syncMiniBlocksAndTxsForHeader( | ||
| header data.HeaderHandler, | ||
| ) error { | ||
| boot.miniBlocksSyncer.ClearFields() | ||
| ctx, cancel := context.WithTimeout(context.Background(), defaultTimeToWaitForRequestedData) | ||
| err := boot.miniBlocksSyncer.SyncPendingMiniBlocks(header.GetMiniBlockHeaderHandlers(), ctx) | ||
| cancel() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| miniBlocks, err := boot.miniBlocksSyncer.GetMiniBlocks() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // sync all txs into pools | ||
|
|
||
| ctx, cancel = context.WithTimeout(context.Background(), defaultTimeToWaitForRequestedData) | ||
| err = boot.txSyncer.SyncTransactionsFor(miniBlocks, header.GetEpoch(), ctx) | ||
|
||
| cancel() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (boot *baseBootstrap) prepareForSyncIfNeeded( | ||
| syncingNonce uint64, | ||
| withTxs bool, | ||
| ) error { | ||
| if boot.preparedForSync { | ||
| return nil | ||
| } | ||
|
|
@@ -1067,6 +1106,13 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(syncingNonce uint64) error { | |
| return errGetBody | ||
| } | ||
|
|
||
| if withTxs { | ||
| err = boot.syncMiniBlocksAndTxsForHeader(currentHeader) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| err = boot.saveProposedTxsToPool(currentHeader, currentBody) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -1103,6 +1149,13 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(syncingNonce uint64) error { | |
| return errGetBody | ||
| } | ||
|
|
||
| if withTxs { | ||
| err = boot.syncMiniBlocksAndTxsForHeader(hdr) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| err = boot.saveProposedTxsToPool(hdr, body) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -2209,3 +2262,31 @@ func (boot *baseBootstrap) getHeaderMiniBlocks( | |
| func (boot *baseBootstrap) IsInterfaceNil() bool { | ||
| return boot == nil | ||
| } | ||
|
|
||
| func (boot *baseBootstrap) createTxSyncer() error { | ||
| var err error | ||
|
|
||
| syncMiniBlocksArgs := updateSync.ArgsNewPendingMiniBlocksSyncer{ | ||
| Storage: disabled.CreateMemUnit(), | ||
| Cache: boot.dataPool.MiniBlocks(), | ||
| Marshalizer: boot.marshalizer, | ||
| RequestHandler: boot.requestHandler, | ||
| } | ||
| boot.miniBlocksSyncer, err = updateSync.NewPendingMiniBlocksSyncer(syncMiniBlocksArgs) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| syncTxsArgs := updateSync.ArgsNewTransactionsSyncer{ | ||
| DataPools: boot.dataPool, | ||
| Storages: boot.store, | ||
| Marshaller: boot.marshalizer, | ||
| RequestHandler: boot.requestHandler, | ||
| } | ||
| boot.txSyncer, err = updateSync.NewTransactionsSyncer(syncTxsArgs) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return 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.
here ctx is reused but already canceled on L1062
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.
right, updated