Skip to content

Commit

Permalink
internal/era: fix rlp decode of header and correctly read total diffi…
Browse files Browse the repository at this point in the history
…culty
  • Loading branch information
lightclient committed Jun 8, 2023
1 parent 2652d1c commit f2c9253
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions internal/era/era.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (e *Era) InitialTD() (*big.Int, error) {
if r, n, err = newSnappyReader(e.s, TypeCompressedHeader, off); err != nil {
return nil, err
}
if err := rlp.Decode(r, header); err != nil {
if err := rlp.Decode(r, &header); err != nil {
return nil, err
}
off += n
Expand All @@ -199,7 +199,8 @@ func (e *Era) InitialTD() (*big.Int, error) {
if r, _, err = e.s.ReaderAt(TypeTotalDifficulty, off); err != nil {
return nil, err
}
if err := rlp.Decode(r, rawTd); err != nil {
rawTd, err = io.ReadAll(r)
if err != nil {
return nil, err
}
td := new(big.Int).SetBytes(reverseOrder(rawTd))
Expand Down
4 changes: 2 additions & 2 deletions internal/era/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (it *Iterator) BlockAndReceipts() (*types.Block, types.Receipts, error) {
// TotalDifficulty returns the total difficulty for the iterator's current
// position.
func (it *Iterator) TotalDifficulty() (*big.Int, error) {
var td []byte
if err := rlp.Decode(it.inner.TotalDifficulty, td); err != nil {
td, err := io.ReadAll(it.inner.TotalDifficulty)
if err != nil {
return nil, err
}
return new(big.Int).SetBytes(reverseOrder(td)), nil
Expand Down

0 comments on commit f2c9253

Please sign in to comment.