Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

"github.com/keep-network/keep-core/pkg/chain/ethereum"
"github.com/keep-network/keep-core/pkg/chain/ethereum_v1"
"github.com/keep-network/keep-core/pkg/operator"

Expand Down Expand Up @@ -92,17 +93,22 @@ func Start(c *cli.Context) error {
return err
}

chainProvider, err := ethereum_v1.Connect(ctx, config.Ethereum)
beaconChain, _, err := ethereum.Connect(ctx, config.Ethereum)
if err != nil {
return fmt.Errorf("error connecting to Ethereum node: [%v]", err)
}

blockCounter, err := chainProvider.BlockCounter()
chainProviderV1, err := ethereum_v1.Connect(ctx, config.Ethereum)
if err != nil {
return fmt.Errorf("error connecting to Ethereum node: [%v]", err)
}

blockCounter, err := chainProviderV1.BlockCounter()
if err != nil {
return err
}

stakeMonitor, err := chainProvider.StakeMonitor()
stakeMonitor, err := chainProviderV1.StakeMonitor()
if err != nil {
return fmt.Errorf("error obtaining stake monitor handle [%v]", err)
}
Expand Down Expand Up @@ -154,8 +160,10 @@ func Start(c *cli.Context) error {
)

err = beacon.Initialize(
ctx,
operatorPublicKey,
chainProvider.ThresholdRelay(),
chainProviderV1.ThresholdRelay(),
beaconChain,
netProvider,
persistence,
)
Expand All @@ -164,7 +172,7 @@ func Start(c *cli.Context) error {
}

initializeMetrics(ctx, config, netProvider, stakeMonitor, operatorPublicKey)
initializeDiagnostics(ctx, config, netProvider, chainProvider.Signing())
initializeDiagnostics(ctx, config, netProvider, chainProviderV1.Signing())

select {
case <-ctx.Done():
Expand Down
10 changes: 4 additions & 6 deletions configs/config.toml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@
KeyFile = "/Users/someuser/ethereum/data/keystore/UTC--2018-03-11T01-37-33.202765887Z--AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAA"

[ethereum.ContractAddresses]
# Hex-encoded address of KeepRandomBeaconOperator contract
KeepRandomBeaconOperator = "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
# Hex-encoded address of TokenStaking contract
RandomBeacon = "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"

# Legacy v1 contracts, do not have to be set. Soon to be removed.
KeepRandomBeaconOperator = "0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
TokenStaking = "0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
# Hex-encoded address of KeepRandomBeaconService contract. Only needed
# in cases where the client's utility functions will be used (e.g., the
# relay subcommand).
KeepRandomBeaconService = "0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"

[LibP2P]
Expand Down
39 changes: 25 additions & 14 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package beacon

import (
"context"
"encoding/hex"
"fmt"
"time"

"github.com/keep-network/keep-core/pkg/operator"
"github.com/keep-network/keep-core/pkg/sortition"

"github.com/ipfs/go-log"

Expand All @@ -23,21 +25,25 @@ var logger = log.Logger("keep-beacon")
// internal random beacon implementation. Returns an error if this failed,
// otherwise enters a blocked loop.
func Initialize(
ctx context.Context,
operatorPublicKey *operator.PublicKey,
beaconChain beaconchain.Interface,
// TODO: Get rid of legacy Ethereum chain
beaconChainV1 beaconchain.Interface,
// TODO: Accept a generic interface, not just sortition.Chain
beaconChain sortition.Chain,
netProvider net.Provider,
persistence persistence.Handle,
) error {
chainConfig := beaconChain.GetConfig()
chainConfig := beaconChainV1.GetConfig()

blockCounter, err := beaconChain.BlockCounter()
blockCounter, err := beaconChainV1.BlockCounter()
if err != nil {
return fmt.Errorf("failed to get block counter instance: [%v]", err)
}

signing := beaconChain.Signing()
signing := beaconChainV1.Signing()

groupRegistry := registry.NewGroupRegistry(beaconChain, persistence)
groupRegistry := registry.NewGroupRegistry(beaconChainV1, persistence)
groupRegistry.LoadExistingGroups()

node := newNode(
Expand All @@ -48,11 +54,16 @@ func Initialize(
groupRegistry,
)

eventDeduplicator := event.NewDeduplicator(beaconChain)
err = sortition.MonitorPool(ctx, beaconChain, sortition.DefaultStatusCheckTick)
if err != nil {
return fmt.Errorf("could not set up sortition pool monitoring: [%v]", err)
}

eventDeduplicator := event.NewDeduplicator(beaconChainV1)

node.ResumeSigningIfEligible(beaconChain, signing)
node.ResumeSigningIfEligible(beaconChainV1, signing)

_ = beaconChain.OnRelayEntryRequested(func(request *event.Request) {
_ = beaconChainV1.OnRelayEntryRequested(func(request *event.Request) {
onConfirmed := func() {
if node.IsInGroup(request.GroupPublicKey) {
go func() {
Expand Down Expand Up @@ -93,7 +104,7 @@ func Initialize(

node.GenerateRelayEntry(
request.PreviousEntry,
beaconChain,
beaconChainV1,
signing,
request.GroupPublicKey,
request.BlockNumber,
Expand All @@ -104,7 +115,7 @@ func Initialize(
}

go node.MonitorRelayEntry(
beaconChain,
beaconChainV1,
request.BlockNumber,
chainConfig,
)
Expand All @@ -115,14 +126,14 @@ func Initialize(

confirmCurrentRelayRequest(
request.BlockNumber,
beaconChain,
beaconChainV1,
onConfirmed,
currentRelayRequestConfirmationRetries,
currentRelayRequestConfirmationDelay,
)
})

_ = beaconChain.OnDKGStarted(func(event *event.DKGStarted) {
_ = beaconChainV1.OnDKGStarted(func(event *event.DKGStarted) {
go func() {
if ok := eventDeduplicator.NotifyDKGStarted(
event.Seed,
Expand All @@ -143,15 +154,15 @@ func Initialize(
)

node.JoinDKGIfEligible(
beaconChain,
beaconChainV1,
signing,
event.Seed,
event.BlockNumber,
)
}()
})

_ = beaconChain.OnGroupRegistered(func(registration *event.GroupRegistration) {
_ = beaconChainV1.OnGroupRegistered(func(registration *event.GroupRegistration) {
logger.Infof(
"new group with public key [0x%x] registered on-chain at block [%v]",
registration.GroupPublicKey,
Expand Down
156 changes: 0 additions & 156 deletions pkg/sortition/internal/local.go

This file was deleted.

Loading