Compare commits

...

1 Commits

Author SHA1 Message Date
prestonvanloon
9de96e8716 Add development lock to SetupTestConfigCleanup 2022-05-11 13:22:44 -05:00
5 changed files with 36 additions and 7 deletions

View File

@@ -114,7 +114,7 @@ func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, e
}
if blockRoots[length-1] != endBlockRoot {
return nil, errors.New("end block roots don't match")
return nil, errors.Errorf("end block roots don't match: got %#x but wanted %#x for %d to %d at length %d", blockRoots[length-1], endBlockRoot, startSlot, endSlot, length)
}
filteredBlocks := []interfaces.SignedBeaconBlock{blocks[length-1]}

View File

@@ -1,3 +1,6 @@
//go:build develop
// +build develop
package params
import "testing"
@@ -9,6 +12,8 @@ func SetupTestConfigCleanup(t testing.TB) {
prevBeaconConfig := beaconConfig.Copy()
prevNetworkCfg := networkConfig.Copy()
t.Cleanup(func() {
beaconConfigLock.Lock()
defer beaconConfigLock.Unlock()
mainnetBeaconConfig = prevDefaultBeaconConfig
beaconConfig = prevBeaconConfig
networkConfig = prevNetworkCfg

View File

@@ -7,7 +7,6 @@ import (
"time"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/async"
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params"
@@ -21,7 +20,6 @@ import (
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/runtime/version"
prysmTime "github.com/prysmaticlabs/prysm/time"
"github.com/prysmaticlabs/prysm/validator/client/iface"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
"google.golang.org/protobuf/types/known/emptypb"
@@ -46,10 +44,6 @@ func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [f
ctx, span := trace.StartSpan(ctx, "validator.ProposeBlock")
defer span.End()
lock := async.NewMultilock(fmt.Sprint(iface.RoleProposer), string(pubKey[:]))
lock.Lock()
defer lock.Unlock()
fmtKey := fmt.Sprintf("%#x", pubKey[:])
span.AddAttributes(trace.StringAttribute("validator", fmtKey))
log := log.WithField("pubKey", fmt.Sprintf("%#x", bytesutil.Trunc(pubKey[:])))
@@ -131,6 +125,34 @@ func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [f
}
return
}
hasProposerNextSlot := false
hasProposerPrevSlot := false
hasProposerPrevPrevSlot := false
for _, d := range v.duties.Duties {
if slot < 6 {
continue
}
if len(d.ProposerSlots) > 0 && d.ProposerSlots[0] == slot+1 {
hasProposerNextSlot = true
}
if len(d.ProposerSlots) > 0 && d.ProposerSlots[0] == slot-1 {
hasProposerPrevSlot = true
}
if len(d.ProposerSlots) > 0 && d.ProposerSlots[0] == slot-2 {
hasProposerPrevPrevSlot = true
}
}
if hasProposerNextSlot && !hasProposerPrevSlot {
log.Infof("waiting for slot %d", slot+1)
<-v.propChan
log.Infof("received from slot %d", slot+1)
}
if hasProposerPrevSlot && !hasProposerPrevPrevSlot {
log.Infof("sending to slot %d", slot-1)
v.propChan <- true
log.Infof("sent to slot %d", slot-1)
}
ctx = context.Background()
blkResp, err := v.validatorClient.ProposeBeaconBlock(ctx, proposal)
if err != nil {
log.WithError(err).Error("Failed to propose block")

View File

@@ -208,6 +208,7 @@ func (v *ValidatorService) Start() {
Web3SignerConfig: v.Web3SignerConfig,
feeRecipientConfig: v.feeRecipientConfig,
walletIntializedChannel: make(chan *wallet.Wallet, 1),
propChan: make(chan bool, 1),
}
// To resolve a race condition at startup due to the interface
// nature of the abstracted block type. We initialize

View File

@@ -81,6 +81,7 @@ type validator struct {
domainDataCache *ristretto.Cache
highestValidSlot types.Slot
genesisTime uint64
propChan chan bool
blockFeed *event.Feed
interopKeysConfig *local.InteropKeymanagerConfig
wallet *wallet.Wallet