Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/protocols/snap: adapt to uint256 API changes #22851

Merged
merged 3 commits into from
May 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions eth/protocols/snap/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ func newHashRange(start common.Hash, num uint64) *hashRange {
step256.SetFromBig(step)

return &hashRange{
current: uint256.NewInt().SetBytes32(start[:]),
current: new(uint256.Int).SetBytes32(start[:]),
step: step256,
}
}

// Next pushes the hash range to the next interval.
func (r *hashRange) Next() bool {
next := new(uint256.Int)
if overflow := next.AddOverflow(r.current, r.step); overflow {
next, overflow := next.AddOverflow(r.current, r.step)
if overflow {
return false
}
r.current = next
Expand All @@ -66,15 +67,16 @@ func (r *hashRange) Start() common.Hash {
func (r *hashRange) End() common.Hash {
// If the end overflows (non divisible range), return a shorter interval
next := new(uint256.Int)
if overflow := next.AddOverflow(r.current, r.step); overflow {
next, overflow := next.AddOverflow(r.current, r.step)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could combine them into

next, overflow := new(uint256.Int).AddOverflow(r.current, r.step)

and drop next := new(uint256.Int)

if overflow {
return common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
}
return new(uint256.Int).Sub(next, uint256.NewInt().SetOne()).Bytes32()
return new(uint256.Int).Sub(next, new(uint256.Int).SetOne()).Bytes32()
fjl marked this conversation as resolved.
Show resolved Hide resolved
}

// incHash returns the next hash, in lexicographical order (a.k.a plus one)
func incHash(h common.Hash) common.Hash {
a := uint256.NewInt().SetBytes32(h[:])
a.Add(a, uint256.NewInt().SetOne())
a := new(uint256.Int).SetBytes32(h[:])
a.Add(a, new(uint256.Int).SetOne())
fjl marked this conversation as resolved.
Show resolved Hide resolved
return common.Hash(a.Bytes32())
}