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

Upstream sync - v2.46.0 #17

Merged
merged 14 commits into from
Jul 20, 2023
Merged
9 changes: 5 additions & 4 deletions commitment/bin_patricia_hashed.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Erigon contributors
Copyright 2022 The Erigon contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ledgerwatch/log/v3"
"golang.org/x/crypto/sha3"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/rlp"
)
Expand All @@ -53,7 +54,7 @@ func hexToBin(hex []byte) bitstring {

// encodes bitstring to its compact representation
func binToCompact(bin []byte) []byte {
compact := make([]byte, 2+(len(bin)+7)/8)
compact := make([]byte, 2+common.BitLenToByteLen(len(bin)))
binary.BigEndian.PutUint16(compact, uint16(len(bin)))
for i := 0; i < len(bin); i++ {
if bin[i] != 0 {
Expand Down Expand Up @@ -432,7 +433,7 @@ func (cell *BinaryCell) accountForHashing(buffer []byte, storageRootHash [length
if cell.Nonce < 128 && cell.Nonce != 0 {
nonceBytes = 0
} else {
nonceBytes = (bits.Len64(cell.Nonce) + 7) / 8
nonceBytes = common.BitLenToByteLen(bits.Len64(cell.Nonce))
}

var structLength = uint(balanceBytes + nonceBytes + 2)
Expand All @@ -443,7 +444,7 @@ func (cell *BinaryCell) accountForHashing(buffer []byte, storageRootHash [length
buffer[0] = byte(192 + structLength)
pos = 1
} else {
lengthBytes := (bits.Len(structLength) + 7) / 8
lengthBytes := common.BitLenToByteLen(bits.Len(structLength))
buffer[0] = byte(247 + lengthBytes)

for i := lengthBytes; i > 0; i-- {
Expand Down
10 changes: 5 additions & 5 deletions commitment/hex_patricia_hashed.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Erigon contributors
Copyright 2022 The Erigon contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,10 +27,10 @@ import (
"strings"

"github.com/holiman/uint256"
"golang.org/x/crypto/sha3"

"github.com/ledgerwatch/log/v3"
"golang.org/x/crypto/sha3"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/rlp"
)
Expand Down Expand Up @@ -409,7 +409,7 @@ func (cell *Cell) accountForHashing(buffer []byte, storageRootHash [length.Hash]
if cell.Nonce < 128 && cell.Nonce != 0 {
nonceBytes = 0
} else {
nonceBytes = (bits.Len64(cell.Nonce) + 7) / 8
nonceBytes = common.BitLenToByteLen(bits.Len64(cell.Nonce))
}

var structLength = uint(balanceBytes + nonceBytes + 2)
Expand All @@ -420,7 +420,7 @@ func (cell *Cell) accountForHashing(buffer []byte, storageRootHash [length.Hash]
buffer[0] = byte(192 + structLength)
pos = 1
} else {
lengthBytes := (bits.Len(structLength) + 7) / 8
lengthBytes := common.BitLenToByteLen(bits.Len(structLength))
buffer[0] = byte(247 + lengthBytes)

for i := lengthBytes; i > 0; i-- {
Expand Down
6 changes: 5 additions & 1 deletion common/bytes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Erigon contributors
Copyright 2021 The Erigon contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,3 +61,7 @@ func EnsureEnoughSize(in []byte, size int) []byte {
}
return in[:size] // Reuse the space if it has enough capacity
}

func BitLenToByteLen(bitLen int) (byteLen int) {
return (bitLen + 7) / 8
}
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ require (
github.com/go-stack/stack v1.8.1
github.com/google/btree v1.1.2
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/hashicorp/golang-lru/v2 v2.0.2
github.com/hashicorp/golang-lru/v2 v2.0.3
github.com/holiman/uint256 v1.2.2
github.com/matryer/moq v0.3.1
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/quasilyte/go-ruleguard/dsl v0.3.22
github.com/spaolacci/murmur3 v1.1.0
github.com/stretchr/testify v1.8.4
github.com/tidwall/btree v1.6.0
golang.org/x/crypto v0.9.0
golang.org/x/crypto v0.10.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/sync v0.2.0
golang.org/x/sys v0.8.0
golang.org/x/sync v0.3.0
golang.org/x/sys v0.9.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.55.0
google.golang.org/grpc v1.56.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.30.0
)
Expand Down Expand Up @@ -109,10 +109,10 @@ require (
go.opentelemetry.io/otel v1.8.0 // indirect
go.opentelemetry.io/otel/trace v1.8.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU=
github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/golang-lru/v2 v2.0.3 h1:kmRrRLlInXvng0SmLxmQpQkpbYAvcXm7NPDrgxJa9mE=
github.com/hashicorp/golang-lru/v2 v2.0.3/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/holiman/uint256 v1.2.2 h1:TXKcSGc2WaxPD2+bmzAsVthL4+pEN0YwXcL5qED83vk=
github.com/holiman/uint256 v1.2.2/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
Expand Down Expand Up @@ -419,8 +419,8 @@ golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220516162934-403b01795ae8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
Expand Down Expand Up @@ -462,8 +462,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -474,8 +474,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -509,8 +509,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -524,8 +524,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down Expand Up @@ -555,17 +555,17 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRn
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA=
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
google.golang.org/grpc v1.56.0 h1:+y7Bs8rtMd07LeXmL3NxcTLn7mUkbKZqEpPhMNkwJEE=
google.golang.org/grpc v1.56.0/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand Down
11 changes: 6 additions & 5 deletions kv/bitmapdb/bitmapdb.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Erigon contributors
Copyright 2022 The Erigon contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,8 @@ import (
"github.com/RoaringBitmap/roaring"
"github.com/RoaringBitmap/roaring/roaring64"
"github.com/c2h5oh/datasize"
libcommon "github.com/ledgerwatch/erigon-lib/common"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
)

Expand Down Expand Up @@ -171,7 +172,7 @@ func TruncateRange(db kv.RwTx, bucket string, key []byte, to uint32) error {
if _, err := chunk.WriteTo(buf); err != nil {
return err
}
return db.Put(bucket, chunkKey, libcommon.Copy(buf.Bytes()))
return db.Put(bucket, chunkKey, common.Copy(buf.Bytes()))
})
}

Expand Down Expand Up @@ -326,7 +327,7 @@ func TruncateRange64(db kv.RwTx, bucket string, key []byte, to uint64) error {
if _, err := chunk.WriteTo(buf); err != nil {
return err
}
return db.Put(bucket, chunkKey, libcommon.Copy(buf.Bytes()))
return db.Put(bucket, chunkKey, common.Copy(buf.Bytes()))
})
}

Expand Down Expand Up @@ -408,7 +409,7 @@ func Walk(c kv.Cursor, startkey []byte, fixedbits int, walker func(k, v []byte)
}

func Bytesmask(fixedbits int) (fixedbytes int, mask byte) {
fixedbytes = (fixedbits + 7) / 8
fixedbytes = common.BitLenToByteLen(fixedbits)
shiftbits := fixedbits & 7
mask = byte(0xff)
if shiftbits != 0 {
Expand Down
20 changes: 10 additions & 10 deletions kv/iter/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func TestUnionPairs(t *testing.T) {
require := require.New(t)
tx, _ := db.BeginRw(ctx)
defer tx.Rollback()
_ = tx.Put(kv.AccountsHistory, []byte{1}, []byte{1})
_ = tx.Put(kv.AccountsHistory, []byte{3}, []byte{1})
_ = tx.Put(kv.AccountsHistory, []byte{4}, []byte{1})
_ = tx.Put(kv.E2AccountsHistory, []byte{1}, []byte{1})
_ = tx.Put(kv.E2AccountsHistory, []byte{3}, []byte{1})
_ = tx.Put(kv.E2AccountsHistory, []byte{4}, []byte{1})
_ = tx.Put(kv.PlainState, []byte{2}, []byte{9})
_ = tx.Put(kv.PlainState, []byte{3}, []byte{9})
it, _ := tx.Range(kv.AccountsHistory, nil, nil)
it, _ := tx.Range(kv.E2AccountsHistory, nil, nil)
it2, _ := tx.Range(kv.PlainState, nil, nil)
keys, values, err := iter.ToKVArray(iter.UnionKV(it, it2, -1))
require.NoError(err)
Expand All @@ -103,7 +103,7 @@ func TestUnionPairs(t *testing.T) {
defer tx.Rollback()
_ = tx.Put(kv.PlainState, []byte{2}, []byte{9})
_ = tx.Put(kv.PlainState, []byte{3}, []byte{9})
it, _ := tx.Range(kv.AccountsHistory, nil, nil)
it, _ := tx.Range(kv.E2AccountsHistory, nil, nil)
it2, _ := tx.Range(kv.PlainState, nil, nil)
keys, _, err := iter.ToKVArray(iter.UnionKV(it, it2, -1))
require.NoError(err)
Expand All @@ -113,10 +113,10 @@ func TestUnionPairs(t *testing.T) {
require := require.New(t)
tx, _ := db.BeginRw(ctx)
defer tx.Rollback()
_ = tx.Put(kv.AccountsHistory, []byte{1}, []byte{1})
_ = tx.Put(kv.AccountsHistory, []byte{3}, []byte{1})
_ = tx.Put(kv.AccountsHistory, []byte{4}, []byte{1})
it, _ := tx.Range(kv.AccountsHistory, nil, nil)
_ = tx.Put(kv.E2AccountsHistory, []byte{1}, []byte{1})
_ = tx.Put(kv.E2AccountsHistory, []byte{3}, []byte{1})
_ = tx.Put(kv.E2AccountsHistory, []byte{4}, []byte{1})
it, _ := tx.Range(kv.E2AccountsHistory, nil, nil)
it2, _ := tx.Range(kv.PlainState, nil, nil)
keys, _, err := iter.ToKVArray(iter.UnionKV(it, it2, -1))
require.NoError(err)
Expand All @@ -126,7 +126,7 @@ func TestUnionPairs(t *testing.T) {
require := require.New(t)
tx, _ := db.BeginRw(ctx)
defer tx.Rollback()
it, _ := tx.Range(kv.AccountsHistory, nil, nil)
it, _ := tx.Range(kv.E2AccountsHistory, nil, nil)
it2, _ := tx.Range(kv.PlainState, nil, nil)
m := iter.UnionKV(it, it2, -1)
require.False(m.HasNext())
Expand Down
15 changes: 15 additions & 0 deletions kv/kv_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,21 @@ type RwCursor interface {
DeleteCurrent() error
}

// CursorDupSort
//
// Example:
//
// for k, v, err = cursor.First(); k != nil; k, v, err = cursor.NextNoDup() {
// if err != nil {
// return err
// }
// for ; v != nil; _, v, err = cursor.NextDup() {
// if err != nil {
// return err
// }
//
// }
// }
type CursorDupSort interface {
Cursor

Expand Down
Loading
Loading