Skip to content

Commit

Permalink
added sync backoff flag (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirylm committed Dec 13, 2021
1 parent 8551d17 commit 21dfae5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ibft/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/semaphore"
"sync"
"time"

"github.com/bloxapp/ssv/beacon"
"github.com/bloxapp/ssv/ibft/proto"
Expand Down Expand Up @@ -42,6 +43,8 @@ type Controller struct {
// locks
currentInstanceLock sync.Locker
syncingLock *semaphore.Weighted

syncBackoff time.Duration
}

// New is the constructor of Controller
Expand All @@ -56,6 +59,7 @@ func New(
ValidatorShare *storage.Share,
fork contollerforks.Fork,
signer beacon.Signer,
syncBackoff time.Duration,
) ibft.Controller {
logger = logger.With(zap.String("role", role.String()))
ret := &Controller{
Expand All @@ -75,6 +79,8 @@ func New(
// locks
currentInstanceLock: &sync.Mutex{},
syncingLock: semaphore.NewWeighted(1),

syncBackoff: syncBackoff,
}

ret.setFork(fork)
Expand Down
2 changes: 1 addition & 1 deletion ibft/controller/controller_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (i *Controller) processSyncQueueMessages() {
Stream: syncMsg.Stream,
})
}
time.Sleep(time.Millisecond * 100)
time.Sleep(i.syncBackoff)
}
}()
i.logger.Info("sync messages queue started")
Expand Down
3 changes: 2 additions & 1 deletion ibft/controller/controller_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func populatedIbft(
proto.DefaultConsensusParams(),
share,
nil,
signer)
signer,
100*time.Millisecond)
ret.(*Controller).setFork(testFork(ret.(*Controller)))
ret.(*Controller).initHandlers.Set(true) // as if they are already synced
ret.(*Controller).initSynced.Set(true) // as if they are already synced
Expand Down
1 change: 1 addition & 0 deletions ibft/simulation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func main() {
shares[i],
v0.New(),
signer,
time.Millisecond*200,
)
nodes = append(nodes, node)
}
Expand Down
2 changes: 2 additions & 0 deletions validator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ControllerOptions struct {
Logger *zap.Logger
SignatureCollectionTimeout time.Duration `yaml:"SignatureCollectionTimeout" env:"SIGNATURE_COLLECTION_TIMEOUT" env-default:"5s" env-description:"Timeout for signature collection after consensus"`
MetadataUpdateInterval time.Duration `yaml:"MetadataUpdateInterval" env:"METADATA_UPDATE_INTERVAL" env-default:"12m" env-description:"Interval for updating metadata"`
HistorySyncBackoff time.Duration `yaml:"HistorySyncBackoff" env:"HISTORY_SYNC_BACKOFF" env-default:"200ms" env-description:"Interval for updating metadata"`
ETHNetwork *core.Network
Network network.Network
Beacon beacon.Beacon
Expand Down Expand Up @@ -94,6 +95,7 @@ func NewController(options ControllerOptions) Controller {
DB: options.DB,
Fork: options.Fork,
Signer: options.KeyManager,
SyncBackoff: options.HistorySyncBackoff,
}),

metadataUpdateQueue: tasks.NewExecutionQueue(10 * time.Millisecond),
Expand Down
7 changes: 5 additions & 2 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Options struct {
DB basedb.IDb
Fork forks.Fork
Signer beacon.Signer
SyncBackoff time.Duration
}

// Validator struct that manages all ibft wrappers
Expand All @@ -63,7 +64,7 @@ func New(opt Options) *Validator {

msgQueue := msgqueue.New()
ibfts := make(map[beacon.RoleType]ibft.Controller)
ibfts[beacon.RoleTypeAttester] = setupIbftController(beacon.RoleTypeAttester, logger, opt.DB, opt.Network, msgQueue, opt.Share, opt.Fork, opt.Signer)
ibfts[beacon.RoleTypeAttester] = setupIbftController(beacon.RoleTypeAttester, logger, opt.DB, opt.Network, msgQueue, opt.Share, opt.Fork, opt.Signer, opt.SyncBackoff)
//ibfts[beacon.RoleAggregator] = setupIbftController(beacon.RoleAggregator, logger, db, opt.Network, msgQueue, opt.Share) TODO not supported for now
//ibfts[beacon.RoleProposer] = setupIbftController(beacon.RoleProposer, logger, db, opt.Network, msgQueue, opt.Share) TODO not supported for now

Expand Down Expand Up @@ -152,6 +153,7 @@ func setupIbftController(
share *storage.Share,
fork forks.Fork,
signer beacon.Signer,
syncBackoff time.Duration,
) ibft.Controller {
ibftStorage := collections.NewIbft(db, logger, role.String())
identifier := []byte(format.IdentifierFormat(share.PublicKey.Serialize(), role.String()))
Expand All @@ -165,7 +167,8 @@ func setupIbftController(
proto.DefaultConsensusParams(),
share,
fork.NewIBFTControllerFork(),
signer)
signer,
syncBackoff)
}

// oneOfIBFTIdentifiers will return true if provided identifier matches one of the iBFT instances.
Expand Down

0 comments on commit 21dfae5

Please sign in to comment.