GetAccountRange response limit and size checks

This commit is contained in:
David Theodore 2024-09-25 09:51:59 -05:00
parent 80b529ea71
commit 3d10a99e7f

View file

@ -294,22 +294,25 @@ func ServiceGetAccountRangeQuery(chain *core.BlockChain, req *GetAccountRangePac
for it.Next() {
hash, account := it.Hash(), common.CopyBytes(it.Account())
// Verify response size does not exceed the requested limit
size += uint64(common.HashLength + len(account))
if size > req.Bytes {
break
}
// If we've exceeded the request threshold, abort
if bytes.Compare(hash[:], req.Limit[:]) > 0 {
break
}
// Track the returned interval for the Merkle proofs
last = hash
// Assemble the reply item
size += uint64(common.HashLength + len(account))
accounts = append(accounts, &AccountData{
Hash: hash,
Body: account,
})
// If we've exceeded the request threshold, abort
if bytes.Compare(hash[:], req.Limit[:]) >= 0 {
break
}
if size > req.Bytes {
break
}
}
it.Release()