Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0bc5fa4
Expose Ethereum Chain implementation
nkuba Jun 17, 2022
d982bc9
Expose properties of ethereum chain handle
nkuba Jun 17, 2022
04f8647
Update legacy comment
nkuba Jun 17, 2022
dd64f26
Chain handle for Random Beacon's Sortition Pool
nkuba Jun 17, 2022
69fcec0
Fix block counter assignment
nkuba Jun 17, 2022
5663c57
Define chain handle interface for sortition pools
nkuba Jun 23, 2022
5942634
Implement sortition pool's functions for beacon
nkuba Jun 23, 2022
499eeb3
Disable legacy V1 chain config code
nkuba Jun 23, 2022
ac63879
Disable legacy stake monitoring
nkuba Jun 23, 2022
ca98c08
Register operator in the sortition pool
nkuba Jun 23, 2022
cf474f0
Register sortition pool registration for client start
nkuba Jun 23, 2022
d31e60a
Move sortition code to pkg/sortition
nkuba Jun 29, 2022
cdb3d50
Fix typo
nkuba Jun 29, 2022
11a11da
Add todo to check if sortition pool is unlocked
nkuba Jun 29, 2022
a54b292
Unit test waitUntilRegistered function
nkuba Jun 29, 2022
1c3fed3
Reorder functions
nkuba Jun 29, 2022
7b9f648
Register in a separate goroutine
nkuba Jun 29, 2022
4b35103
Add unit tests for joinSortitionPoolWhenEligible
nkuba Jun 29, 2022
6ff3779
Add unit tests for waitUntilJoined
nkuba Jun 29, 2022
a2850e3
Rename chain handle argument
nkuba Jun 29, 2022
242a8f1
Check if pool is locked when joining
nkuba Jun 29, 2022
476b87e
Improve log messages to include retry delay
nkuba Jun 29, 2022
4997b6e
Include locked pool case in test
nkuba Jun 29, 2022
d81b89e
Print logs in tests
nkuba Jun 29, 2022
0894f40
Add unit tests for RegisterAndMonitorStatus
nkuba Jun 29, 2022
6c0ec08
Local implementation of isPoolLocked
nkuba Jun 29, 2022
f21af30
Add more time before test verification
nkuba Jun 29, 2022
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
49 changes: 29 additions & 20 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/keep-network/keep-core/pkg/net/retransmission"
"github.com/keep-network/keep-core/pkg/operator"
"github.com/urfave/cli"

beaconChain "github.com/keep-network/keep-core/pkg/chain/random-beacon"
)

// StartCommand contains the definition of the start command-line subcommand.
Expand Down Expand Up @@ -90,6 +92,11 @@ func Start(c *cli.Context) error {
return fmt.Errorf("error connecting to Ethereum node: [%v]", err)
}

beaconChainHandle, err := beaconChain.Connect(chainProvider)
if err != nil {
return fmt.Errorf("error initializing ethereum chain handle for Beacon: [%w]", err)
}

blockCounter, err := chainProvider.BlockCounter()
if err != nil {
return err
Expand All @@ -99,26 +106,27 @@ func Start(c *cli.Context) error {
if err != nil {
return fmt.Errorf("error obtaining stake monitor handle [%v]", err)
}
if c.Int(waitForStakeFlag) != 0 {
err = waitForStake(stakeMonitor, ethereumKey.Address.Hex(), c.Int(waitForStakeFlag))
if err != nil {
return err
}
}
hasMinimumStake, err := stakeMonitor.HasMinimumStake(
ethereumKey.Address.Hex(),
)
if err != nil {
return fmt.Errorf("could not check the stake [%v]", err)
}
if !hasMinimumStake {
return fmt.Errorf(
"no minimum KEEP stake or operator is not authorized to use it; " +
"please make sure the operator address in the configuration " +
"is correct and it has KEEP tokens delegated and the operator " +
"contract has been authorized to operate on the stake",
)
}
// FIXME: Update for V2
// if c.Int(waitForStakeFlag) != 0 {
// err = waitForStake(stakeMonitor, ethereumKey.Address.Hex(), c.Int(waitForStakeFlag))
// if err != nil {
// return err
// }
// }
// hasMinimumStake, err := stakeMonitor.HasMinimumStake(
// ethereumKey.Address.Hex(),
// )
// if err != nil {
// return fmt.Errorf("could not check the stake [%v]", err)
// }
// if !hasMinimumStake {
// return fmt.Errorf(
// "no minimum KEEP stake or operator is not authorized to use it; " +
// "please make sure the operator address in the configuration " +
// "is correct and it has KEEP tokens delegated and the operator " +
// "contract has been authorized to operate on the stake",
// )
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove it. It is hard to say what we should wait for here - stake, authorization, or maybe staking provider<>operator mapping?


networkPrivateKey, _ := key.OperatorKeyToNetworkKey(
operator.ChainKeyToOperatorKey(ethereumKey),
Expand Down Expand Up @@ -152,6 +160,7 @@ func Start(c *cli.Context) error {
chainProvider,
netProvider,
persistence,
beaconChainHandle,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing it as a separate parameter, I would replace ThresholdRelay() in chain.Handle with this interface. In case it is too complicated to replace ThresholdRelay() now, I would introduce it next to ThresholdRelay() and deprecated ThresholdRelay() use.

)
if err != nil {
return fmt.Errorf("error initializing beacon: [%v]", err)
Expand Down
5 changes: 5 additions & 0 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
"github.com/keep-network/keep-core/pkg/beacon/relay/groupselection"
"github.com/keep-network/keep-core/pkg/beacon/relay/registry"
"github.com/keep-network/keep-core/pkg/chain"
beaconChain "github.com/keep-network/keep-core/pkg/chain/random-beacon"
"github.com/keep-network/keep-core/pkg/net"
"github.com/keep-network/keep-core/pkg/sortition"
)

var logger = log.Logger("keep-beacon")
Expand All @@ -31,6 +33,7 @@ func Initialize(
chainHandle chain.Handle,
netProvider net.Provider,
persistence persistence.Handle,
beaconChainHandle beaconChain.Handle,
) error {
relayChain := chainHandle.ThresholdRelay()
chainConfig := relayChain.GetConfig()
Expand Down Expand Up @@ -209,6 +212,8 @@ func Initialize(
go groupRegistry.UnregisterStaleGroups(registration.GroupPublicKey)
})

go sortition.RegisterAndMonitorStatus(ctx, blockCounter, beaconChainHandle)

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/chain/ethereum/_LEGACY_V1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This directory contains legacy code from V1. It should be removed.
This directory contains legacy code from V1. It should be moved to fit the new directories structure.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would clear up this directory and remove everything that is not needed for v2, assuming there is a way to make the compilation pass.

14 changes: 7 additions & 7 deletions pkg/chain/ethereum/balance_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ const defaultBalanceMonitoringTick = 10 * time.Minute
const defaultBalanceMonitoringRetryTimeout = 5 * time.Minute

// initializeBalanceMonitoring sets up the balance monitoring process
func (ec *ethereumChain) initializeBalanceMonitoring(ctx context.Context) {
balanceMonitor, err := ec.balanceMonitor()
func (c *Chain) initializeBalanceMonitoring(ctx context.Context) {
balanceMonitor, err := c.balanceMonitor()
if err != nil {
logger.Errorf("could not get balance monitor [%v]", err)
return
}

alertThreshold := defaultBalanceAlertThreshold
if value := ec.config.BalanceAlertThreshold; value != nil {
if value := c.config.BalanceAlertThreshold; value != nil {
alertThreshold = value
}

balanceMonitor.Observe(
ctx,
ec.Address(),
c.Address(),
alertThreshold,
defaultBalanceMonitoringTick,
defaultBalanceMonitoringRetryTimeout,
Expand All @@ -49,13 +49,13 @@ func (ec *ethereumChain) initializeBalanceMonitoring(ctx context.Context) {
logger.Infof(
"started balance monitoring for address [%v] "+
"with the alert threshold set to [%v] wei",
ec.Address().Hex(),
c.Address().Hex(),
alertThreshold,
)
}

// balanceMonitor returns a balance monitor.
func (ec *ethereumChain) balanceMonitor() (*ethutil.BalanceMonitor, error) {
func (c *Chain) balanceMonitor() (*ethutil.BalanceMonitor, error) {
weiBalanceOf := func(
address common.Address,
) (*ethereum.Wei, error) {
Expand All @@ -65,7 +65,7 @@ func (ec *ethereumChain) balanceMonitor() (*ethutil.BalanceMonitor, error) {
)
defer cancelCtx()

balance, err := ec.client.BalanceAt(ctx, address, nil)
balance, err := c.client.BalanceAt(ctx, address, nil)
if err != nil {
return nil, err
}
Expand Down
Loading