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

chore(storage): cleanup NotFound errors #2065

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a19b0d1
cleanup block.ErrSlotNotFound
abi87 Oct 11, 2024
06aee0d
some more errors cleanup
abi87 Oct 11, 2024
7bfea6b
wip: fixing err not found in beacondb package
abi87 Oct 11, 2024
bba5071
wip: more fixing err not found in beacondb package
abi87 Oct 11, 2024
3afed77
wip: some more fixing err not found in beacondb package
abi87 Oct 11, 2024
3917a9a
wip: yet some more fixing err not found in beacondb package
abi87 Oct 11, 2024
64d2f3e
reverted
abi87 Oct 11, 2024
dc50cc1
reducing code duplication
abi87 Oct 13, 2024
034f7d1
nit
abi87 Oct 13, 2024
b0f9050
nit
abi87 Oct 13, 2024
55ce71e
reverted faulty changes to slashings
abi87 Oct 13, 2024
b32f9d8
nit
abi87 Oct 13, 2024
86da4a8
Merge branch 'main' into storage-cleanup-err-not-found
nidhi-singh02 Oct 14, 2024
c9b579a
updated mockery to v 2.46.3
abi87 Oct 14, 2024
b998227
chores(engine-primitives): nit (#2068)
abi87 Oct 15, 2024
ec89f97
consolidated ErrNotFound
abi87 Oct 15, 2024
7c5e4ad
Merge branch 'update-mockery-v2-46-3' into storage-cleanup-err-not-found
abi87 Oct 15, 2024
23e5a13
nit
abi87 Oct 15, 2024
35e893c
Merge branch 'main' into storage-cleanup-err-not-found
abi87 Oct 15, 2024
30b680f
nits
abi87 Oct 15, 2024
fbd9772
repackaged storage errors
abi87 Oct 15, 2024
4acb893
Merge branch 'main' into storage-cleanup-err-not-found
abi87 Oct 15, 2024
3e88d11
chore(storage): No errors silencing (#2076)
abi87 Oct 15, 2024
db3bee6
Merge branch 'main' into storage-cleanup-err-not-found
abi87 Oct 17, 2024
c2d9108
Merge branch 'main' into storage-cleanup-err-not-found
abi87 Oct 19, 2024
c1a1986
Merge branch 'main' into storage-cleanup-err-not-found
abi87 Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions mod/state-transition/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ module github.com/berachain/beacon-kit/mod/state-transition

go 1.23.0

replace (
cosmossdk.io/core => cosmossdk.io/core v0.0.0-20240806152830-8fb47b368cd4
github.com/berachain/beacon-kit/mod/storage => ../storage
)
abi87 marked this conversation as resolved.
Show resolved Hide resolved

require (
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240618214413-d5ec0e66b3dd
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570
github.com/berachain/beacon-kit/mod/storage v0.0.0-00010101000000-000000000000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update the placeholder version for the storage module.

The github.com/berachain/beacon-kit/mod/storage module is added with a placeholder version (v0.0.0-00010101000000-000000000000). This is likely due to the local replacement directive. Before merging, ensure that this is replaced with a proper version or commit hash to maintain reproducible builds.

github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/go-faster/xor v1.0.0
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8
golang.org/x/sync v0.8.0
)

require (
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v1.0.0 // indirect
github.com/DataDog/zstd v1.5.6 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db // indirect
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df // indirect
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
Expand All @@ -30,6 +38,7 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.13.0 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
Expand All @@ -44,6 +53,7 @@ require (
github.com/gofrs/flock v0.12.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
Expand Down Expand Up @@ -80,6 +90,8 @@ require (
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
30 changes: 26 additions & 4 deletions mod/state-transition/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
cosmossdk.io/core v0.0.0-20240806152830-8fb47b368cd4 h1:dDdZ0xneWTA63vu1OOc1fEpqYQNangvSsxrdPWymlQ8=
cosmossdk.io/core v0.0.0-20240806152830-8fb47b368cd4/go.mod h1:sLzMwAW9HW+Nm3GltUVHDRSRZbcXLy9+2AYgi2bwt/s=
github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY=
github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
Expand All @@ -8,12 +12,12 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db h1:vGczI1vJ6s86tSDS4tsllzlWZUVZ42xZ710GoHMd4to=
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db/go.mod h1:rbvfJqTKUIckels2AlWy+XuG+UGnegoFQuHC+TUg+zA=
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df h1:mnD1LKqDQ0n+OFdDqOuvKaEiUKRJzsO4V0wyyn/gJYg=
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df/go.mod h1:bTFB4Rdvm7D/WdwPYkqQ+8T0XOMBv0pzXfp1E46BFX8=
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197 h1:wVWkiiERY/7kaXvE/VNPPUtYp/l8ky6QSuKM3ThVMXU=
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197/go.mod h1:LiOiqrJhhLH/GPo0XE5fel3EYyi7X6dwBOyTqZakTeQ=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240618214413-d5ec0e66b3dd h1:jD/ggR959ZX+lqxsMzoRJzrGvFK7PI6UmgnRwOTh4S4=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240618214413-d5ec0e66b3dd/go.mod h1:iXa+Q+i0q+GCpLzkusulO57K5vlkDgM77jtfMr3QdFA=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0 h1:kCSrkb/uVXfMKJPKjf0c7nlJkwn5cNwMxtzRW4zNq2A=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0/go.mod h1:og0jtHZosPDTyhge9tMBlRItoZ4Iv3aZFM9n4QDpcdo=
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e h1:0/FDBXtagMkpta/f4J2uAah2NM1G+0dqxngzMzrmbw4=
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e/go.mod h1:7/SXz8S5VpFl2thcKuBdu1OId+SgI1o4N+S1FB92Zw8=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570 h1:w0Gkg31VQRFDv0EJjYgVtlpza7kSaJq7U28zxZjfZeE=
Expand Down Expand Up @@ -48,6 +52,10 @@ github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/Yj
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.13.0 h1:VPULb/v6bbYELAPTDFINEVaMTTybV5GLxDdcjnS+4oc=
github.com/consensys/gnark-crypto v0.13.0/go.mod h1:wKqwsieaKPThcFkHe0d0zMsbHEUWFmZcG7KBCse210o=
github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAKs=
github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA=
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg=
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a/go.mod h1:sTwzHBvIzm2RfVCGNEBZgRyjwK40bVoun3ZnGOCafNM=
github.com/crate-crypto/go-kzg-4844 v1.1.0 h1:EN/u9k2TF6OWSHrCCDBBU6GLNMq88OspHHlMnHfoyU4=
Expand Down Expand Up @@ -101,9 +109,13 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -138,6 +150,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
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/linxGnu/grocksdb v1.9.2 h1:O3mzvO0wuzQ9mtlHbDrShixyVjVbmuqTjFrzlf43wZ8=
github.com/linxGnu/grocksdb v1.9.2/go.mod h1:QYiYypR2d4v63Wj1adOOfzglnoII0gLj3PNh4fZkcFA=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand Down Expand Up @@ -198,6 +212,8 @@ github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKl
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
Expand Down Expand Up @@ -286,6 +302,10 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand All @@ -309,5 +329,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=
9 changes: 7 additions & 2 deletions mod/state-transition/pkg/core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/berachain/beacon-kit/mod/errors"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
storageerrors "github.com/berachain/beacon-kit/mod/storage/pkg/errors"
)

// StateDB is the underlying struct behind the BeaconState interface.
Expand Down Expand Up @@ -162,12 +163,16 @@ func (s *StateDB[
) error {
// Update the total slashing amount before overwriting the old amount.
total, err := s.GetTotalSlashing()
if err != nil {
if errors.Is(err, storageerrors.ErrNotFound) {
total = 0
} else if err != nil {
abi87 marked this conversation as resolved.
Show resolved Hide resolved
return err
}

oldValue, err := s.GetSlashingAtIndex(index)
if err != nil {
if errors.Is(err, storageerrors.ErrNotFound) {
oldValue = 0
} else if err != nil {
return err
}

Expand Down
72 changes: 62 additions & 10 deletions mod/storage/pkg/beacondb/eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

package beacondb

import (
"fmt"

"github.com/berachain/beacon-kit/mod/storage/pkg/errors"
)

// GetLatestExecutionPayloadHeader retrieves the latest execution payload
// header from the BeaconStore.
func (kv *KVStore[
Expand All @@ -28,13 +34,40 @@ func (kv *KVStore[
]) GetLatestExecutionPayloadHeader() (
ExecutionPayloadHeaderT, error,
) {
forkVersion, err := kv.latestExecutionPayloadVersion.Get(kv.ctx)
var h ExecutionPayloadHeaderT
v, err := kv.getLatestExecutionPayloadVersion()
if err != nil {
return h, fmt.Errorf(
"failed retrieving latest execution payload header: %w",
err,
)
}

kv.latestExecutionPayloadCodec.SetActiveForkVersion(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

SetActiveForkVersion Does Not Validate Version Inputs

The SetActiveForkVersion method in mod/storage/pkg/encoding/ssz.go assigns the provided version directly without validating whether it is valid or supported. This lack of validation may lead to unexpected behavior if an invalid or unsupported version is set.

  • File: mod/storage/pkg/encoding/ssz.go
    • SetActiveForkVersion lacks error handling for invalid versions.
🔗 Analysis chain

Ensure SetActiveForkVersion handles invalid versions

When setting the active fork version with kv.latestExecutionPayloadCodec.SetActiveForkVersion(v), it's important to verify that invalid or unsupported versions are properly handled. Lack of validation may lead to unexpected behavior elsewhere in the code.

Run the following script to check the implementation of SetActiveForkVersion:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that SetActiveForkVersion handles invalid versions.

# Search for the SetActiveForkVersion method implementation and check for error handling.
rg --type go 'func\s+\([^)]+\)\s+SetActiveForkVersion\s*\(' -A 15

# Review the implementation to ensure it includes validation logic.

Length of output: 1081

h, err = kv.latestExecutionPayloadHeader.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return h, fmt.Errorf(
"failed retrieving latest execution payload header: %w",
err,
)
}
return h, nil
}

func (kv *KVStore[
BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT,
ForkT, ValidatorT, ValidatorsT,
]) getLatestExecutionPayloadVersion() (uint32, error) {
v, err := kv.latestExecutionPayloadVersion.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
var t ExecutionPayloadHeaderT
return t, err
return 0, fmt.Errorf(
"failed retrieving latest execution payload version: %w",
err,
)
}
kv.latestExecutionPayloadCodec.SetActiveForkVersion(forkVersion)
return kv.latestExecutionPayloadHeader.Get(kv.ctx)
return v, nil
}

// SetLatestExecutionPayloadHeader sets the latest execution payload header in
Expand All @@ -45,9 +78,11 @@ func (kv *KVStore[
]) SetLatestExecutionPayloadHeader(
payloadHeader ExecutionPayloadHeaderT,
) error {
if err := kv.latestExecutionPayloadVersion.Set(
kv.ctx, payloadHeader.Version(),
); err != nil {
var (
ctx = kv.ctx
version = payloadHeader.Version()
)
if err := kv.latestExecutionPayloadVersion.Set(ctx, version); err != nil {
Comment on lines +81 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify SetLatestExecutionPayloadHeader by removing unnecessary variable

The variable ctx is assigned kv.ctx but is used only once. You can simplify the code by using kv.ctx directly, eliminating the need for the extra variable.

Apply this diff to streamline the function:

 func (kv *KVStore[
     BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT,
     ForkT, ValidatorT, ValidatorsT,
 ]) SetLatestExecutionPayloadHeader(
     payloadHeader ExecutionPayloadHeaderT,
 ) error {
-    var (
-        ctx     = kv.ctx
-        version = payloadHeader.Version()
-    )
+    version := payloadHeader.Version()
-    if err := kv.latestExecutionPayloadVersion.Set(ctx, version); err != nil {
+    if err := kv.latestExecutionPayloadVersion.Set(kv.ctx, version); err != nil {
         return err
     }
     kv.latestExecutionPayloadCodec.SetActiveForkVersion(payloadHeader.Version())
     return kv.latestExecutionPayloadHeader.Set(kv.ctx, payloadHeader)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var (
ctx = kv.ctx
version = payloadHeader.Version()
)
if err := kv.latestExecutionPayloadVersion.Set(ctx, version); err != nil {
version := payloadHeader.Version()
if err := kv.latestExecutionPayloadVersion.Set(kv.ctx, version); err != nil {

return err
abi87 marked this conversation as resolved.
Show resolved Hide resolved
}
abi87 marked this conversation as resolved.
Show resolved Hide resolved
kv.latestExecutionPayloadCodec.SetActiveForkVersion(payloadHeader.Version())
Expand All @@ -59,7 +94,16 @@ func (kv *KVStore[
BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT,
ForkT, ValidatorT, ValidatorsT,
]) GetEth1DepositIndex() (uint64, error) {
return kv.eth1DepositIndex.Get(kv.ctx)
idx, err := kv.eth1DepositIndex.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return 0, fmt.Errorf(
"failed retrieving eth1 deposit index %d, %w",
idx,
err,
)
}
Comment on lines +97 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid including uninitialized variables in error messages

In the GetEth1DepositIndex method, including idx in the error message before it's successfully retrieved could be misleading, as it may contain a default value (e.g., zero). For clarity, consider modifying the error message to exclude idx.

Apply this diff to adjust the error message:

     if err != nil {
-        return 0, fmt.Errorf(
-            "failed retrieving eth1 deposit index %d, %w",
-            idx,
-            err,
-        )
+        return 0, fmt.Errorf(
+            "failed retrieving eth1 deposit index: %w",
+            err,
+        )
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
idx, err := kv.eth1DepositIndex.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return 0, fmt.Errorf(
"failed retrieving eth1 deposit index %d, %w",
idx,
err,
)
}
idx, err := kv.eth1DepositIndex.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return 0, fmt.Errorf(
"failed retrieving eth1 deposit index: %w",
err,
)
}

return idx, nil
}

// SetEth1DepositIndex sets the eth1 deposit index in the beacon state.
Expand All @@ -77,7 +121,15 @@ func (kv *KVStore[
BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT,
ForkT, ValidatorT, ValidatorsT,
]) GetEth1Data() (Eth1DataT, error) {
return kv.eth1Data.Get(kv.ctx)
d, err := kv.eth1Data.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return d, fmt.Errorf(
"failed retrieving eth1 data: %w",
err,
)
}
return d, nil
}

// SetEth1Data sets the eth1 data in the beacon state.
Expand Down
13 changes: 12 additions & 1 deletion mod/storage/pkg/beacondb/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

package beacondb

import (
"fmt"

"github.com/berachain/beacon-kit/mod/storage/pkg/errors"
)

// SetFork sets the fork version for the given epoch.
func (kv *KVStore[
BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT,
Expand All @@ -35,5 +41,10 @@ func (kv *KVStore[
BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT,
ForkT, ValidatorT, ValidatorsT,
]) GetFork() (ForkT, error) {
return kv.fork.Get(kv.ctx)
f, err := kv.fork.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return f, fmt.Errorf("failed retrieving fork: %w", err)
}
return f, nil
}
31 changes: 27 additions & 4 deletions mod/storage/pkg/beacondb/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

package beacondb

import "github.com/berachain/beacon-kit/mod/primitives/pkg/common"
import (
"fmt"

"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/storage/pkg/errors"
)

// UpdateBlockRootAtIndex sets a block root in the BeaconStore.
func (kv *KVStore[
Expand All @@ -41,8 +46,13 @@ func (kv *KVStore[
index uint64,
) (common.Root, error) {
bz, err := kv.blockRoots.Get(kv.ctx, index)
err = errors.MapError(err)
if err != nil {
return common.Root{}, err
return common.Root{}, fmt.Errorf(
"failed retrieving block root at index %d: %w",
index,
err,
)
Comment on lines +49 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

LGTM with a minor suggestion for consistency.

The error handling improvements in GetBlockRootAtIndex align well with the PR objectives. The use of errors.MapError likely handles the mapping to the new ErrNotFound type, and the error message now includes the index, providing more context.

For consistency with other error messages, consider updating the error message:

-			"failed retrieving block root at index %d: %w",
+			"failed to retrieve block root at index %d: %w",

This minor change would make the error messages more uniform across the file.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
err = errors.MapError(err)
if err != nil {
return common.Root{}, err
return common.Root{}, fmt.Errorf(
"failed retrieving block root at index %d: %w",
index,
err,
)
err = errors.MapError(err)
if err != nil {
return common.Root{}, fmt.Errorf(
"failed to retrieve block root at index %d: %w",
index,
err,
)

}
return common.Root(bz), nil
}
Expand All @@ -64,7 +74,15 @@ func (kv *KVStore[
]) GetLatestBlockHeader() (
BeaconBlockHeaderT, error,
) {
return kv.latestBlockHeader.Get(kv.ctx)
h, err := kv.latestBlockHeader.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return h, fmt.Errorf(
"failed retrieving latest block header: %w",
err,
)
}
return h, nil
Comment on lines +77 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

LGTM with a minor suggestion for consistency.

The error handling improvements in GetLatestBlockHeader are well-aligned with the PR objectives. The use of errors.MapError likely handles the mapping to the new ErrNotFound type, and the error message is now more descriptive.

For consistency with the suggested changes in other methods, consider updating the error message:

-			"failed retrieving latest block header: %w",
+			"failed to retrieve latest block header: %w",

This minor change would make the error messages more uniform across the file.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
h, err := kv.latestBlockHeader.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return h, fmt.Errorf(
"failed retrieving latest block header: %w",
err,
)
}
return h, nil
h, err := kv.latestBlockHeader.Get(kv.ctx)
err = errors.MapError(err)
if err != nil {
return h, fmt.Errorf(
"failed to retrieve latest block header: %w",
err,
)
}
return h, nil

}

// UpdateStateRootAtIndex updates the state root at the given slot.
Expand All @@ -86,8 +104,13 @@ func (kv *KVStore[
idx uint64,
) (common.Root, error) {
bz, err := kv.stateRoots.Get(kv.ctx, idx)
err = errors.MapError(err)
if err != nil {
return common.Root{}, err
return common.Root{}, fmt.Errorf(
"failed retrieving state root at index %d: %w",
idx,
err,
)
Comment on lines +107 to +113
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

LGTM with minor suggestions for consistency and clarity.

The error handling improvements in StateRootAtIndex align well with the PR objectives. The use of errors.MapError likely handles the mapping to the new ErrNotFound type, and the error message now includes the index, providing more context.

For consistency with other error messages and to improve clarity, consider the following changes:

  1. Use "failed to retrieve" instead of "failed retrieving" for consistency.
  2. Use "index" instead of "idx" in the error message for clarity.

Apply this diff to implement these changes:

-			"failed retrieving state root at index %d: %w",
-			idx,
+			"failed to retrieve state root at index %d: %w",
+			index,

These changes will make the error messages more uniform and clear across the file.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
err = errors.MapError(err)
if err != nil {
return common.Root{}, err
return common.Root{}, fmt.Errorf(
"failed retrieving state root at index %d: %w",
idx,
err,
)
err = errors.MapError(err)
if err != nil {
return common.Root{}, fmt.Errorf(
"failed to retrieve state root at index %d: %w",
index,
err,
)

}
return common.Root(bz), nil
}
14 changes: 12 additions & 2 deletions mod/storage/pkg/beacondb/randao.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

package beacondb

import "github.com/berachain/beacon-kit/mod/primitives/pkg/common"
import (
"fmt"

"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/storage/pkg/errors"
)

// UpdateRandaoMixAtIndex sets the current RANDAO mix in the store.
func (kv *KVStore[
Expand All @@ -41,8 +46,13 @@ func (kv *KVStore[
index uint64,
) (common.Bytes32, error) {
bz, err := kv.randaoMix.Get(kv.ctx, index)
err = errors.MapError(err)
if err != nil {
return common.Bytes32{}, err
return common.Bytes32{}, fmt.Errorf(
"failed retrieving randao mix at index %d: %w",
index,
err,
)
Comment on lines +49 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Improved error handling, but consider explicit ErrNotFound check

The changes improve error handling by using errors.MapError and providing a formatted error message. This aligns with the PR objectives to enhance error reporting.

However, to fully meet the PR objectives, consider explicitly checking for collections.ErrNotFound and returning beacondb.ErrNotFound. This would ensure that collections.ErrNotFound is never returned to clients, as specified in the PR summary.

Here's a suggested implementation:

bz, err := kv.randaoMix.Get(kv.ctx, index)
if errors.Is(err, collections.ErrNotFound) {
    return common.Bytes32{}, fmt.Errorf(
        "failed retrieving randao mix at index %d: %w",
        index,
        beacondb.ErrNotFound,
    )
} else if err != nil {
    return common.Bytes32{}, fmt.Errorf(
        "failed retrieving randao mix at index %d: %w",
        index,
        err,
    )
}
return common.Bytes32(bz), nil

This change would make the use of beacondb.ErrNotFound explicit and ensure that collections.ErrNotFound is never returned to clients.

}
return common.Bytes32(bz), nil
}
Loading
Loading