Skip to content

Commit

Permalink
prog
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Oct 11, 2023
1 parent 85005b6 commit 3f8692e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (ce *Exchange) GetRangeByHeight(
from *header.ExtendedHeader,
to uint64,
) ([]*header.ExtendedHeader, error) {
amount := to - from.Height()
amount := to - (from.Height() + 1)
headers, err := ce.getRangeByHeight(ctx, from.Height()+1, amount)
if err != nil {
return nil, err
Expand Down
14 changes: 10 additions & 4 deletions core/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {
genHeader, err := ce.Get(ctx, genBlock.Header.Hash().Bytes())
require.NoError(t, err)

// request headers from height 1 to 10 (1:10]
headers, err := ce.GetRangeByHeight(context.Background(), genHeader, 10)
to := uint64(10)
expectedFirstHeightInRange := genHeader.Height() + 1
expectedLastHeightInRange := to - 1
expectedLenHeaders := to - expectedFirstHeightInRange

// request headers from height 1 to 10 [2:10)
headers, err := ce.GetRangeByHeight(context.Background(), genHeader, to)
require.NoError(t, err)

assert.Equal(t, 9, len(headers))
assert.Equal(t, uint64(10), headers[len(headers)-1].Height())
assert.Len(t, headers, int(expectedLenHeaders))
assert.Equal(t, expectedFirstHeightInRange, headers[0].Height())
assert.Equal(t, expectedLastHeightInRange, headers[len(headers)-1].Height())
}

func createCoreFetcher(t *testing.T, cfg *testnode.Config) (*BlockFetcher, testnode.Context) {
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/header/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *Service) GetRangeByHeight(
from *header.ExtendedHeader,
to uint64,
) ([]*header.ExtendedHeader, error) {
return s.store.GetRange(ctx, from.Height()+1, to)
return s.store.GetRangeByHeight(ctx, from, to)
}

func (s *Service) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error) {
Expand Down

0 comments on commit 3f8692e

Please sign in to comment.