Skip to content

Commit

Permalink
added check_consensus_attestation_stats task
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 14, 2023
1 parent 8cbf009 commit 0cad2f4
Show file tree
Hide file tree
Showing 7 changed files with 545 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/coordinator/clients/consensus/blockcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (cache *BlockCache) InitWallclock() {
}

specs := cache.GetSpecs()
if specs == nil || cache.genesis != nil {
if specs == nil || cache.genesis == nil {
return
}

Expand Down Expand Up @@ -233,6 +233,21 @@ func (cache *BlockCache) GetCachedBlockByRoot(root phase0.Root) *Block {
return cache.rootMap[root]
}

func (cache *BlockCache) GetCachedBlocksBySlot(slot phase0.Slot) []*Block {
cache.cacheMutex.RLock()
defer cache.cacheMutex.RUnlock()

blocks := cache.slotMap[slot]
if len(blocks) == 0 {
return blocks
}

res := make([]*Block, len(blocks))
copy(res, blocks)

return res
}

func (cache *BlockCache) GetCachedBlocks() []*Block {
cache.cacheMutex.RLock()
defer cache.cacheMutex.RUnlock()
Expand Down
1 change: 1 addition & 0 deletions pkg/coordinator/clients/consensus/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewPool(config *PoolConfig) (*Pool, error) {
pool := Pool{
config: config,
clients: make([]*Client, 0),
forkCache: map[int64][]*HeadFork{},
rrLastIndexes: map[ClientType]uint16{},
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/coordinator/clients/consensus/rpc/beaconapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ func (bc *BeaconClient) GetBlockBodyByBlockroot(ctx context.Context, blockroot p
return result, nil
}

func (bc *BeaconClient) GetState(ctx context.Context, stateRef string) (*spec.VersionedBeaconState, error) {
provider, isProvider := bc.clientSvc.(eth2client.BeaconStateProvider)
if !isProvider {
return nil, fmt.Errorf("get beacon state not supported")
}

result, err := provider.BeaconState(ctx, stateRef)
if err != nil {
return nil, err
}

return result, nil
}

func (bc *BeaconClient) GetStateValidators(ctx context.Context, stateRef string) (map[phase0.ValidatorIndex]*v1.Validator, error) {
provider, isProvider := bc.clientSvc.(eth2client.ValidatorsProvider)
if !isProvider {
Expand All @@ -219,6 +233,20 @@ func (bc *BeaconClient) GetStateValidators(ctx context.Context, stateRef string)
return result, nil
}

func (bc *BeaconClient) GetCommitteeDuties(ctx context.Context, stateRef string, epoch uint64) ([]*v1.BeaconCommittee, error) {
provider, isProvider := bc.clientSvc.(eth2client.BeaconCommitteesProvider)
if !isProvider {
return nil, fmt.Errorf("get beacon committees not supported")
}

result, err := provider.BeaconCommitteesAtEpoch(ctx, stateRef, phase0.Epoch(epoch))
if err != nil {
return nil, err
}

return result, nil
}

func (bc *BeaconClient) GetForkState(ctx context.Context, stateRef string) (*phase0.Fork, error) {
provider, isProvider := bc.clientSvc.(eth2client.ForkProvider)
if !isProvider {
Expand Down
1 change: 1 addition & 0 deletions pkg/coordinator/clients/execution/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewPool(config *PoolConfig) (*Pool, error) {
pool := Pool{
config: config,
clients: make([]*Client, 0),
forkCache: map[int64][]*HeadFork{},
rrLastIndexes: map[ClientType]uint16{},
walletsMap: map[common.Address]*Wallet{},
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/coordinator/tasks/check_consensus_attestation_stats/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package checkconsensusattestationstats

type Config struct {
MinTargetPercent uint64 `yaml:"minTargetPercent" json:"minTargetPercent"`
MaxTargetPercent uint64 `yaml:"maxTargetPercent" json:"maxTargetPercent"`
MinHeadPercent uint64 `yaml:"minHeadPercent" json:"minHeadPercent"`
MaxHeadPercent uint64 `yaml:"maxHeadPercent" json:"maxHeadPercent"`
MinTotalPercent uint64 `yaml:"minTotalPercent" json:"minTotalPercent"`
MaxTotalPercent uint64 `yaml:"maxTotalPercent" json:"maxTotalPercent"`
FailOnCheckMiss bool `yaml:"failOnCheckMiss" json:"failOnCheckMiss"`
MinCheckedEpochs uint64 `yaml:"minCheckedEpochs" json:"minCheckedEpochs"`
}

func DefaultConfig() Config {
return Config{
MaxTargetPercent: 100,
MaxHeadPercent: 100,
MaxTotalPercent: 100,
MinCheckedEpochs: 1,
}
}

func (c *Config) Validate() error {
return nil
}
Loading

0 comments on commit 0cad2f4

Please sign in to comment.