Skip to content

Commit

Permalink
Merge pull request #2 from mysteriumnetwork/header_only
Browse files Browse the repository at this point in the history
use only header
  • Loading branch information
Snawoot authored Feb 28, 2022
2 parents 1f67ac5 + fdd036a commit 10cfffe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
)

type Client interface {
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
BlockNumber(ctx context.Context) (uint64, error)
}

Expand Down Expand Up @@ -48,30 +48,30 @@ func getNumbers(ctx context.Context, left, right Client) (uint64, uint64, error)
return leftNumber, rightNumber, nil
}

func getBlocks(ctx context.Context, left, right Client, blockNumber uint64) (*types.Block, *types.Block, error) {
func getBlocks(ctx context.Context, left, right Client, blockNumber uint64) (*types.Header, *types.Header, error) {
var (
wg sync.WaitGroup
leftBlock, rightBlock *types.Block
leftBlock, rightBlock *types.Header
leftErr, rightErr error
)
bigBlockNumber := big.NewInt(int64(blockNumber))

wg.Add(2)
go func() {
defer wg.Done()
leftBlock, leftErr = left.BlockByNumber(ctx, bigBlockNumber)
leftBlock, leftErr = left.HeaderByNumber(ctx, bigBlockNumber)
}()
go func() {
defer wg.Done()
rightBlock, rightErr = right.BlockByNumber(ctx, bigBlockNumber)
rightBlock, rightErr = right.HeaderByNumber(ctx, bigBlockNumber)
}()
wg.Wait()

if leftErr != nil {
return nil, nil, fmt.Errorf("left.BlockByNumber: error: %w", leftErr)
return nil, nil, fmt.Errorf("left.HeaderByNumber: error: %w", leftErr)
}
if rightErr != nil {
return nil, nil, fmt.Errorf("right.BlockByNumber: error: %w", rightErr)
return nil, nil, fmt.Errorf("right.HeaderByNumber: error: %w", rightErr)
}

return leftBlock, rightBlock, nil
Expand Down
4 changes: 2 additions & 2 deletions diff/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func NewRetryingClient(client Client, retries uint) *RetryingClient {
}
}

func (c *RetryingClient) BlockByNumber(ctx context.Context, number *big.Int) (block *types.Block, err error) {
func (c *RetryingClient) HeaderByNumber(ctx context.Context, number *big.Int) (block *types.Header, err error) {
for i := uint(0); i < c.retries; i++ {
block, err = c.client.BlockByNumber(ctx, number)
block, err = c.client.HeaderByNumber(ctx, number)
if err == nil {
return
}
Expand Down

0 comments on commit 10cfffe

Please sign in to comment.