From 0ffaca865e99e19e8154b0674edf6059e807480c Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Wed, 22 Mar 2023 13:58:01 +0700 Subject: [PATCH] e3: unionKV limit (#7157) --- core/state/temporal/kv_temporal.go | 9 ++++----- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/state/temporal/kv_temporal.go b/core/state/temporal/kv_temporal.go index fc86d1253..9c5bc38f2 100644 --- a/core/state/temporal/kv_temporal.go +++ b/core/state/temporal/kv_temporal.go @@ -154,7 +154,7 @@ func (tx *Tx) DomainRange(name kv.Domain, k1, k2 []byte, asOfTs uint64, asc orde } switch name { 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 // Is histStateIt possible to increase keys lifetime to: 2 .Next() calls?? 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 }) - 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 { 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 }) //TODO: seems UnionKV can't handle "amount" request - return iter.UnionKV(histStateIt2, latestStateIt2), nil + return iter.UnionKV(histStateIt2, latestStateIt2, limit), nil case StorageDomain: toKey, _ := kv.NextSubtree(k1) 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) { return append(append([]byte{}, k[:20]...), k[28:]...), v, nil }) - //TODO: seems MergePairs can't handle "amount" request - return iter.UnionKV(it11, it3), nil + return iter.UnionKV(it11, it3, limit), nil case CodeDomain: panic("not implemented yet") default: diff --git a/go.mod b/go.mod index 50b540316..8eec8ec1c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon go 1.18 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/log/v3 v3.7.0 github.com/ledgerwatch/secp256k1 v1.0.0 diff --git a/go.sum b/go.sum index f93c8a872..e8e6a7d6f 100644 --- a/go.sum +++ b/go.sum @@ -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/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/ledgerwatch/erigon-lib v0.0.0-20230322063357-c394d9bb48a7 h1:Sj0xGrrw9uNPjkdbBMYR2tc9hBBsjtnzmGWv9AadNAc= -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 h1:FgNuXyDyXDNitxI3KdqQSRw8D5dk9IKEJWuw1m2MK6M= +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/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=