Skip to content

Commit

Permalink
fix the remembered proposer index/pubkey mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Apr 7, 2023
1 parent bccadc5 commit bf5f210
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions beaconclient/multi_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,22 @@ func (c *MultiBeaconClient) PublishBlock(block *common.SignedBeaconBlock) (code
var lastErrPublishResp publishResp
for i := 0; i < len(clients); i++ {
res := <-resChans
log = log.WithField("beacon", clients[res.index].GetURI())
if res.err != nil {
log.WithField("beacon", clients[res.index].GetURI()).WithField("statusCode", res.code).WithError(res.err).Error("failed to publish block")
log.WithField("statusCode", res.code).WithError(res.err).Warn("failed to publish block")
lastErrPublishResp = res
continue
} else if res.code == 202 {
// Should the block fail full validation, a separate success response code (202) is used to indicate that the block was successfully broadcast but failed integration.
// https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/publishBlock
log.WithField("beacon", clients[res.index].GetURI()).WithField("statusCode", res.code).WithError(res.err).Error("block failed validation but was still broadcast")
log.WithField("statusCode", res.code).WithError(res.err).Error("block failed validation but was still broadcast")
lastErrPublishResp = res
continue
}

c.bestBeaconIndex.Store(int64(res.index))

log.WithField("beacon", clients[res.index].GetURI()).WithField("statusCode", res.code).Info("published block")
log.WithField("statusCode", res.code).Info("published block")
return res.code, nil
}

Expand Down
11 changes: 6 additions & 5 deletions services/housekeeper/housekeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Housekeeper struct {

headSlot uberatomic.Uint64

proposersAlreadySaved map[string]bool // to avoid repeating redis writes
proposersAlreadySaved map[uint64]string // to avoid repeating redis writes
}

var ErrServerAlreadyStarted = errors.New("server was already started")
Expand All @@ -56,7 +56,7 @@ func NewHousekeeper(opts *HousekeeperOpts) *Housekeeper {
redis: opts.Redis,
db: opts.DB,
beaconClient: opts.BeaconClient,
proposersAlreadySaved: make(map[string]bool),
proposersAlreadySaved: make(map[uint64]string),
}

return server
Expand Down Expand Up @@ -202,16 +202,17 @@ func (hk *Housekeeper) updateKnownValidators() {
hk.log.Debugf("writing to redis: %d / %d", i, numValidators)
}

// avoid resaving
if hk.proposersAlreadySaved[validator.Validator.Pubkey] {
// avoid resaving if index->pubkey mapping is the same
prevPubkeyForIndex := hk.proposersAlreadySaved[validator.Index]
if prevPubkeyForIndex == validator.Validator.Pubkey {
continue
}

err := hk.redis.SetKnownValidator(types.PubkeyHex(validator.Validator.Pubkey), validator.Index)
if err != nil {
log.WithError(err).WithField("pubkey", validator.Validator.Pubkey).Error("failed to set known validator in Redis")
} else {
hk.proposersAlreadySaved[validator.Validator.Pubkey] = true
hk.proposersAlreadySaved[validator.Index] = validator.Validator.Pubkey
newValidators++
}
}
Expand Down

0 comments on commit bf5f210

Please sign in to comment.