-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c57105
commit ca9ba4e
Showing
14 changed files
with
768 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package tbtc | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"sync" | ||
|
||
"github.com/ipfs/go-log/v2" | ||
"github.com/keep-network/keep-core/pkg/generator" | ||
"github.com/keep-network/keep-core/pkg/net" | ||
"github.com/keep-network/keep-core/pkg/protocol/group" | ||
"github.com/keep-network/keep-core/pkg/tecdsa/inactivity" | ||
) | ||
|
||
type inactivityClaimExecutor struct { | ||
chain Chain | ||
signers []*signer | ||
|
||
protocolLatch *generator.ProtocolLatch | ||
} | ||
|
||
// TODO Consider moving all inactivity-related code to pkg/protocol/inactivity. | ||
func newInactivityClaimExecutor( | ||
chain Chain, | ||
signers []*signer, | ||
) *inactivityClaimExecutor { | ||
return &inactivityClaimExecutor{ | ||
chain: chain, | ||
signers: signers, | ||
} | ||
} | ||
|
||
func (ice *inactivityClaimExecutor) publishClaim( | ||
inactiveMembersIndexes []group.MemberIndex, | ||
heartbeatFailed bool, | ||
) error { | ||
// TODO: Build a claim and launch the publish function for all | ||
// the signers. The value of `heartbeat` should be true and | ||
// `inactiveMembersIndices` should be empty. | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(len(ice.signers)) | ||
|
||
for _, currentSigner := range ice.signers { | ||
ice.protocolLatch.Lock() | ||
defer ice.protocolLatch.Unlock() | ||
|
||
go func(signer *signer) { | ||
// TODO: Launch claim publishing for members. | ||
}(currentSigner) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (ice *inactivityClaimExecutor) publish( | ||
ctx context.Context, | ||
inactivityLogger log.StandardLogger, | ||
seed *big.Int, | ||
memberIndex group.MemberIndex, | ||
broadcastChannel net.BroadcastChannel, | ||
groupSize int, | ||
dishonestThreshold int, | ||
membershipValidator *group.MembershipValidator, | ||
inactivityClaim *inactivity.Claim, | ||
) error { | ||
return inactivity.Publish( | ||
ctx, | ||
inactivityLogger, | ||
seed.Text(16), | ||
memberIndex, | ||
broadcastChannel, | ||
groupSize, | ||
dishonestThreshold, | ||
membershipValidator, | ||
newInactivityClaimSigner(ice.chain), | ||
newInactivityClaimSubmitter(), | ||
inactivityClaim, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package tbtc | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/keep-network/keep-core/pkg/protocol/group" | ||
"github.com/keep-network/keep-core/pkg/tecdsa/inactivity" | ||
) | ||
|
||
// inactivityClaimSigner is responsible for signing the inactivity claim and | ||
// verification of signatures generated by other group members. | ||
type inactivityClaimSigner struct { | ||
chain Chain | ||
} | ||
|
||
func newInactivityClaimSigner( | ||
chain Chain, | ||
) *inactivityClaimSigner { | ||
return &inactivityClaimSigner{ | ||
chain: chain, | ||
} | ||
} | ||
|
||
func (ics *inactivityClaimSigner) SignClaim(claim *inactivity.Claim) ( | ||
*inactivity.SignedClaim, | ||
error, | ||
) { | ||
if claim == nil { | ||
return nil, fmt.Errorf("result is nil") | ||
} | ||
|
||
claimHash, err := ics.chain.CalculateInactivityClaimSignatureHash( | ||
claim.Nonce, | ||
claim.WalletPublicKey, | ||
claim.InactiveMembersIndexes, | ||
claim.HeartbeatFailed, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf( | ||
"inactivity claim hash calculation failed [%w]", | ||
err, | ||
) | ||
} | ||
|
||
signing := ics.chain.Signing() | ||
|
||
signature, err := signing.Sign(claimHash[:]) | ||
if err != nil { | ||
return nil, fmt.Errorf( | ||
"inactivity claim hash signing failed [%w]", | ||
err, | ||
) | ||
} | ||
|
||
return &inactivity.SignedClaim{ | ||
PublicKey: signing.PublicKey(), | ||
Signature: signature, | ||
ClaimHash: claimHash, | ||
}, nil | ||
} | ||
|
||
// VerifySignature verifies if the signature was generated from the provided | ||
// inactivity claim using the provided public key. | ||
func (ics *inactivityClaimSigner) VerifySignature( | ||
signedClaim *inactivity.SignedClaim, | ||
) ( | ||
bool, | ||
error, | ||
) { | ||
return ics.chain.Signing().VerifyWithPublicKey( | ||
signedClaim.ClaimHash[:], | ||
signedClaim.Signature, | ||
signedClaim.PublicKey, | ||
) | ||
} | ||
|
||
type inactivityClaimSubmitter struct { | ||
// TODO: Implement | ||
} | ||
|
||
func newInactivityClaimSubmitter() *inactivityClaimSubmitter { | ||
// TODO: Implement | ||
return &inactivityClaimSubmitter{} | ||
} | ||
|
||
func (ics *inactivityClaimSubmitter) SubmitClaim( | ||
ctx context.Context, | ||
memberIndex group.MemberIndex, | ||
claim *inactivity.Claim, | ||
signatures map[group.MemberIndex][]byte, | ||
) error { | ||
// TODO: Implement | ||
return nil | ||
} |
Oops, something went wrong.