Skip to content

Commit

Permalink
Merge pull request #3305 from keep-network/print-addresses
Browse files Browse the repository at this point in the history
Print addresses of operators selected to a signing group

To make the debugging of problems easier, we now print the addresses of
operators selected to ECDSA and Beacon signing groups.
  • Loading branch information
tomaszslabon authored Sep 26, 2022
2 parents 243ce9c + ae4d72d commit 33724c6
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/beacon/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type GroupSelectionInterface interface {
// SelectGroup returns the group members for the group generated by
// the given seed. This function can return an error if the beacon chain's
// state does not allow for group selection at the moment.
SelectGroup(seed *big.Int) ([]chain.Address, error)
SelectGroup(seed *big.Int) (chain.Addresses, error)
}

// GroupRegistrationInterface defines the subset of the beacon chain interface
Expand Down
2 changes: 2 additions & 0 deletions pkg/beacon/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (n *node) JoinDKGIfEligible(
return
}

logger.Infof("selected group members = %s", selectedOperators)

if len(selectedOperators) > n.beaconChain.GetConfig().GroupSize {
logger.Errorf(
"group size larger than supported: [%v]",
Expand Down
29 changes: 29 additions & 0 deletions pkg/chain/address.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package chain

import (
"fmt"
"strings"
)

// Address is a chain-agnostic representation of a chain address.
type Address string

Expand All @@ -20,3 +25,27 @@ func (a Addresses) Set() map[Address]bool {

return set
}

// String converts Addresses into a string with elements indexed from 1.
// This allows to print the list of addresses as a group members with member
// indexes starting from 1.
func (a Addresses) String() string {
if len(a) == 0 {
return "[]"
}

if len(a) == 1 {
return fmt.Sprintf("[1: %s]", a[0])
}

var sb strings.Builder
var i = 0

sb.WriteString("[")
for i = 0; i < len(a)-1; i++ {
fmt.Fprintf(&sb, "%d: %s, ", i+1, a[i].String())
}
fmt.Fprintf(&sb, "%d: %s]", i+1, a[i].String())

return sb.String()
}
43 changes: 43 additions & 0 deletions pkg/chain/address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package chain

import (
"testing"

"github.com/keep-network/keep-core/pkg/internal/testutils"
)

func TestAddressesToString(t *testing.T) {
var tests = map[string]struct {
addresses Addresses
expectedString string
}{
"empty addresses": {
addresses: Addresses{},
expectedString: "[]",
},
"one address": {
addresses: Addresses{"0x123"},
expectedString: "[1: 0x123]",
},
"two addresses": {
addresses: Addresses{"0x123", "0x234"},
expectedString: "[1: 0x123, 2: 0x234]",
},
"three addresses": {
addresses: Addresses{"0x123", "0x234", "0x345"},
expectedString: "[1: 0x123, 2: 0x234, 3: 0x345]",
},
}

for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
actualString := test.addresses.String()
testutils.AssertStringsEqual(
t,
"ToString() result",
test.expectedString,
actualString,
)
})
}
}
2 changes: 1 addition & 1 deletion pkg/chain/ethereum/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (bc *BeaconChain) RestoreRewardEligibility() error {
// SelectGroup returns the group members for the group generated by
// the given seed. This function can return an error if the beacon chain's
// state does not allow for group selection at the moment.
func (bc *BeaconChain) SelectGroup(seed *big.Int) ([]chain.Address, error) {
func (bc *BeaconChain) SelectGroup(seed *big.Int) (chain.Addresses, error) {
groupSize := big.NewInt(int64(bc.GetConfig().GroupSize))
seedBytes := [32]byte{}
seed.FillBytes(seedBytes[:])
Expand Down
4 changes: 2 additions & 2 deletions pkg/chain/ethereum/tbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (tc *TbtcChain) RestoreRewardEligibility() error {
// SelectGroup returns the group members for the group generated by
// the given seed. This function can return an error if the beacon chain's
// state does not allow for group selection at the moment.
func (tc *TbtcChain) SelectGroup(seed *big.Int) ([]chain.Address, error) {
func (tc *TbtcChain) SelectGroup(seed *big.Int) (chain.Addresses, error) {
groupSize := big.NewInt(int64(tc.GetConfig().GroupSize))
seedBytes := [32]byte{}
seed.FillBytes(seedBytes[:])
Expand Down Expand Up @@ -385,7 +385,7 @@ func (tc *TbtcChain) OnSignatureRequested(
}

// TODO: Temporary mock that simulates the behavior of the WalletRegistry
// contract. Should be removed eventually.
// contract. Should be removed eventually.
type mockWalletRegistry struct {
blockCounter chain.BlockCounter

Expand Down
2 changes: 1 addition & 1 deletion pkg/chain/local_v1/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *localChain) OnRelayEntryRequested(
})
}

func (c *localChain) SelectGroup(seed *big.Int) ([]chain.Address, error) {
func (c *localChain) SelectGroup(seed *big.Int) (chain.Addresses, error) {
panic("not implemented")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/tbtc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type GroupSelectionChain interface {
// SelectGroup returns the group members for the group generated by
// the given seed. This function can return an error if the TBTC chain's
// state does not allow for group selection at the moment.
SelectGroup(seed *big.Int) ([]chain.Address, error)
SelectGroup(seed *big.Int) (chain.Addresses, error)
}

// DistributedKeyGenerationChain defines the subset of the TBTC chain
Expand Down Expand Up @@ -101,7 +101,7 @@ type BridgeChain interface {
// SignatureRequestedEvent represents a Bridge signature request event.
//
// TODO: This is a temporary structure that should be removed once the client
// is integrated with real on-chain contracts.
// is integrated with real on-chain contracts.
type SignatureRequestedEvent struct {
WalletPublicKey []byte
Message *big.Int
Expand Down
2 changes: 2 additions & 0 deletions pkg/tbtc/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (n *node) joinDKGIfEligible(seed *big.Int, startBlockNumber uint64) {
return
}

logger.Infof("selected group members = %s", selectedSigningGroupOperators)

chainConfig := n.chain.GetConfig()

if len(selectedSigningGroupOperators) > chainConfig.GroupSize {
Expand Down

0 comments on commit 33724c6

Please sign in to comment.