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.
Merge branch 'main' of https://github.com/rollkit/rollkit into chandi…
…ni/avail-da
- Loading branch information
Showing
29 changed files
with
546 additions
and
244 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pull_request_rules: | ||
- name: backport patches to v0.11.x branch | ||
conditions: | ||
- base=main | ||
- label=backport:v0.11.x | ||
actions: | ||
backport: | ||
branches: | ||
- v0.11.x | ||
- name: backport patches to v0.10.x branch | ||
conditions: | ||
- base=main | ||
- label=backport:v0.10.x | ||
actions: | ||
backport: | ||
branches: | ||
- v0.10.x-lts |
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
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,60 @@ | ||
package block | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/rollkit/rollkit/types" | ||
) | ||
|
||
type BlockCache struct { | ||
blocks map[uint64]*types.Block | ||
hashes map[string]bool | ||
hardConfirmations map[string]bool | ||
mtx *sync.RWMutex | ||
} | ||
|
||
func NewBlockCache() *BlockCache { | ||
return &BlockCache{ | ||
blocks: make(map[uint64]*types.Block), | ||
hashes: make(map[string]bool), | ||
hardConfirmations: make(map[string]bool), | ||
mtx: new(sync.RWMutex), | ||
} | ||
} | ||
|
||
func (bc *BlockCache) getBlock(height uint64) (*types.Block, bool) { | ||
bc.mtx.Lock() | ||
defer bc.mtx.Unlock() | ||
block, ok := bc.blocks[height] | ||
return block, ok | ||
} | ||
|
||
func (bc *BlockCache) setBlock(height uint64, block *types.Block) { | ||
bc.mtx.Lock() | ||
defer bc.mtx.Unlock() | ||
bc.blocks[height] = block | ||
} | ||
|
||
func (bc *BlockCache) deleteBlock(height uint64) { | ||
bc.mtx.Lock() | ||
defer bc.mtx.Unlock() | ||
delete(bc.blocks, height) | ||
} | ||
|
||
func (bc *BlockCache) isSeen(hash string) bool { | ||
bc.mtx.Lock() | ||
defer bc.mtx.Unlock() | ||
return bc.hashes[hash] | ||
} | ||
|
||
func (bc *BlockCache) setSeen(hash string) { | ||
bc.mtx.Lock() | ||
defer bc.mtx.Unlock() | ||
bc.hashes[hash] = true | ||
} | ||
|
||
func (bc *BlockCache) setHardConfirmed(hash string) { | ||
bc.mtx.Lock() | ||
defer bc.mtx.Unlock() | ||
bc.hardConfirmations[hash] = true | ||
} |
Oops, something went wrong.