Skip to content

Commit b199d39

Browse files
authored
Merge pull request #3303 from keep-network/chaosnet-client
Chaosnet support in the client After adding chaosnet support to the sortition pool, we need to modify the client to check the chaosnet state before attempting to join the sortition pool. BetaOperatorPolicy is a JoinPolicy implementation checking chaosnet and beta operator status. If chaosnet has been deactivated, the operator is allowed to join the pool. If chaosnet is active and the operator is beta operator, the operator is allowed to join the pool. If chaosnet is active and the operator is not beta operator, the operator is not allowed to join the pool. The BetaOperatorPolicy is applied both to the random beacon and tbtc.
2 parents 227dca6 + 61079ff commit b199d39

File tree

16 files changed

+3996
-83
lines changed

16 files changed

+3996
-83
lines changed

pkg/beacon/beacon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Initialize(
5151
logger,
5252
beaconChain,
5353
sortition.DefaultStatusCheckTick,
54-
sortition.UnconditionalJoinPolicy,
54+
sortition.NewBetaOperatorPolicy(beaconChain, logger),
5555
)
5656
if err != nil {
5757
return fmt.Errorf(

pkg/chain/ethereum/beacon.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ func (bc *BeaconChain) RestoreRewardEligibility() error {
230230
return err
231231
}
232232

233+
// Returns true if the chaosnet phase is active, false otherwise.
234+
func (bc *BeaconChain) IsChaosnetActive() (bool, error) {
235+
return bc.sortitionPool.IsChaosnetActive()
236+
}
237+
238+
// Returns true if operator is a beta operator, false otherwise.
239+
// Chaosnet status does not matter.
240+
func (bc *BeaconChain) IsBetaOperator() (bool, error) {
241+
return bc.sortitionPool.IsBetaOperator(bc.key.Address)
242+
}
243+
233244
// SelectGroup returns the group members for the group generated by
234245
// the given seed. This function can return an error if the beacon chain's
235246
// state does not allow for group selection at the moment.
@@ -281,17 +292,17 @@ func (bc *BeaconChain) IsStaleGroup(groupPublicKey []byte) (bool, error) {
281292
}
282293

283294
// TODO: Implement a real OnDKGStarted event subscription. The current
284-
// implementation generates a fake event every 500th block where the
285-
// seed is the keccak256 of the block number.
295+
// implementation generates a fake event every 500th block where the
296+
// seed is the keccak256 of the block number.
286297
func (bc *BeaconChain) OnDKGStarted(
287298
handler func(event *event.DKGStarted),
288299
) subscription.EventSubscription {
289300
return bc.mockRandomBeacon.OnDKGStarted(handler)
290301
}
291302

292303
// TODO: Implement a real SubmitDKGResult action. The current implementation
293-
// just creates and pipes the DKG submission event to the handlers
294-
// registered in the dkgResultSubmissionHandlers map.
304+
// just creates and pipes the DKG submission event to the handlers
305+
// registered in the dkgResultSubmissionHandlers map.
295306
func (bc *BeaconChain) SubmitDKGResult(
296307
participantIndex beaconchain.GroupMemberIndex,
297308
dkgResult *beaconchain.DKGResult,
@@ -305,9 +316,9 @@ func (bc *BeaconChain) SubmitDKGResult(
305316
}
306317

307318
// TODO: Implement a real OnDKGResultSubmitted event subscription. The current
308-
// implementation just pipes the DKG submission event generated within
309-
// SubmitDKGResult to the handlers registered in the
310-
// dkgResultSubmissionHandlers map.
319+
// implementation just pipes the DKG submission event generated within
320+
// SubmitDKGResult to the handlers registered in the
321+
// dkgResultSubmissionHandlers map.
311322
func (bc *BeaconChain) OnDKGResultSubmitted(
312323
handler func(event *event.DKGResultSubmission),
313324
) subscription.EventSubscription {
@@ -422,7 +433,7 @@ func (bc *BeaconChain) CurrentRequestGroupPublicKey() ([]byte, error) {
422433
}
423434

424435
// TODO: Temporary mock that simulates the behavior of the RandomBeacon
425-
// contract. Should be removed eventually.
436+
// contract. Should be removed eventually.
426437
type mockRandomBeacon struct {
427438
blockCounter chain.BlockCounter
428439

pkg/chain/ethereum/beacon/gen/abi/BeaconSortitionPool.go

Lines changed: 559 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/chain/ethereum/beacon/gen/cmd/BeaconSortitionPool.go

Lines changed: 225 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)