-
Notifications
You must be signed in to change notification settings - Fork 367
[staking] build staking view from blockdao if indexer height behind #4658
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d363c1
build staking view from blockdao if indexer height behind
envestcc e40318c
fix
envestcc bc6a7ce
add test
envestcc 1bad899
fix test
envestcc 7652017
Merge branch 'master' into viewbuilder
CoderZhi 932556e
address comment
envestcc 4c1106e
Merge remote-tracking branch 'upstream/master' into viewbuilder
envestcc b77d544
Merge remote-tracking branch 'upstream/master' into viewbuilder
envestcc c94370a
Merge branch 'master' into viewbuilder
CoderZhi ef07720
fix height not updated
envestcc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package staking | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/pkg/errors" | ||
|
|
||
| "github.com/iotexproject/iotex-core/v2/action" | ||
| "github.com/iotexproject/iotex-core/v2/action/protocol" | ||
| "github.com/iotexproject/iotex-core/v2/blockchain/block" | ||
| ) | ||
|
|
||
| type ( | ||
| BlockStore interface { | ||
| GetReceipts(uint64) ([]*action.Receipt, error) | ||
| HeaderByHeight(height uint64) (*block.Header, error) | ||
| } | ||
|
|
||
| contractStakeViewBuilder struct { | ||
| indexer ContractStakingIndexer | ||
| blockdao BlockStore | ||
| } | ||
| ) | ||
|
|
||
| func NewContractStakeViewBuilder( | ||
| indexer ContractStakingIndexer, | ||
| blockdao BlockStore, | ||
| ) *contractStakeViewBuilder { | ||
| return &contractStakeViewBuilder{ | ||
| indexer: indexer, | ||
| blockdao: blockdao, | ||
| } | ||
| } | ||
|
|
||
| func (b *contractStakeViewBuilder) Build(ctx context.Context, height uint64) (ContractStakeView, error) { | ||
| view, err := b.indexer.StartView(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| indexerHeight, err := b.indexer.Height() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if indexerHeight == height { | ||
| return view, nil | ||
| } | ||
| if indexerHeight > height { | ||
| return nil, errors.Errorf("indexer height %d is greater than requested height %d", indexerHeight, height) | ||
| } | ||
| if b.blockdao == nil { | ||
| return nil, errors.Errorf("blockdao is nil, cannot build view for height %d", height) | ||
| } | ||
| for h := indexerHeight + 1; h <= height; h++ { | ||
| receipts, err := b.blockdao.GetReceipts(h) | ||
| if err != nil { | ||
| return nil, errors.Wrapf(err, "failed to get receipts at height %d", h) | ||
| } | ||
| header, err := b.blockdao.HeaderByHeight(h) | ||
| if err != nil { | ||
| return nil, errors.Wrapf(err, "failed to get header at height %d", h) | ||
| } | ||
| ctx = protocol.WithBlockCtx(ctx, protocol.BlockCtx{ | ||
| BlockHeight: h, | ||
| BlockTimeStamp: header.Timestamp(), | ||
| }) | ||
| if err = view.AddBlockReceipts(ctx, receipts); err != nil { | ||
| return nil, errors.Wrapf(err, "failed to build view with block at height %d", h) | ||
| } | ||
| } | ||
| return view, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.