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

[factory] add parent to workingset #4539

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

[factory] add parent to workingset #4539

wants to merge 2 commits into from

Conversation

dustinxie
Copy link
Member

Description

Prep for pipelined ValidateBlock/CommitBlock.

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

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

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@dustinxie dustinxie marked this pull request as draft January 9, 2025 06:39
Copy link

sonarqubecloud bot commented Jan 9, 2025

@@ -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)
Copy link
Member Author

@dustinxie dustinxie Jan 9, 2025

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)
Copy link
Member Author

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()
Copy link
Member Author

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)
Copy link
Member Author

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

Copy link
Member Author

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
}
}
}
Copy link
Member Author

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)
Copy link
Member Author

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
}
Copy link
Member Author

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
}
Copy link
Member Author

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

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.

1 participant