mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
Wire voluntary exits pool (#4613)
* Hookup voluntary exits pool * Merge refs/heads/master into wire-voluntary-exits * Merge refs/heads/master into wire-voluntary-exits * Merge refs/heads/master into wire-voluntary-exits * Merge refs/heads/master into wire-voluntary-exits * Merge refs/heads/master into wire-voluntary-exits * Merge refs/heads/master into wire-voluntary-exits * fix tests * Merge branch 'wire-voluntary-exits' of github.com:prysmaticlabs/prysm into wire-voluntary-exits * Merge refs/heads/master into wire-voluntary-exits * gofmt * Merge branch 'wire-voluntary-exits' of github.com:prysmaticlabs/prysm into wire-voluntary-exits * gofmt * gaz * Merge refs/heads/master into wire-voluntary-exits
This commit is contained in:
parent
a1e3c2d47c
commit
4aa7ebc2b7
@ -24,6 +24,7 @@ go_library(
|
||||
"//beacon-chain/core/state:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/powchain:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
|
@ -125,6 +125,9 @@ func (s *Service) ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.SignedB
|
||||
log.Errorf("Could not save attestation for fork choice: %v", err)
|
||||
return nil
|
||||
}
|
||||
for _, exit := range block.Block.Body.VoluntaryExits {
|
||||
s.exitPool.MarkIncluded(exit)
|
||||
}
|
||||
|
||||
// Reports on block and fork choice metrics.
|
||||
s.reportSlotMetrics(blockCopy.Block.Slot)
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@ -43,6 +44,7 @@ type Service struct {
|
||||
depositCache *depositcache.DepositCache
|
||||
chainStartFetcher powchain.ChainStartFetcher
|
||||
attPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
forkChoiceStore forkchoice.ForkChoicer
|
||||
genesisTime time.Time
|
||||
p2p p2p.Broadcaster
|
||||
@ -65,6 +67,7 @@ type Config struct {
|
||||
BeaconDB db.HeadAccessDatabase
|
||||
DepositCache *depositcache.DepositCache
|
||||
AttPool attestations.Pool
|
||||
ExitPool *voluntaryexits.Pool
|
||||
P2p p2p.Broadcaster
|
||||
MaxRoutines int64
|
||||
StateNotifier statefeed.Notifier
|
||||
@ -82,6 +85,7 @@ func NewService(ctx context.Context, cfg *Config) (*Service, error) {
|
||||
depositCache: cfg.DepositCache,
|
||||
chainStartFetcher: cfg.ChainStartFetcher,
|
||||
attPool: cfg.AttPool,
|
||||
exitPool: cfg.ExitPool,
|
||||
forkChoiceStore: store,
|
||||
p2p: cfg.P2p,
|
||||
canonicalRoots: make(map[uint64][]byte),
|
||||
|
@ -17,6 +17,7 @@ go_library(
|
||||
"//beacon-chain/gateway:go_default_library",
|
||||
"//beacon-chain/interop-cold-start:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/powchain:go_default_library",
|
||||
"//beacon-chain/rpc:go_default_library",
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/gateway"
|
||||
interopcoldstart "github.com/prysmaticlabs/prysm/beacon-chain/interop-cold-start"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/rpc"
|
||||
@ -58,6 +59,7 @@ type BeaconNode struct {
|
||||
stop chan struct{} // Channel to wait for termination notifications.
|
||||
db db.Database
|
||||
attestationPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
depositCache *depositcache.DepositCache
|
||||
stateFeed *event.Feed
|
||||
opFeed *event.Feed
|
||||
@ -101,6 +103,7 @@ func NewBeaconNode(ctx *cli.Context) (*BeaconNode, error) {
|
||||
stateFeed: new(event.Feed),
|
||||
opFeed: new(event.Feed),
|
||||
attestationPool: attestations.NewPool(),
|
||||
exitPool: voluntaryexits.NewPool(),
|
||||
}
|
||||
|
||||
if err := beacon.startDB(ctx); err != nil {
|
||||
@ -304,6 +307,7 @@ func (b *BeaconNode) registerBlockchainService(ctx *cli.Context) error {
|
||||
DepositCache: b.depositCache,
|
||||
ChainStartFetcher: web3Service,
|
||||
AttPool: b.attestationPool,
|
||||
ExitPool: b.exitPool,
|
||||
P2p: b.fetchP2P(ctx),
|
||||
MaxRoutines: maxRoutines,
|
||||
StateNotifier: b,
|
||||
@ -392,6 +396,7 @@ func (b *BeaconNode) registerSyncService(ctx *cli.Context) error {
|
||||
InitialSync: initSync,
|
||||
StateNotifier: b,
|
||||
AttPool: b.attestationPool,
|
||||
ExitPool: b.exitPool,
|
||||
})
|
||||
|
||||
return b.services.RegisterService(rs)
|
||||
@ -471,6 +476,7 @@ func (b *BeaconNode) registerRPCService(ctx *cli.Context) error {
|
||||
AttestationReceiver: chainService,
|
||||
GenesisTimeFetcher: chainService,
|
||||
AttestationsPool: b.attestationPool,
|
||||
ExitPool: b.exitPool,
|
||||
POWChainService: web3Service,
|
||||
ChainStartFetcher: chainStartFetcher,
|
||||
MockEth1Votes: mockEth1DataVotes,
|
||||
|
@ -9,7 +9,6 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/blockchain:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
@ -22,8 +21,6 @@ go_test(
|
||||
srcs = ["service_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"sync"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
@ -17,16 +16,14 @@ type Pool struct {
|
||||
lock sync.RWMutex
|
||||
pending []*ethpb.SignedVoluntaryExit
|
||||
included map[uint64]bool
|
||||
chain blockchain.HeadFetcher
|
||||
}
|
||||
|
||||
// NewPool accepts a head fetcher (for reading the validator set) and returns an initialized
|
||||
// voluntary exit pool.
|
||||
func NewPool(chain blockchain.HeadFetcher) *Pool {
|
||||
func NewPool() *Pool {
|
||||
return &Pool{
|
||||
pending: make([]*ethpb.SignedVoluntaryExit, 0),
|
||||
included: make(map[uint64]bool),
|
||||
chain: chain,
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +43,7 @@ func (p *Pool) PendingExits(slot uint64) []*ethpb.SignedVoluntaryExit {
|
||||
|
||||
// InsertVoluntaryExit into the pool. This method is a no-op if the pending exit already exists,
|
||||
// has been included recently, or the validator is already exited.
|
||||
func (p *Pool) InsertVoluntaryExit(ctx context.Context, exit *ethpb.SignedVoluntaryExit) {
|
||||
func (p *Pool) InsertVoluntaryExit(ctx context.Context, validators []*ethpb.Validator, exit *ethpb.SignedVoluntaryExit) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
@ -56,7 +53,7 @@ func (p *Pool) InsertVoluntaryExit(ctx context.Context, exit *ethpb.SignedVolunt
|
||||
}
|
||||
|
||||
// Has the validator been exited already?
|
||||
if h, _ := p.chain.HeadState(ctx); h == nil || len(h.Validators) <= int(exit.Exit.ValidatorIndex) || h.Validators[exit.Exit.ValidatorIndex].ExitEpoch != params.BeaconConfig().FarFutureEpoch {
|
||||
if len(validators) <= int(exit.Exit.ValidatorIndex) || validators[exit.Exit.ValidatorIndex].ExitEpoch != params.BeaconConfig().FarFutureEpoch {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,6 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
@ -193,22 +191,18 @@ func TestPool_InsertVoluntaryExit(t *testing.T) {
|
||||
},
|
||||
}
|
||||
ctx := context.Background()
|
||||
chain := &mock.ChainService{
|
||||
State: &pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
{ // 0
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{ // 1
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{ // 2 - Already exited.
|
||||
ExitEpoch: 15,
|
||||
},
|
||||
{ // 3
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
},
|
||||
validators := []*ethpb.Validator{
|
||||
{ // 0
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{ // 1
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{ // 2 - Already exited.
|
||||
ExitEpoch: 15,
|
||||
},
|
||||
{ // 3
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@ -216,9 +210,8 @@ func TestPool_InsertVoluntaryExit(t *testing.T) {
|
||||
p := &Pool{
|
||||
pending: tt.fields.pending,
|
||||
included: tt.fields.included,
|
||||
chain: chain,
|
||||
}
|
||||
p.InsertVoluntaryExit(ctx, tt.args.exit)
|
||||
p.InsertVoluntaryExit(ctx, validators, tt.args.exit)
|
||||
if len(p.pending) != len(tt.want) {
|
||||
t.Fatalf("Mismatched lengths of pending list. Got %d, wanted %d.", len(p.pending), len(tt.want))
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ go_library(
|
||||
"//beacon-chain/core/feed/state:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/powchain:go_default_library",
|
||||
"//beacon-chain/rpc/aggregator:go_default_library",
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/aggregator"
|
||||
@ -64,6 +65,7 @@ type Service struct {
|
||||
chainStartFetcher powchain.ChainStartFetcher
|
||||
mockEth1Votes bool
|
||||
attestationsPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
syncService sync.Checker
|
||||
host string
|
||||
port string
|
||||
@ -105,6 +107,7 @@ type Config struct {
|
||||
GenesisTimeFetcher blockchain.GenesisTimeFetcher
|
||||
MockEth1Votes bool
|
||||
AttestationsPool attestations.Pool
|
||||
ExitPool *voluntaryexits.Pool
|
||||
SyncService sync.Checker
|
||||
Broadcaster p2p.Broadcaster
|
||||
PeersFetcher p2p.PeersProvider
|
||||
@ -137,6 +140,7 @@ func NewService(ctx context.Context, cfg *Config) *Service {
|
||||
chainStartFetcher: cfg.ChainStartFetcher,
|
||||
mockEth1Votes: cfg.MockEth1Votes,
|
||||
attestationsPool: cfg.AttestationsPool,
|
||||
exitPool: cfg.ExitPool,
|
||||
syncService: cfg.SyncService,
|
||||
host: cfg.Host,
|
||||
port: cfg.Port,
|
||||
@ -202,6 +206,7 @@ func (s *Service) Start() {
|
||||
BeaconDB: s.beaconDB,
|
||||
AttestationCache: cache.NewAttestationCache(),
|
||||
AttPool: s.attestationsPool,
|
||||
ExitPool: s.exitPool,
|
||||
HeadFetcher: s.headFetcher,
|
||||
ForkFetcher: s.forkFetcher,
|
||||
FinalizationFetcher: s.finalizationFetcher,
|
||||
|
@ -25,6 +25,7 @@ go_library(
|
||||
"//beacon-chain/core/state/interop:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/powchain:go_default_library",
|
||||
"//beacon-chain/sync:go_default_library",
|
||||
@ -72,6 +73,7 @@ go_test(
|
||||
"//beacon-chain/core/state:go_default_library",
|
||||
"//beacon-chain/db/testing:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p/testing:go_default_library",
|
||||
"//beacon-chain/powchain/testing:go_default_library",
|
||||
"//beacon-chain/rpc/testing:go_default_library",
|
||||
|
@ -39,5 +39,7 @@ func (vs *Server) ProposeExit(ctx context.Context, req *ethpb.SignedVoluntaryExi
|
||||
},
|
||||
})
|
||||
|
||||
return nil, nil
|
||||
vs.ExitPool.InsertVoluntaryExit(ctx, s.Validators, req)
|
||||
|
||||
return nil, vs.P2P.Broadcast(ctx, req)
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import (
|
||||
opfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@ -46,6 +48,8 @@ func TestSub(t *testing.T) {
|
||||
GenesisTime: genesisTime,
|
||||
StateNotifier: mockChainService.StateNotifier(),
|
||||
OperationNotifier: mockChainService.OperationNotifier(),
|
||||
ExitPool: voluntaryexits.NewPool(),
|
||||
P2P: mockp2p.NewTestP2P(t),
|
||||
}
|
||||
|
||||
// Subscribe to operation notifications.
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
||||
@ -51,6 +52,7 @@ type Server struct {
|
||||
StateNotifier statefeed.Notifier
|
||||
P2P p2p.Broadcaster
|
||||
AttPool attestations.Pool
|
||||
ExitPool *voluntaryexits.Pool
|
||||
BlockReceiver blockchain.BlockReceiver
|
||||
MockEth1Votes bool
|
||||
Eth1BlockFetcher powchain.POWBlockFetcher
|
||||
|
@ -43,6 +43,7 @@ go_library(
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/filters:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
"//beacon-chain/operations/voluntaryexits:go_default_library",
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/p2p/encoder:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/shared"
|
||||
)
|
||||
@ -25,6 +26,7 @@ type Config struct {
|
||||
P2P p2p.P2P
|
||||
DB db.NoHeadAccessDatabase
|
||||
AttPool attestations.Pool
|
||||
ExitPool *voluntaryexits.Pool
|
||||
Chain blockchainService
|
||||
InitialSync Checker
|
||||
StateNotifier statefeed.Notifier
|
||||
@ -49,6 +51,7 @@ func NewRegularSync(cfg *Config) *Service {
|
||||
db: cfg.DB,
|
||||
p2p: cfg.P2P,
|
||||
attPool: cfg.AttPool,
|
||||
exitPool: cfg.ExitPool,
|
||||
chain: cfg.Chain,
|
||||
initialSync: cfg.InitialSync,
|
||||
slotToPendingBlocks: make(map[uint64]*ethpb.SignedBeaconBlock),
|
||||
@ -71,6 +74,7 @@ type Service struct {
|
||||
p2p p2p.P2P
|
||||
db db.NoHeadAccessDatabase
|
||||
attPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
chain blockchainService
|
||||
slotToPendingBlocks map[uint64]*ethpb.SignedBeaconBlock
|
||||
seenPendingBlocks map[[32]byte]bool
|
||||
|
@ -4,10 +4,15 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
)
|
||||
|
||||
func (r *Service) voluntaryExitSubscriber(ctx context.Context, msg proto.Message) error {
|
||||
// TODO(#3259): Requires handlers in operations service to be implemented.
|
||||
s, err := r.chain.HeadState(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.exitPool.InsertVoluntaryExit(ctx, s.Validators, msg.(*ethpb.SignedVoluntaryExit))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ func setupValidExit(t *testing.T) (*ethpb.SignedVoluntaryExit, *pb.BeaconState)
|
||||
exit := ðpb.SignedVoluntaryExit{
|
||||
Exit: ðpb.VoluntaryExit{
|
||||
ValidatorIndex: 0,
|
||||
Epoch: 1+params.BeaconConfig().PersistentCommitteePeriod,
|
||||
Epoch: 1 + params.BeaconConfig().PersistentCommitteePeriod,
|
||||
},
|
||||
}
|
||||
registry := []*ethpb.Validator{
|
||||
|
Loading…
Reference in New Issue
Block a user