Unverified Commit e536bb52 authored by Felix Lange's avatar Felix Lange Committed by GitHub

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

parent c0e201b6
...@@ -42,15 +42,15 @@ func newHashRange(start common.Hash, num uint64) *hashRange { ...@@ -42,15 +42,15 @@ func newHashRange(start common.Hash, num uint64) *hashRange {
step256.SetFromBig(step) step256.SetFromBig(step)
return &hashRange{ return &hashRange{
current: uint256.NewInt().SetBytes32(start[:]), current: new(uint256.Int).SetBytes32(start[:]),
step: step256, step: step256,
} }
} }
// Next pushes the hash range to the next interval. // Next pushes the hash range to the next interval.
func (r *hashRange) Next() bool { func (r *hashRange) Next() bool {
next := new(uint256.Int) next, overflow := new(uint256.Int).AddOverflow(r.current, r.step)
if overflow := next.AddOverflow(r.current, r.step); overflow { if overflow {
return false return false
} }
r.current = next r.current = next
...@@ -65,16 +65,17 @@ func (r *hashRange) Start() common.Hash { ...@@ -65,16 +65,17 @@ func (r *hashRange) Start() common.Hash {
// End returns the last hash in the current interval. // End returns the last hash in the current interval.
func (r *hashRange) End() common.Hash { func (r *hashRange) End() common.Hash {
// If the end overflows (non divisible range), return a shorter interval // If the end overflows (non divisible range), return a shorter interval
next := new(uint256.Int) next, overflow := new(uint256.Int).AddOverflow(r.current, r.step)
if overflow := next.AddOverflow(r.current, r.step); overflow { if overflow {
return common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") return common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
} }
return new(uint256.Int).Sub(next, uint256.NewInt().SetOne()).Bytes32() return next.SubUint64(next, 1).Bytes32()
} }
// incHash returns the next hash, in lexicographical order (a.k.a plus one) // incHash returns the next hash, in lexicographical order (a.k.a plus one)
func incHash(h common.Hash) common.Hash { func incHash(h common.Hash) common.Hash {
a := uint256.NewInt().SetBytes32(h[:]) var a uint256.Int
a.Add(a, uint256.NewInt().SetOne()) a.SetBytes32(h[:])
a.AddUint64(&a, 1)
return common.Hash(a.Bytes32()) return common.Hash(a.Bytes32())
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment