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

Eoe scheduled roothash sync #3456

Merged

Conversation

AdoAdoAdo
Copy link
Contributor

@AdoAdoAdo AdoAdoAdo commented Sep 20, 2021

This PR enables the use of the scheduled roothash on epoch start instead of the intermediate roothash.
There are several changes done in order to make this possible such as synchronizing extra blocks/miniblocks, changing what roothash is used for the snapshot so that new nodes or shuffled nodes can synchronize from the epoch start block and have the same security guarantees as before introducing the scheduled smart contract calls.

The unit tests will come in a follow up PR targeted to feat/scheduled-sc-execution

@AdoAdoAdo AdoAdoAdo marked this pull request as ready for review October 8, 2021 08:27
if !ok {
return epochStart.ErrWrongTypeAssertion
}

log.Debug("start in epoch bootstrap: started syncUserAccountsState")
err = e.syncUserAccountsState(ownShardHdr.GetRootHash())
ownShardHdr, rootHashToSync, withScheduled, additionalHeaders, err := e.getDataToSync(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an private DTO here -> type dataToSync struct {} with all these members: ownShardHdr, rootHashToSync, withScheduled, additionalHeaders

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return nil, nil, nil, err
}

ownShardHdr, headers, err := e.dataSyncerWithScheduled.updateSyncDataIfNeeded(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be on single line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

mbs = append(mbs, processedMiniBlockHeaders[i])
crossMbsProcessed[mbHeader.GetSenderShardID()] = mbs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved after L195, not needed to be called each time

Copy link
Contributor Author

@AdoAdoAdo AdoAdoAdo Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, append can change the mbs pointer

header data.HeaderHandler,
withScheduled bool,
) ([]bootstrapStorage.MiniBlocksInMeta, []bootstrapStorage.PendingMiniBlocksInfo, error) {
log.Debug("TESTTEST: getProcessedAndPendingMiniBlocksWithScheduled", "withScheduled", withScheduled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it or refactor the message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored

processedMiniBlocks = removeMbsFromProcessed(processedMiniBlocks, mapMbHeaderHandlers)
pendingMiniBlocks = addMbsToPending(pendingMiniBlocks, mapMbHeaderHandlers)

return processedMiniBlocks, pendingMiniBlocks, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil instead err to be more clear that in this point there is no error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -1057,6 +1068,13 @@ func (boot *baseBootstrap) requestHeaders(fromNonce uint64, toNonce uint64) {
}
}

// SetNodeSyncState sets the synced state of the node
func (boot *baseBootstrap) SetNodeSyncState(synced bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

rootHash = scheduledRootHash
} else {
log.Debug("storageBootstrapper.applyHeaderInfo scheduledTxsExecutionHandler.GetScheduledRootHashForHeader", "error", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a real error, if one header does not have sheduled txs inside. We can remove L262 and L265 and add in L267 a log with both, rootHash an scheduledRootHash like this one:

log.Debug("storageBootstrapper.applyHeaderInfo", "rootHash", rootHash, "scheduledRootHash", scheduledRootHash)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return nil, err
}

cache, err := lrucache.NewCache(10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use a constant with a properly name instead 10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -58,7 +58,7 @@ func NewPendingTransactionsSyncer(args ArgsNewPendingTransactionsSyncer) (*pendi
return nil, process.ErrNilRequestHandler
}

p := &pendingTransactions{
p := &transactionsSync{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t or ts instead p here and for all pointer receivers in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -165,7 +165,7 @@ func (p *pendingTransactions) requestTransactionsFor(miniBlock *block.MiniBlock)
}

// receivedMiniBlock is a callback function when a new transactions was received
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove or refactor this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

epochStart/bootstrap/process.go Outdated Show resolved Hide resolved
if !ok {
return epochStart.ErrWrongTypeAssertion
}

log.Debug("start in epoch bootstrap: started syncUserAccountsState")
err = e.syncUserAccountsState(ownShardHdr.GetRootHash())
ownShardHdr, rootHashToSync, withScheduled, additionalHeaders, err := e.getDataToSync(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

epochStart/bootstrap/process.go Show resolved Hide resolved
header data.HeaderHandler,
withScheduled bool,
) ([]bootstrapStorage.MiniBlocksInMeta, []bootstrapStorage.PendingMiniBlocksInfo, error) {
log.Debug("TESTTEST: getProcessedAndPendingMiniBlocksWithScheduled", "withScheduled", withScheduled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

for i := range list {
for j, mbHash := range list[i].MiniBlocksHashes {
if bytes.Equal(mbHash, mbHandler.GetHash()) {
list[i].MiniBlocksHashes = append(list[i].MiniBlocksHashes[j:], list[i].MiniBlocksHashes[:j+1]...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for the first

epochStart/bootstrap/startInEpochScheduled.go Outdated Show resolved Hide resolved
@@ -70,7 +70,7 @@ import (
)

// StepDelay is used so that transactions can disseminate properly
var StepDelay = time.Second / 10
var StepDelay = time.Millisecond * 180
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for @raduchis check teamcity

process/block/baseProcess.go Outdated Show resolved Hide resolved
@@ -1123,6 +1129,11 @@ func (sp *shardProcessor) snapShotEpochStartFromMeta(header data.ShardHeaderHand
}

rootHash := epochStartShData.RootHash
schRootHash := epochStartShData.GetScheduledRootHash()
if schRootHash!= nil{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and a space before {

process/block/shardblock.go Outdated Show resolved Hide resolved
}

ownShardHdr, rootHashToSync, headers, err := e.updateDataForScheduled(shardNotarizedHeader)
res.ownShardHdr, res.rootHashToSync, res.additionalHeaders, err = e.updateDataForScheduled(shardNotarizedHeader)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: res, err := e.updateDataForScheduled(shardNotarizedHeader), move L899-L895 inside updateDataForScheduled, and return nil, err in L903 and 908

@SebastianMarian SebastianMarian merged commit 0768cae into feat/scheduled-sc-execution Oct 19, 2021
@SebastianMarian SebastianMarian deleted the eoe-scheduled-roothash-sync branch October 19, 2021 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants