Skip to content

Commit

Permalink
fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed May 28, 2024
1 parent 9296cf0 commit ffe7996
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/prometheus/client_golang v1.19.0
github.com/protolambda/zrnt v0.32.3
github.com/protolambda/ztyp v0.2.2
github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e
github.com/rs/zerolog v1.32.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -74,7 +75,6 @@ require (
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/protolambda/bls12-381-util v0.1.0 // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e // indirect
github.com/r3labs/sse/v2 v2.10.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=
github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o=
github.com/attestantio/go-eth2-client v0.0.0-20240507092336-27309754c54f h1:k4axih4fc/7Atb9eTsPsPFxlGGb501o+ryUt9q0stR8=
github.com/attestantio/go-eth2-client v0.0.0-20240507092336-27309754c54f/go.mod h1:Ht9tN0WlhpgIWWO7Hqfi3/nq2rUGQv/zCd/BMI93a84=
github.com/attestantio/go-eth2-client v0.0.0-20240508205406-66fbb02e3c16 h1:42mZV077pxU7zD/v5NSoA+L8qjetVsBcyYbYKDw4UpA=
github.com/attestantio/go-eth2-client v0.0.0-20240508205406-66fbb02e3c16/go.mod h1:Ht9tN0WlhpgIWWO7Hqfi3/nq2rUGQv/zCd/BMI93a84=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
16 changes: 11 additions & 5 deletions pkg/coordinator/tasks/check_consensus_attestation_stats/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func (t *Task) aggregateEpochVotes(ctx context.Context, epoch uint64) []*epochVo

voteAmount := uint64(0)
voteCount := uint64(0)

if att.Version >= spec.DataVersionElectra {
// EIP-7549 changes the attestation aggregation
// there can now be attestations from all committees aggregated into a single attestation aggregate
Expand All @@ -433,6 +434,7 @@ func (t *Task) aggregateEpochVotes(ctx context.Context, epoch uint64) []*epochVo
}

aggregationBitsOffset := uint64(0)

for committee := uint64(0); committee < specs.MaxCommitteesPerSlot; committee++ {
if !committeeBits.BitAt(committee) {
continue
Expand All @@ -459,6 +461,7 @@ func (t *Task) aggregateEpochVotes(ctx context.Context, epoch uint64) []*epochVo
votes.currentEpoch.targetVoteAmount += voteAmount
}
}

if bytes.Equal(attData.BeaconBlockRoot[:], parentRoot[:]) {
if isNextEpoch {
votes.nextEpoch.headVoteCount += voteCount
Expand Down Expand Up @@ -490,21 +493,24 @@ func (t *Task) aggregateEpochVotes(ctx context.Context, epoch uint64) []*epochVo
return votes
}

func (t *Task) aggregateAttestationVotes(votes *epochVotes, slot uint64, committee uint64, aggregationBits bitfield.Bitfield, aggregationBitsOffset uint64) (uint64, uint64, uint64) {
voteAmount := uint64(0)
voteCount := uint64(0)
func (t *Task) aggregateAttestationVotes(votes *epochVotes, slot, committee uint64, aggregationBits bitfield.Bitfield, aggregationBitsOffset uint64) (voteAmount, voteCount, validatorCount uint64) {
attKey := fmt.Sprintf("%v-%v", slot, committee)
voteValidators := votes.attesterDuties.duties[attKey]

for bitIdx, attDuty := range voteValidators {
validatorIdx := attDuty.validator
if aggregationBits.BitAt(uint64(bitIdx) + aggregationBitsOffset) {
if votes.activityMap[validatorIdx] {
continue
}

voteAmount += attDuty.balance
voteCount += 1
voteCount++
votes.activityMap[validatorIdx] = true
}
}
return voteAmount, voteCount, uint64(len(voteValidators))

validatorCount = uint64(len(voteValidators))

return
}
1 change: 1 addition & 0 deletions pkg/coordinator/tasks/generate_consolidations/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (c *Config) Validate() error {
if c.SourceMnemonic == "" {
return errors.New("sourceMnemonic must be set")
}

if c.TargetMnemonic == "" {
return errors.New("sourceMnemonic must be set")
}
Expand Down
17 changes: 12 additions & 5 deletions pkg/coordinator/tasks/generate_consolidations/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
}
)

var DOMAIN_CONSOLIDATION = common.BLSDomainType{0x0B, 0x00, 0x00, 0x00}
var DomainConsolidation = common.BLSDomainType{0x0B, 0x00, 0x00, 0x00}

type Task struct {
ctx *types.TaskContext
Expand Down Expand Up @@ -110,6 +110,7 @@ func (t *Task) LoadConfig() error {
}

validatorKeyPath := fmt.Sprintf("m/12381/3600/%d/0/0", config.TargetKeyIndex)

t.targetPrivKey, err = util.PrivateKeyFromSeedAndPath(t.targetSeed, validatorKeyPath)
if err != nil {
return fmt.Errorf("failed generating target validator key %v: %w", validatorKeyPath, err)
Expand Down Expand Up @@ -188,15 +189,16 @@ func (t *Task) generateConsolidation(ctx context.Context, accountIdx uint64) err
validatorSet := clientPool.GetConsensusPool().GetValidatorSet()
specs := clientPool.GetConsensusPool().GetBlockCache().GetSpecs()

var sourceValidator *v1.Validator
var targetValidator *v1.Validator
var sourceValidator, targetValidator *v1.Validator

sourceValidatorPubkey := validatorPrivkey.PublicKey().Marshal()
targetValidatorPubkey := t.targetPrivKey.PublicKey().Marshal()

for _, val := range validatorSet {
if bytes.Equal(val.Validator.PublicKey[:], sourceValidatorPubkey) {
sourceValidator = val
}

if bytes.Equal(val.Validator.PublicKey[:], targetValidatorPubkey) {
targetValidator = val
}
Expand All @@ -205,13 +207,15 @@ func (t *Task) generateConsolidation(ctx context.Context, accountIdx uint64) err
if sourceValidator == nil {
return fmt.Errorf("source validator not found")
}

if targetValidator == nil {
return fmt.Errorf("source validator not found")
}

if sourceValidator.Validator.WithdrawalCredentials[0] != 0x01 {
return fmt.Errorf("validator %v does not have 0x01 withdrawal creds", sourceValidator.Index)
}

if targetValidator.Validator.WithdrawalCredentials[0] != 0x01 {
return fmt.Errorf("validator %v does not have 0x01 withdrawal creds", targetValidator.Index)
}
Expand All @@ -238,7 +242,8 @@ func (t *Task) generateConsolidation(ctx context.Context, accountIdx uint64) err
SourceIndex: sourceValidator.Index,
TargetIndex: targetValidator.Index,
}
if t.config.ConsolidationEpoch >= 0 {

if t.config.ConsolidationEpoch > 0 {
operation.Epoch = phase0.Epoch(t.config.ConsolidationEpoch)
} else {
currentSlot, _ := client.GetLastHead()
Expand All @@ -252,7 +257,7 @@ func (t *Task) generateConsolidation(ctx context.Context, accountIdx uint64) err
}

genesis := clientPool.GetConsensusPool().GetBlockCache().GetGenesis()
dom := common.ComputeDomain(DOMAIN_CONSOLIDATION, common.Version(genesis.GenesisForkVersion), tree.Root(genesis.GenesisValidatorsRoot))
dom := common.ComputeDomain(DomainConsolidation, common.Version(genesis.GenesisForkVersion), tree.Root(genesis.GenesisValidatorsRoot))
signingRoot := common.ComputeSigningRoot(operationRoot, dom)

// source signature
Expand All @@ -262,6 +267,7 @@ func (t *Task) generateConsolidation(ctx context.Context, accountIdx uint64) err
if err != nil {
return fmt.Errorf("failed converting validator priv key: %w", err)
}

sig1 := sourceSecKey.SignHash(signingRoot[:])

// target signature
Expand All @@ -271,6 +277,7 @@ func (t *Task) generateConsolidation(ctx context.Context, accountIdx uint64) err
if err != nil {
return fmt.Errorf("failed converting validator priv key: %w", err)
}

sig2 := targetSecKey.SignHash(signingRoot[:])

// aggregate signature
Expand Down

0 comments on commit ffe7996

Please sign in to comment.