Skip to content

Commit

Permalink
Implemented inactivity claim submitter
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Apr 24, 2024
1 parent 17df0d8 commit a2923f1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
8 changes: 6 additions & 2 deletions pkg/tbtc/inactivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type inactivityClaimExecutor struct {
broadcastChannel net.BroadcastChannel
membershipValidator *group.MembershipValidator
groupParameters *GroupParameters
protocolLatch *generator.ProtocolLatch
protocolLatch *generator.ProtocolLatch

waitForBlockFn waitForBlockFn
}
Expand Down Expand Up @@ -159,7 +159,11 @@ func (ice *inactivityClaimExecutor) publish(
dishonestThreshold,
membershipValidator,
newInactivityClaimSigner(ice.chain),
newInactivityClaimSubmitter(),
newInactivityClaimSubmitter(
inactivityLogger,
ice.chain,
ice.groupParameters,
),
inactivityClaim,
)
}
Expand Down
55 changes: 50 additions & 5 deletions pkg/tbtc/inactivity_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/ipfs/go-log/v2"
"github.com/keep-network/keep-core/pkg/bitcoin"
"github.com/keep-network/keep-core/pkg/protocol/group"
"github.com/keep-network/keep-core/pkg/tecdsa/inactivity"
)
Expand Down Expand Up @@ -71,12 +73,22 @@ func (ics *inactivityClaimSigner) VerifySignature(
}

type inactivityClaimSubmitter struct {
// TODO: Implement
inactivityLogger log.StandardLogger

chain Chain
groupParameters *GroupParameters
}

func newInactivityClaimSubmitter() *inactivityClaimSubmitter {
// TODO: Implement
return &inactivityClaimSubmitter{}
func newInactivityClaimSubmitter(
inactivityLogger log.StandardLogger,
chain Chain,
groupParameters *GroupParameters,
) *inactivityClaimSubmitter {
return &inactivityClaimSubmitter{
inactivityLogger: inactivityLogger,
chain: chain,
groupParameters: groupParameters,
}
}

func (ics *inactivityClaimSubmitter) SubmitClaim(
Expand All @@ -85,6 +97,39 @@ func (ics *inactivityClaimSubmitter) SubmitClaim(
claim *inactivity.Claim,
signatures map[group.MemberIndex][]byte,
) error {
// TODO: Implement
if len(signatures) < ics.groupParameters.HonestThreshold {
return fmt.Errorf(
"could not submit inactivity claim with [%v] signatures for "+
"group honest threshold [%v]",
len(signatures),
ics.groupParameters.HonestThreshold,
)
}

walletPublicKeyHash := bitcoin.PublicKeyHash(claim.WalletPublicKey)

walletRegistryData, err := ics.chain.GetWallet(walletPublicKeyHash)
if err != nil {
return fmt.Errorf("could not get registry data on wallet: [%v]", err)
}

currentNonce, err := ics.chain.GetInactivityClaimNonce(
walletRegistryData.EcdsaWalletID,
)
if err != nil {
return fmt.Errorf("could not get nonce for wallet: [%v]", err)
}

if currentNonce.Cmp(claim.Nonce) > 0 {
// Someone who was ahead of us in the queue submitted the claim. Giving up.
ics.inactivityLogger.Infof(
"[member:%v] inactivity claim already submitted; "+
"aborting inactivity claim on-chain submission",
memberIndex,
)
return nil
}

// TODO: Continue with the implementation
return nil
}

0 comments on commit a2923f1

Please sign in to comment.