Skip to content

Commit

Permalink
Set unmarshallers early during signing (#3700)
Browse files Browse the repository at this point in the history
#Refs #3611.
This PR handles problems with unmarshallers not found errors during
signing:
```
eep-libp2p	libp2p/channel.go:286	couldn't find unmarshaler for type [protocol_announcer/announcement_message]
keep-libp2p	libp2p/channel.go:286	couldn't find unmarshaler for type [tbtc/signing_done_message]
```
The solution is is to register the marshaller for those messages early,
before the signing process begins.
  • Loading branch information
dimpar authored Sep 7, 2023
2 parents eec2e6a + b6d65d9 commit 7157a33
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
12 changes: 8 additions & 4 deletions pkg/protocol/announcer/announcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ type Announcer struct {
membershipValidator *group.MembershipValidator
}

// RegisterUnmarshaller initializes the given broadcast channel to be able to
// handle announcement messages by registering the required unmarshaller.
func RegisterUnmarshaller(channel net.BroadcastChannel) {
channel.SetUnmarshaler(func() net.TaggedUnmarshaler {
return &announcementMessage{}
})
}

// New creates a new instance of the Announcer. It expects a unique protocol
// identifier, a broadcast channel configured to mediate between group members,
// and a membership validator configured to validate the group membership of
Expand All @@ -80,10 +88,6 @@ func New(
broadcastChannel net.BroadcastChannel,
membershipValidator *group.MembershipValidator,
) *Announcer {
broadcastChannel.SetUnmarshaler(func() net.TaggedUnmarshaler {
return &announcementMessage{}
})

return &Announcer{
protocolID: protocolID,
broadcastChannel: broadcastChannel,
Expand Down
2 changes: 2 additions & 0 deletions pkg/protocol/announcer/announcer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func TestAnnouncer(t *testing.T) {
localChain.Signing(),
)

RegisterUnmarshaller(broadcastChannel)

announcer := New(
protocolID,
broadcastChannel,
Expand Down
15 changes: 8 additions & 7 deletions pkg/tbtc/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (de *dkgExecutor) preParamsCount() int {
// the result to the chain. The execution can be delayed by an arbitrary number
// of blocks using the delayBlocks argument. This allows confirming the state
// on-chain - e.g. wait for the required number of confirming blocks - before
//executing the off-chain action.
// executing the off-chain action.
func (de *dkgExecutor) executeDkgIfEligible(
seed *big.Int,
startBlock uint64,
Expand Down Expand Up @@ -162,12 +162,12 @@ func (de *dkgExecutor) executeDkgIfEligible(

// checkEligibility performs on-chain group selection and returns two pieces
// of information:
// - Indexes of members selected to the signing group and controlled by this
// operator. The indexes are in range [1, `groupSize`]. The slice is nil if
// none of the selected signing group members is controlled by this operator.
// - Group selection result holding chain.OperatorID and chain.Address for
// operators selected to the signing group. There are always `groupSize`
// selected operators.
// - Indexes of members selected to the signing group and controlled by this
// operator. The indexes are in range [1, `groupSize`]. The slice is nil if
// none of the selected signing group members is controlled by this operator.
// - Group selection result holding chain.OperatorID and chain.Address for
// operators selected to the signing group. There are always `groupSize`
// selected operators.
func (de *dkgExecutor) checkEligibility(
dkgLogger log.StandardLogger,
) ([]uint8, *GroupSelectionResult, error) {
Expand Down Expand Up @@ -218,6 +218,7 @@ func (de *dkgExecutor) setupBroadcastChannel(
}

dkg.RegisterUnmarshallers(broadcastChannel)
announcer.RegisterUnmarshaller(broadcastChannel)

err = broadcastChannel.SetFilter(membershipValidator.IsInGroup)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/tbtc/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/keep-network/keep-common/pkg/persistence"
"github.com/keep-network/keep-core/pkg/generator"
"github.com/keep-network/keep-core/pkg/net"
"github.com/keep-network/keep-core/pkg/protocol/announcer"
"github.com/keep-network/keep-core/pkg/protocol/group"
"github.com/keep-network/keep-core/pkg/tecdsa/signing"
)
Expand Down Expand Up @@ -241,6 +242,10 @@ func (n *node) getSigningExecutor(
}

signing.RegisterUnmarshallers(broadcastChannel)
announcer.RegisterUnmarshaller(broadcastChannel)
broadcastChannel.SetUnmarshaler(func() net.TaggedUnmarshaler {
return &signingDoneMessage{}
})

membershipValidator := group.NewMembershipValidator(
executorLogger,
Expand Down
4 changes: 0 additions & 4 deletions pkg/tbtc/signing_done.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ func newSigningDoneCheck(
broadcastChannel net.BroadcastChannel,
membershipValidator *group.MembershipValidator,
) *signingDoneCheck {
broadcastChannel.SetUnmarshaler(func() net.TaggedUnmarshaler {
return &signingDoneMessage{}
})

return &signingDoneCheck{
groupSize: groupSize,
broadcastChannel: broadcastChannel,
Expand Down
5 changes: 5 additions & 0 deletions pkg/tbtc/signing_done_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/keep-network/keep-core/internal/testutils"
"github.com/keep-network/keep-core/pkg/chain"
"github.com/keep-network/keep-core/pkg/chain/local_v1"
"github.com/keep-network/keep-core/pkg/net"
"github.com/keep-network/keep-core/pkg/net/local"
"github.com/keep-network/keep-core/pkg/operator"
"github.com/keep-network/keep-core/pkg/protocol/group"
Expand Down Expand Up @@ -326,6 +327,10 @@ func setupSigningDoneCheck(
t.Fatal(err)
}

broadcastChannel.SetUnmarshaler(func() net.TaggedUnmarshaler {
return &signingDoneMessage{}
})

membershipValidator := group.NewMembershipValidator(
&testutils.MockLogger{},
operators,
Expand Down

0 comments on commit 7157a33

Please sign in to comment.