Skip to content

Commit

Permalink
remove useless latestBlock from blockPoller initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Feb 6, 2024
1 parent 4db49ff commit 0d43042
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Operators, you should copy/paste content of this content straight to your projec

If you were at `firehose-core` version `1.0.0` and are bumping to `1.1.0`, you should copy the content between those 2 version to your own repository, replacing placeholder value `fire{chain}` with your chain's own binary.

## v1.1.3

* Removed useless chainLatestFinalizeBlock from blockPoller initialization

## v1.1.2

* Added `Arweave` to known list of Block model.
Expand Down
19 changes: 3 additions & 16 deletions blockpoller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,15 @@ func New(
return b
}

func (p *BlockPoller) Run(ctx context.Context, startBlockNum uint64, chainLatestFinalizeBlock bstream.BlockRef) error {
func (p *BlockPoller) Run(ctx context.Context, startBlockNum uint64) error {
p.startBlockNumGate = startBlockNum
resolveStartBlockNum := resolveStartBlock(startBlockNum, chainLatestFinalizeBlock.Num())
p.logger.Info("starting poller",
zap.Uint64("start_block_num", startBlockNum),
zap.Stringer("chain_latest_finalize_block", chainLatestFinalizeBlock),
zap.Uint64("resolved_start_block_num", resolveStartBlockNum),
)

p.blockHandler.Init()

startBlock, err := p.blockFetcher.Fetch(ctx, resolveStartBlockNum)
startBlock, err := p.blockFetcher.Fetch(ctx, startBlockNum)
if err != nil {

return fmt.Errorf("unable to fetch start block %d: %w", resolveStartBlockNum, err)
return fmt.Errorf("unable to fetch start block %d: %w", startBlockNum, err)
}

return p.run(startBlock.AsRef())
Expand Down Expand Up @@ -215,10 +209,3 @@ func prevBlkInSeg(blocks []*forkable.Block) uint64 {
}
return blocks[0].Object.(*block).ParentNum
}

func resolveStartBlock(startBlockNum, chainLatestFinalizeBlock uint64) uint64 {
if chainLatestFinalizeBlock < startBlockNum {
return chainLatestFinalizeBlock
}
return startBlockNum
}
18 changes: 0 additions & 18 deletions blockpoller/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,6 @@ func TestForkHandler_run(t *testing.T) {
}
}

func TestForkHandler_resolveStartBlock(t *testing.T) {
tests := []struct {
startBlockNum uint64
finalizedBlockNum uint64
expected uint64
}{
{90, 100, 90},
{100, 100, 100},
{110, 100, 100},
}

for _, test := range tests {
t.Run("", func(t *testing.T) {
assert.Equal(t, test.expected, resolveStartBlock(test.startBlockNum, test.finalizedBlockNum))
})
}
}

func TestForkHandler_fire(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 0d43042

Please sign in to comment.