-
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
Proposer optimisation #6186
Proposer optimisation #6186
Conversation
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.
Normal allin test: 1.7.11-f7efd0fc48 -> proposer-optimisation-e105bd9b53
--- Specific errors ---
block hash does not match 249
wrong nonce in block 215
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0
/------/
--- Statistics ---
Nr. of all ERRORS: 1
Nr. of all WARNS: 252
Nr. of new ERRORS: 1
Nr. of new WARNS: 0
Nr. of PANICS: 0
/------/
--- ERRORS ---
/------/
@@ -170,7 +171,7 @@ type TransactionCoordinator interface { | |||
VerifyCreatedBlockTransactions(hdr data.HeaderHandler, body *block.Body) error | |||
GetCreatedInShardMiniBlocks() []*block.MiniBlock | |||
VerifyCreatedMiniBlocks(hdr data.HeaderHandler, body *block.Body) error | |||
AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler) error | |||
AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error |
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.
Maybe rename key
to originalTransactionHash
, to be more explicit?
Later edit: comment can be ignored, since key
may have a different meaning.
bpp.mapProcessedResult[key] = append(bpp.mapProcessedResult[key], txHash) | ||
pr, ok := bpp.mapProcessedResult[string(key)] | ||
if !ok { | ||
return |
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.
An extra confirmation - this is a valid case?
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.
Normally should not exist, the intermediate results are added on a key that was previously registered, before starting the execution of the tx that generated the result.
Now the exception comes in case of scheduled txs, where the results are from previous block but are added on the next block and do not have any previously registered key (they don't need one as they don't need to revert).
In this case key comes as nil and it would not be found in the mapProcessedResult.
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.
Wouldn't be better to check for key == nil in that case ?
@@ -28,6 +29,14 @@ type txInfo struct { | |||
*txShardInfo | |||
} | |||
|
|||
type processedResult 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.
Even is not exported, perhaps we can add some comments for each field, e.g. "the hash of the parent tx", "a lookup map with hashes of children txs" or something similar (since this part of the code is so important).
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.
yes. a little bit more explicit names could be added.
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.
renamed:
parent -> parentKey
children -> childrenKeys
the keys we are currently using are indeed the hashes, but could be anything.
|
||
func (bpp *basePostProcessor) removeProcessedResultsAndLinks(key string) ([][]byte, bool) { | ||
processedResults, ok := bpp.mapProcessedResult[key] | ||
if !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.
This case is for transactions without results?
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, also for blocks without miniblocks - valid case, miniblocks without transactions (hopefully we don't have this case but should be fine even if there are), or transactions without scrs - valid case.
@@ -28,6 +29,14 @@ type txInfo struct { | |||
*txShardInfo | |||
} | |||
|
|||
type processedResult 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.
yes. a little bit more explicit names could be added.
@@ -237,7 +238,7 @@ func (irp *intermediateResultsProcessor) VerifyInterMiniBlocks(body *block.Body) | |||
} | |||
|
|||
// AddIntermediateTransactions adds smart contract results from smart contract processing for cross-shard calls | |||
func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data.TransactionHandler) error { | |||
func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error { |
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.
key is too generic - add a name here - maybe miniBlockHash ?
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 can be different things, such as a txhash, a scr hash or nil in case of scheduled txs results
|
||
bpp.mapProcessedResult[string(key)] = pr | ||
|
||
if parentKey != 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.
len(parentKey) > 0 ?
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
…n-go into proposer-optimisation
a75c3df
@@ -28,6 +29,14 @@ type txInfo struct { | |||
*txShardInfo | |||
} | |||
|
|||
type processedResult 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.
renamed:
parent -> parentKey
children -> childrenKeys
the keys we are currently using are indeed the hashes, but could be anything.
|
||
func (bpp *basePostProcessor) removeProcessedResultsAndLinks(key string) ([][]byte, bool) { | ||
processedResults, ok := bpp.mapProcessedResult[key] | ||
if !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.
right, also for blocks without miniblocks - valid case, miniblocks without transactions (hopefully we don't have this case but should be fine even if there are), or transactions without scrs - valid case.
|
||
bpp.mapProcessedResult[string(key)] = pr | ||
|
||
if parentKey != 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.
done
bpp.mapProcessedResult[key] = append(bpp.mapProcessedResult[key], txHash) | ||
pr, ok := bpp.mapProcessedResult[string(key)] | ||
if !ok { | ||
return |
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.
Normally should not exist, the intermediate results are added on a key that was previously registered, before starting the execution of the tx that generated the result.
Now the exception comes in case of scheduled txs, where the results are from previous block but are added on the next block and do not have any previously registered key (they don't need one as they don't need to revert).
In this case key comes as nil and it would not be found in the mapProcessedResult.
@@ -237,7 +238,7 @@ func (irp *intermediateResultsProcessor) VerifyInterMiniBlocks(body *block.Body) | |||
} | |||
|
|||
// AddIntermediateTransactions adds smart contract results from smart contract processing for cross-shard calls | |||
func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data.TransactionHandler) error { | |||
func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error { |
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 can be different things, such as a txhash, a scr hash or nil in case of scheduled txs results
@@ -963,7 +964,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( | |||
return err | |||
} | |||
|
|||
err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}) | |||
err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}, originalTxHash) |
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 should be verified, if the originalTxHash or the userTxHash should be used.
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.
originalTxHash has to be used. as in case of revert, the used key for this is the originalTxHash.
@@ -985,7 +986,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( | |||
} | |||
|
|||
if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) { | |||
err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{originalTx}) | |||
err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{originalTx}, originalTxHash) |
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.
should be checked here as well if userTxHash should be used.
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.
originalTxHash has to be used. as in case of revert, the used key for this is the originalTxHash.
@@ -890,7 +891,7 @@ func (txProc *txProcessor) processUserTx( | |||
return returnCode, nil | |||
} | |||
|
|||
err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrFromTx}) | |||
err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrFromTx}, txHash) |
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.
txhash is for relay transaction, should be checked if here we should use the user tx hash 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.
originalTxHash has to be used. as in case of revert, the used key for this is the originalTxHash.
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 could be check with an integration test 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.
Normal allin test: v1.7.13-dev-config-aebb55e8e0 -> proposer-optimisation-6042eaaf4e
--- Specific errors ---
block hash does not match 327
wrong nonce in block 235
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0
/------/
--- Statistics ---
Nr. of all ERRORS: 0
Nr. of all WARNS: 247
Nr. of new ERRORS: 0
Nr. of new WARNS: 0
Nr. of PANICS: 0
/------/
--- ERRORS ---
/------/
--- WARNINGS ---
/------/
Reasoning behind the pull request
There is some degradation on the proposer during execution, which does not happen on the validators that vote the proposed block
Proposed changes
The process that takes most of this time is the management of generated smart contract results and their registration in the intermediate processors, that will be used afterwards in the case of reverts.
This will be refactored and optimized.
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
?