mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
798bbbdc82
* coldstart flags for validator * WIP beacon node flags * wip beacon chain, flag fix in validator, arg fix in validator * checkpoint * Added interop service * working on mock chainstart * save the state lol * fix tests * Save genesis validators * gaz * fix validator help flags * WaitForChainStart actually waits for genesis time * cold start fixes * cache * change back * allow for genesis state too * remove logs * increase mmap size * dont process if head doesn't exist * add 10ms tolerance * enable libp2p debug at debug, fix pubsub * works with checkpt * initialize justified and finalized in db * Removed preloadStatePath from blockchain service * Clean up * Write to disk for now post state * revert b466dd536f8eadbdae2264a545a755370223d917 * Builds * Only RPC test fails now * use minimal config, no demo config * clean up branch * Lint * resolve lint * more lint fixes * lint * fix viz * Fixing RPC test * skip before epoch 2 * RPC time out * Fixed ordering * rename * remove some dbg statements * ensure index is correct * fix some panics * getting closer * fix tests * Fix private key * Fixed RPC test * Fixed beacon chain build for docker * Add interop.go to validator go_image * Fixed docker build * handle errors * skip test, skip disconnecting peers * Fixed docker build * tolerance for attestation processing * revert copy * clearer err message parse * fix launching from dep contract
101 lines
3.9 KiB
Go
101 lines
3.9 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
|
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// BeaconServer defines a server implementation of the gRPC Beacon service,
|
|
// providing RPC endpoints for obtaining the canonical beacon chain head,
|
|
// fetching latest observed attestations, and more.
|
|
type BeaconServer struct {
|
|
beaconDB db.Database
|
|
ctx context.Context
|
|
chainStartFetcher powchain.ChainStartFetcher
|
|
eth1InfoFetcher powchain.ChainInfoFetcher
|
|
headFetcher blockchain.HeadFetcher
|
|
stateFeedListener blockchain.ChainFeeds
|
|
incomingAttestation chan *ethpb.Attestation
|
|
canonicalStateChan chan *pbp2p.BeaconState
|
|
chainStartChan chan time.Time
|
|
}
|
|
|
|
// WaitForChainStart queries the logs of the Deposit Contract in order to verify the beacon chain
|
|
// has started its runtime and validators begin their responsibilities. If it has not, it then
|
|
// subscribes to an event stream triggered by the powchain service whenever the ChainStart log does
|
|
// occur in the Deposit Contract on ETH 1.0.
|
|
func (bs *BeaconServer) WaitForChainStart(req *ptypes.Empty, stream pb.BeaconService_WaitForChainStartServer) error {
|
|
head, err := bs.beaconDB.HeadState(context.Background())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if head != nil {
|
|
res := &pb.ChainStartResponse{
|
|
Started: true,
|
|
GenesisTime: head.GenesisTime,
|
|
}
|
|
return stream.Send(res)
|
|
}
|
|
|
|
sub := bs.stateFeedListener.StateInitializedFeed().Subscribe(bs.chainStartChan)
|
|
defer sub.Unsubscribe()
|
|
for {
|
|
select {
|
|
case chainStartTime := <-bs.chainStartChan:
|
|
log.Info("Sending ChainStart log and genesis time to connected validator clients")
|
|
res := &pb.ChainStartResponse{
|
|
Started: true,
|
|
GenesisTime: uint64(chainStartTime.Unix()),
|
|
}
|
|
return stream.Send(res)
|
|
case <-sub.Err():
|
|
return errors.New("subscriber closed, exiting goroutine")
|
|
case <-bs.ctx.Done():
|
|
return errors.New("rpc context closed, exiting goroutine")
|
|
}
|
|
}
|
|
}
|
|
|
|
// CanonicalHead of the current beacon chain. This method is requested on-demand
|
|
// by a validator when it is their time to propose or attest.
|
|
func (bs *BeaconServer) CanonicalHead(ctx context.Context, req *ptypes.Empty) (*ethpb.BeaconBlock, error) {
|
|
return bs.headFetcher.HeadBlock(), nil
|
|
}
|
|
|
|
// BlockTree returns the current tree of saved blocks and their votes starting from the justified state.
|
|
func (bs *BeaconServer) BlockTree(ctx context.Context, _ *ptypes.Empty) (*pb.BlockTreeResponse, error) {
|
|
// TODO(3219): Add after new fork choice service.
|
|
return nil, status.Error(codes.Unimplemented, "not implemented")
|
|
}
|
|
|
|
// BlockTreeBySlots returns the current tree of saved blocks and their
|
|
// votes starting from the justified state.
|
|
func (bs *BeaconServer) BlockTreeBySlots(ctx context.Context, req *pb.TreeBlockSlotRequest) (*pb.BlockTreeResponse, error) {
|
|
// TODO(3219): Add after new fork choice service.
|
|
return nil, status.Error(codes.Unimplemented, "not implemented")
|
|
}
|
|
|
|
func constructMerkleProof(trie *trieutil.MerkleTrie, index int, deposit *ethpb.Deposit) (*ethpb.Deposit, error) {
|
|
proof, err := trie.MerkleProof(index)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "could not generate merkle proof for deposit at index %d", index)
|
|
}
|
|
// For every deposit, we construct a Merkle proof using the powchain service's
|
|
// in-memory deposits trie, which is updated only once the state's LatestETH1Data
|
|
// property changes during a state transition after a voting period.
|
|
deposit.Proof = proof
|
|
return deposit, nil
|
|
}
|