-
Notifications
You must be signed in to change notification settings - Fork 328
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
[factory] add parent to workingset #4539
base: master
Are you sure you want to change the base?
Conversation
Quality Gate passedIssues Measures |
@@ -356,7 +360,8 @@ func (sf *factory) Validate(ctx context.Context, blk *block.Block) error { | |||
if err := ws.ValidateBlock(ctx, blk); err != nil { | |||
return errors.Wrap(err, "failed to validate block with workingset in factory") | |||
} | |||
sf.putIntoWorkingSets(key, ws) | |||
sf.workingsets.Add(key, ws) | |||
sf.workingsets.Add(ws.height, ws) |
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 success validation for block n
, validation of the next block may continue which needs the state changes in this block, so adding ws
to cache, which will become parent of next block's workingset
@@ -398,7 +403,8 @@ func (sf *factory) NewBlockBuilder( | |||
|
|||
blkCtx := protocol.MustGetBlockCtx(ctx) | |||
key := generateWorkingSetCacheKey(blkBuilder.GetCurrentBlockHeader(), blkCtx.Producer.String()) | |||
sf.putIntoWorkingSets(key, ws) | |||
sf.workingsets.Add(key, ws) | |||
sf.workingsets.Add(ws.height, ws) |
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 used by new block proposal, so for the same reason adding ws
to cache
} | ||
ws.detachParent() |
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 used by CommitBlock()
, at this time parent of current ws
must have successfully committed his state changes into stateDB, so the current ws
must only rely on itself when processing the block
func (sf *factory) putIntoWorkingSets(key hash.Hash256, ws *workingSet) { | ||
sf.mutex.Lock() | ||
defer sf.mutex.Unlock() | ||
sf.workingsets.Add(key, ws) |
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.
sf.workingsets
is thread-safe cache, so no need to 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.
quick clean-up not relevant to primary PR
break | ||
} | ||
} | ||
} |
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.
both factory and statedb have the same workingset cache.LRUCache
, these can become a new small component WorkingSetCollection
later
} | ||
} | ||
if fCtx.CorrectTxLogIndex { | ||
updateReceiptIndex(receipts) |
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 func is not used any more
@@ -322,6 +318,9 @@ func (ws *workingSet) freshAccountConversion(ctx context.Context, actCtx *protoc | |||
|
|||
// Commit persists all changes in RunActions() into the DB | |||
func (ws *workingSet) Commit(ctx context.Context) error { | |||
if err := ws.verifyParent(); err != nil { | |||
return err | |||
} |
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.
if parent is abandoned, the workingset is not valid, abort here
@@ -508,6 +519,9 @@ func (ws *workingSet) Process(ctx context.Context, actions []*action.SealedEnvel | |||
} | |||
|
|||
func (ws *workingSet) processWithCorrectOrder(ctx context.Context, actions []*action.SealedEnvelope) error { | |||
if err := ws.verifyParent(); err != nil { | |||
return err | |||
} |
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.
if parent is abandoned, the workingset is not valid, abort here
Description
Prep for pipelined
ValidateBlock/CommitBlock
.Fixes #(issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: