e3: unionKV limit (#7157)

This commit is contained in:
Alex Sharov 2023-03-22 13:58:01 +07:00 committed by GitHub
parent 753a680cbd
commit 0ffaca865e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 8 deletions

View File

@ -154,7 +154,7 @@ func (tx *Tx) DomainRange(name kv.Domain, k1, k2 []byte, asOfTs uint64, asc orde
} }
switch name { switch name {
case AccountsDomain: case AccountsDomain:
histStateIt := tx.agg.AccountHistoricalStateRange(asOfTs, k1, nil, -1, tx) histStateIt := tx.agg.AccountHistoricalStateRange(asOfTs, k1, nil, limit, tx)
// TODO: somehow avoid common.Copy(k) - WalkAsOfIter is not zero-copy // TODO: somehow avoid common.Copy(k) - WalkAsOfIter is not zero-copy
// Is histStateIt possible to increase keys lifetime to: 2 .Next() calls?? // Is histStateIt possible to increase keys lifetime to: 2 .Next() calls??
histStateIt2 := iter.TransformKV(histStateIt, func(k, v []byte) ([]byte, []byte, error) { histStateIt2 := iter.TransformKV(histStateIt, func(k, v []byte) ([]byte, []byte, error) {
@ -181,7 +181,7 @@ func (tx *Tx) DomainRange(name kv.Domain, k1, k2 []byte, asOfTs uint64, asc orde
} }
return k[:20], v, nil return k[:20], v, nil
}) })
lastestStateIt, err := tx.RangeAscend(kv.PlainState, k1, nil, -1) lastestStateIt, err := tx.RangeAscend(kv.PlainState, k1, nil, -1) // don't apply limit, because need filter
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -190,7 +190,7 @@ func (tx *Tx) DomainRange(name kv.Domain, k1, k2 []byte, asOfTs uint64, asc orde
return len(k) == 20 return len(k) == 20
}) })
//TODO: seems UnionKV can't handle "amount" request //TODO: seems UnionKV can't handle "amount" request
return iter.UnionKV(histStateIt2, latestStateIt2), nil return iter.UnionKV(histStateIt2, latestStateIt2, limit), nil
case StorageDomain: case StorageDomain:
toKey, _ := kv.NextSubtree(k1) toKey, _ := kv.NextSubtree(k1)
fromKey2 := append(common.Copy(k1), k2...) fromKey2 := append(common.Copy(k1), k2...)
@ -223,8 +223,7 @@ func (tx *Tx) DomainRange(name kv.Domain, k1, k2 []byte, asOfTs uint64, asc orde
it3 := iter.TransformKV(it2, func(k, v []byte) ([]byte, []byte, error) { it3 := iter.TransformKV(it2, func(k, v []byte) ([]byte, []byte, error) {
return append(append([]byte{}, k[:20]...), k[28:]...), v, nil return append(append([]byte{}, k[:20]...), k[28:]...), v, nil
}) })
//TODO: seems MergePairs can't handle "amount" request return iter.UnionKV(it11, it3, limit), nil
return iter.UnionKV(it11, it3), nil
case CodeDomain: case CodeDomain:
panic("not implemented yet") panic("not implemented yet")
default: default:

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.18 go 1.18
require ( require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230322063357-c394d9bb48a7 github.com/ledgerwatch/erigon-lib v0.0.0-20230322064408-18d6be44a77f
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3
github.com/ledgerwatch/log/v3 v3.7.0 github.com/ledgerwatch/log/v3 v3.7.0
github.com/ledgerwatch/secp256k1 v1.0.0 github.com/ledgerwatch/secp256k1 v1.0.0

4
go.sum
View File

@ -519,8 +519,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0= github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230322063357-c394d9bb48a7 h1:Sj0xGrrw9uNPjkdbBMYR2tc9hBBsjtnzmGWv9AadNAc= github.com/ledgerwatch/erigon-lib v0.0.0-20230322064408-18d6be44a77f h1:FgNuXyDyXDNitxI3KdqQSRw8D5dk9IKEJWuw1m2MK6M=
github.com/ledgerwatch/erigon-lib v0.0.0-20230322063357-c394d9bb48a7/go.mod h1:I+1Oys00tH9C8Ow1u5atjh3XasMPE4VoAG5lq8Bi1Zs= github.com/ledgerwatch/erigon-lib v0.0.0-20230322064408-18d6be44a77f/go.mod h1:I+1Oys00tH9C8Ow1u5atjh3XasMPE4VoAG5lq8Bi1Zs=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 h1:tfzawK1gIIgRjVZeANXOr0Ziu+kqCIBuKMe0TXfl5Aw= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 h1:tfzawK1gIIgRjVZeANXOr0Ziu+kqCIBuKMe0TXfl5Aw=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og= github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=