forked from rollkit/rollkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use channel instead of sync cond for RetrieveLoop and blockStoreRetri… (
rollkit#1152) <!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Resolves: rollkit#1132, resolves: rollkit#1153 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords
- Loading branch information
1 parent
344d382
commit 63486ad
Showing
3 changed files
with
77 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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 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,43 @@ | ||
package block | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/rollkit/rollkit/types" | ||
) | ||
|
||
// Maintains blocks that need to be published to DA layer | ||
type PendingBlocks struct { | ||
pendingBlocks []*types.Block | ||
mtx *sync.RWMutex | ||
} | ||
|
||
func NewPendingBlocks() *PendingBlocks { | ||
return &PendingBlocks{ | ||
pendingBlocks: make([]*types.Block, 0), | ||
mtx: new(sync.RWMutex), | ||
} | ||
} | ||
|
||
func (pb *PendingBlocks) getPendingBlocks() []*types.Block { | ||
pb.mtx.RLock() | ||
defer pb.mtx.RUnlock() | ||
return pb.pendingBlocks | ||
} | ||
|
||
func (pb *PendingBlocks) isEmpty() bool { | ||
pendingBlocks := pb.getPendingBlocks() | ||
return len(pendingBlocks) == 0 | ||
} | ||
|
||
func (pb *PendingBlocks) addPendingBlock(block *types.Block) { | ||
pb.mtx.Lock() | ||
defer pb.mtx.Unlock() | ||
pb.pendingBlocks = append(pb.pendingBlocks, block) | ||
} | ||
|
||
func (pb *PendingBlocks) resetPendingBlocks() { | ||
pb.mtx.Lock() | ||
defer pb.mtx.Unlock() | ||
pb.pendingBlocks = make([]*types.Block, 0) | ||
} |
This file contains 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