Skip to content

Commit 615feb1

Browse files
committed
GET
1 parent f7912e7 commit 615feb1

File tree

16 files changed

+211
-47
lines changed

16 files changed

+211
-47
lines changed

beacon-chain/cache/depositcache/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"//beacon-chain/cache:go_default_library",
1717
"//config/fieldparams:go_default_library",
1818
"//config/params:go_default_library",
19+
"//consensus-types:go_default_library",
1920
"//container/trie:go_default_library",
2021
"//crypto/hash:go_default_library",
2122
"//encoding/bytesutil:go_default_library",

beacon-chain/cache/depositcache/deposits_cache.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache"
1919
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
2020
"github.com/prysmaticlabs/prysm/v5/config/params"
21+
consensus_types "github.com/prysmaticlabs/prysm/v5/consensus-types"
2122
"github.com/prysmaticlabs/prysm/v5/container/trie"
2223
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
2324
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
@@ -312,6 +313,10 @@ func (dc *DepositCache) PruneProofs(ctx context.Context, untilDepositIndex int64
312313
return nil
313314
}
314315

316+
func (dc *DepositCache) Snapshot() (*ethpb.DepositSnapshot, error) {
317+
return nil, consensus_types.ErrUnsupportedField
318+
}
319+
315320
// Deposits returns the cached internal deposit tree.
316321
func (fd *FinalizedDeposits) Deposits() cache.MerkleTree {
317322
if fd.deposits != nil {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@prysm//tools/go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
testonly = true,
6+
srcs = ["mock.go"],
7+
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/cache/depositcache/testing",
8+
visibility = ["//visibility:public"],
9+
deps = [
10+
"//beacon-chain/cache:go_default_library",
11+
"//proto/prysm/v1alpha1:go_default_library",
12+
],
13+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package testing
2+
3+
import (
4+
"context"
5+
"math/big"
6+
7+
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache"
8+
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
9+
)
10+
11+
type MockDepositFetcher struct {
12+
Snap *ethpb.DepositSnapshot
13+
}
14+
15+
func (MockDepositFetcher) AllDeposits(_ context.Context, _ *big.Int) []*ethpb.Deposit {
16+
panic("implement me")
17+
}
18+
19+
func (MockDepositFetcher) AllDepositContainers(_ context.Context) []*ethpb.DepositContainer {
20+
panic("implement me")
21+
}
22+
23+
func (MockDepositFetcher) DepositByPubkey(_ context.Context, _ []byte) (*ethpb.Deposit, *big.Int) {
24+
panic("implement me")
25+
}
26+
27+
func (MockDepositFetcher) DepositsNumberAndRootAtHeight(_ context.Context, _ *big.Int) (uint64, [32]byte) {
28+
panic("implement me")
29+
}
30+
31+
func (MockDepositFetcher) InsertPendingDeposit(_ context.Context, _ *ethpb.Deposit, _ uint64, _ int64, _ [32]byte) {
32+
panic("implement me")
33+
}
34+
35+
func (MockDepositFetcher) PendingDeposits(_ context.Context, _ *big.Int) []*ethpb.Deposit {
36+
panic("implement me")
37+
}
38+
39+
func (MockDepositFetcher) PendingContainers(_ context.Context, _ *big.Int) []*ethpb.DepositContainer {
40+
panic("implement me")
41+
}
42+
43+
func (MockDepositFetcher) PrunePendingDeposits(_ context.Context, _ int64) {
44+
panic("implement me")
45+
}
46+
47+
func (MockDepositFetcher) PruneProofs(_ context.Context, _ int64) error {
48+
panic("implement me")
49+
}
50+
51+
func (m MockDepositFetcher) Snapshot() (*ethpb.DepositSnapshot, error) {
52+
return m.Snap, nil
53+
}
54+
55+
func (MockDepositFetcher) FinalizedDeposits(_ context.Context) (cache.FinalizedDeposits, error) {
56+
panic("implement me")
57+
}
58+
59+
func (MockDepositFetcher) NonFinalizedDeposits(_ context.Context, _ int64, _ *big.Int) []*ethpb.Deposit {
60+
panic("implement me")
61+
}

beacon-chain/cache/depositsnapshot/deposit_fetcher.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ func (c *Cache) InsertPendingDeposit(ctx context.Context, d *ethpb.Deposit, bloc
244244
span.AddAttributes(trace.Int64Attribute("count", int64(len(c.pendingDeposits))))
245245
}
246246

247+
func (c *Cache) Snapshot() (*ethpb.DepositSnapshot, error) {
248+
return c.finalizedDeposits.depositTree.ToProto()
249+
}
250+
247251
// Deposits returns the cached internal deposit tree.
248252
func (fd *finalizedDepositsContainer) Deposits() cache.MerkleTree {
249253
return fd.depositTree

beacon-chain/cache/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type DepositFetcher interface {
2525
PendingContainers(ctx context.Context, untilBlk *big.Int) []*ethpb.DepositContainer
2626
PrunePendingDeposits(ctx context.Context, merkleTreeIndex int64)
2727
PruneProofs(ctx context.Context, untilDepositIndex int64) error
28+
Snapshot() (*ethpb.DepositSnapshot, error)
2829
FinalizedFetcher
2930
}
3031

beacon-chain/deterministic-genesis/service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func (s *Service) PruneProofs(ctx context.Context, untilDepositIndex int64) erro
6464
return nil
6565
}
6666

67+
func (s *Service) Snapshot() (*ethpb.DepositSnapshot, error) {
68+
log.Error("Snapshot should not be called")
69+
return nil, nil
70+
}
71+
6772
// Config options for the interop service.
6873
type Config struct {
6974
GenesisTime uint64

beacon-chain/rpc/endpoints.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func (s *Service) beaconEndpoints(
358358
FinalizationFetcher: s.cfg.FinalizationFetcher,
359359
ForkchoiceFetcher: s.cfg.ForkchoiceFetcher,
360360
CoreService: coreService,
361+
DepositFetcher: s.cfg.DepositFetcher,
361362
}
362363

363364
const namespace = "beacon"
@@ -548,6 +549,12 @@ func (s *Service) beaconEndpoints(
548549
handler: server.GetValidatorBalances,
549550
methods: []string{http.MethodGet, http.MethodPost},
550551
},
552+
{
553+
template: "/eth/v1/beacon/deposit_snapshot",
554+
name: namespace + ",GetDepositSnapshot",
555+
handler: server.GetDepositSnapshot,
556+
methods: []string{http.MethodGet},
557+
},
551558
}
552559
}
553560

beacon-chain/rpc/eth/beacon/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ go_library(
1717
"//api/server:go_default_library",
1818
"//api/server/structs:go_default_library",
1919
"//beacon-chain/blockchain:go_default_library",
20+
"//beacon-chain/cache:go_default_library",
2021
"//beacon-chain/cache/depositsnapshot:go_default_library",
2122
"//beacon-chain/core/altair:go_default_library",
2223
"//beacon-chain/core/blocks:go_default_library",
@@ -79,6 +80,7 @@ go_test(
7980
"//api/server:go_default_library",
8081
"//api/server/structs:go_default_library",
8182
"//beacon-chain/blockchain/testing:go_default_library",
83+
"//beacon-chain/cache/depositcache/testing:go_default_library",
8284
"//beacon-chain/cache/depositsnapshot:go_default_library",
8385
"//beacon-chain/core/signing:go_default_library",
8486
"//beacon-chain/core/time:go_default_library",

beacon-chain/rpc/eth/beacon/handlers.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,29 +2054,24 @@ func (s *Server) GetGenesis(w http.ResponseWriter, r *http.Request) {
20542054
// GetDepositSnapshot retrieves the EIP-4881 Deposit Tree Snapshot. Either a JSON or,
20552055
// if the Accept header was added, bytes serialized by SSZ will be returned.
20562056
func (s *Server) GetDepositSnapshot(w http.ResponseWriter, r *http.Request) {
2057-
ctx, span := trace.StartSpan(r.Context(), "beacon.GetDepositSnapshot")
2057+
_, span := trace.StartSpan(r.Context(), "beacon.GetDepositSnapshot")
20582058
defer span.End()
20592059

2060-
if s.BeaconDB == nil {
2061-
httputil.HandleError(w, "Could not retrieve beaconDB", http.StatusInternalServerError)
2062-
return
2063-
}
2064-
eth1data, err := s.BeaconDB.ExecutionChainData(ctx)
2060+
snapshot, err := s.DepositFetcher.Snapshot()
20652061
if err != nil {
2066-
httputil.HandleError(w, "Could not retrieve execution chain data: "+err.Error(), http.StatusInternalServerError)
2067-
return
2068-
}
2069-
if eth1data == nil {
2070-
httputil.HandleError(w, "Could not retrieve execution chain data: empty Eth1Data", http.StatusInternalServerError)
2062+
httputil.HandleError(w, "Could not retrieve snapshot: "+err.Error(), http.StatusInternalServerError)
20712063
return
20722064
}
2073-
snapshot := eth1data.DepositSnapshot
20742065
if snapshot == nil || len(snapshot.Finalized) == 0 {
2075-
httputil.HandleError(w, "No Finalized Snapshot Available", http.StatusNotFound)
2066+
httputil.HandleError(w, "Could not retrieve snapshot: empty snapshot", http.StatusInternalServerError)
20762067
return
20772068
}
20782069
if len(snapshot.Finalized) > depositsnapshot.DepositContractDepth {
2079-
httputil.HandleError(w, "Retrieved invalid deposit snapshot", http.StatusInternalServerError)
2070+
httputil.HandleError(
2071+
w,
2072+
fmt.Sprintf("Snapshot depth %d bigger than deposit contract depth %d", len(snapshot.Finalized), depositsnapshot.DepositContractDepth),
2073+
http.StatusInternalServerError,
2074+
)
20802075
return
20812076
}
20822077
if httputil.RespondWithSsz(r) {

0 commit comments

Comments
 (0)