Skip to content

Commit

Permalink
Improved inactivity claim submission process
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed May 2, 2024
1 parent bd181a9 commit abad9ad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
10 changes: 6 additions & 4 deletions pkg/tbtc/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (ha *heartbeatAction) execute() error {
)
defer cancelHeartbeatCtx()

signature, activeOperatorsCount, _, err := ha.signingExecutor.sign(
signature, activeOperatorsCount, signingEndBlock, err := ha.signingExecutor.sign(
heartbeatCtx,
messageToSign,
ha.startBlock,
Expand Down Expand Up @@ -189,12 +189,14 @@ func (ha *heartbeatAction) execute() error {
// The value of consecutive heartbeat failures exceeds the threshold.
// Proceed with operator inactivity notification.
err = ha.inactivityClaimExecutor.publishClaim(
// Leave the list empty. Some operators were inactive during the
// heartbeat because they were simply unstaking and therefore should not
// be punished.
// Leave the list of inactive operators empty even if some operators
// were inactive during signing heartbeat. The inactive operators could
// simply be in the process of unstaking and therefore should not be
// punished.
[]group.MemberIndex{},
true,
messageToSign,
signingEndBlock,
)
if err != nil {
return fmt.Errorf(
Expand Down
6 changes: 5 additions & 1 deletion pkg/tbtc/inactivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const (
// by the given member to avoid all members submitting the same inactivity claim
// at the same time.
inactivityClaimSubmissionDelayStepBlocks = 3
// inactivityClaimMaximumSubmissionBlocks determines the maximum block
// duration of inactivity claim submission procedure.
inactivityClaimMaximumSubmissionBlocks = 60
)

// errInactivityClaimExecutorBusy is an error returned when the inactivity claim
Expand Down Expand Up @@ -70,6 +73,7 @@ func (ice *inactivityClaimExecutor) publishClaim(
inactiveMembersIndexes []group.MemberIndex,
heartbeatFailed bool,
message *big.Int,
startBlock uint64,
) error {
if lockAcquired := ice.lock.TryAcquire(1); !lockAcquired {
return errInactivityClaimExecutorBusy
Expand Down Expand Up @@ -121,7 +125,7 @@ func (ice *inactivityClaimExecutor) publishClaim(

defer wg.Done()

inactivityClaimTimeoutBlock := uint64(0) // TODO: Set the value of timeout block
inactivityClaimTimeoutBlock := startBlock + inactivityClaimMaximumSubmissionBlocks

go func(signer *signer) {
ctx, cancelCtx := withCancelOnBlock(
Expand Down
9 changes: 2 additions & 7 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-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/inactivity"
"github.com/keep-network/keep-core/pkg/tecdsa/signing"
)

Expand Down Expand Up @@ -493,13 +494,7 @@ func (n *node) getInactivityClaimExecutor(
return nil, false, fmt.Errorf("failed to get broadcast channel: [%v]", err)
}

// TODO: Handle unmarshallers

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

membershipValidator := group.NewMembershipValidator(
executorLogger,
Expand Down
9 changes: 9 additions & 0 deletions pkg/tecdsa/inactivity/inactivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ func Publish(

return nil
}

// RegisterUnmarshallers initializes the given broadcast channel to be able to
// perform inactivity claim interactions by registering all the required
// protocol message unmarshallers.
func RegisterUnmarshallers(channel net.BroadcastChannel) {
channel.SetUnmarshaler(func() net.TaggedUnmarshaler {
return &claimSignatureMessage{}
})
}

0 comments on commit abad9ad

Please sign in to comment.