|
1 | 1 | package epochkghandler
|
2 | 2 |
|
3 |
| -// import ( |
4 |
| -// "context" |
5 |
| -// "testing" |
6 |
| - |
7 |
| -// pubsub "github.com/libp2p/go-libp2p-pubsub" |
8 |
| -// "gotest.tools/assert" |
9 |
| - |
10 |
| -// "github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database" |
11 |
| -// "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/identitypreimage" |
12 |
| -// "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/testsetup" |
13 |
| -// "github.com/shutter-network/rolling-shutter/rolling-shutter/p2pmsg" |
14 |
| -// ) |
15 |
| - |
16 |
| -// func BenchmarkDecryptionKeySharesValidationIntegration(b *testing.B) { |
17 |
| -// ctx := context.Background() |
18 |
| - |
19 |
| -// dbpool, dbclose := testsetup.NewTestDBPool(ctx, b, database.Definition) |
20 |
| -// b.Cleanup(dbclose) |
21 |
| - |
22 |
| -// identityPreimages := []identitypreimage.IdentityPreimage{} |
23 |
| -// for i := 0; i < 3; i++ { |
24 |
| -// identityPreimage := identitypreimage.Uint64ToIdentityPreimage(uint64(i)) |
25 |
| -// identityPreimages = append(identityPreimages, identityPreimage) |
26 |
| -// } |
27 |
| -// keyperIndex := uint64(1) |
28 |
| -// keyperConfigIndex := uint64(1) |
29 |
| - |
30 |
| -// tkg := testsetup.InitializeEon(ctx, b, dbpool, config, keyperIndex) |
31 |
| -// handler := &DecryptionKeyShareHandler{config: config, dbpool: dbpool} |
32 |
| - |
33 |
| -// shares := []*p2pmsg.KeyShare{} |
34 |
| -// for _, identityPreimage := range identityPreimages { |
35 |
| -// share := &p2pmsg.KeyShare{ |
36 |
| -// EpochID: identityPreimage.Bytes(), |
37 |
| -// Share: tkg.EpochSecretKeyShare(identityPreimage, 0).Marshal(), |
38 |
| -// } |
39 |
| -// shares = append(shares, share) |
40 |
| -// } |
41 |
| - |
42 |
| -// msg := &p2pmsg.DecryptionKeyShares{ |
43 |
| -// InstanceID: config.GetInstanceID(), |
44 |
| -// Eon: keyperConfigIndex, |
45 |
| -// KeyperIndex: keyperIndex, |
46 |
| -// Shares: shares, |
47 |
| -// } |
48 |
| - |
49 |
| -// b.ResetTimer() |
50 |
| -// validationResult, err := handler.ValidateMessage(ctx, msg) |
51 |
| -// b.StopTimer() |
52 |
| - |
53 |
| -// assert.NilError(b, err) |
54 |
| -// assert.Equal(b, pubsub.ValidationAccept, validationResult) |
55 |
| -// } |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + pubsub "github.com/libp2p/go-libp2p-pubsub" |
| 8 | + "gotest.tools/assert" |
| 9 | + |
| 10 | + "github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database" |
| 11 | + "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/identitypreimage" |
| 12 | + "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/testsetup" |
| 13 | + "github.com/shutter-network/rolling-shutter/rolling-shutter/p2p" |
| 14 | + "github.com/shutter-network/rolling-shutter/rolling-shutter/p2pmsg" |
| 15 | +) |
| 16 | + |
| 17 | +func BenchmarkDecryptionKeySharesValidationIntegration(b *testing.B) { |
| 18 | + ctx := context.Background() |
| 19 | + |
| 20 | + dbpool, dbclose := testsetup.NewTestDBPool(ctx, b, database.Definition) |
| 21 | + b.Cleanup(dbclose) |
| 22 | + |
| 23 | + keyperIndex := uint64(1) |
| 24 | + tkg := testsetup.InitializeEon(ctx, b, dbpool, config, keyperIndex) |
| 25 | + |
| 26 | + keyperConfigIndex := uint64(1) |
| 27 | + identityPreimages := []identitypreimage.IdentityPreimage{} |
| 28 | + for i := 0; i < 10000; i++ { |
| 29 | + identityPreimage := identitypreimage.Uint64ToIdentityPreimage(uint64(i)) |
| 30 | + identityPreimages = append(identityPreimages, identityPreimage) |
| 31 | + } |
| 32 | + identityPreimages = sort |
| 33 | + var handler p2p.MessageHandler = &DecryptionKeyShareHandler{config: config, dbpool: dbpool} |
| 34 | + |
| 35 | + shares := []*p2pmsg.KeyShare{} |
| 36 | + for _, identityPreimage := range identityPreimages { |
| 37 | + share := &p2pmsg.KeyShare{ |
| 38 | + EpochID: identityPreimage.Bytes(), |
| 39 | + Share: tkg.EpochSecretKeyShare(identityPreimage, 0).Marshal(), |
| 40 | + } |
| 41 | + shares = append(shares, share) |
| 42 | + } |
| 43 | + msg := &p2pmsg.DecryptionKeyShares{ |
| 44 | + InstanceID: config.GetInstanceID(), |
| 45 | + Eon: keyperConfigIndex, |
| 46 | + KeyperIndex: 0, |
| 47 | + Shares: shares, |
| 48 | + } |
| 49 | + |
| 50 | + validationResult, err := handler.ValidateMessage(ctx, msg) |
| 51 | + assert.NilError(b, err) |
| 52 | + assert.Equal(b, pubsub.ValidationAccept, validationResult) |
| 53 | + _, err = handler.HandleMessage(ctx, msg) |
| 54 | + assert.NilError(b, err) |
| 55 | + |
| 56 | + shares2 := []*p2pmsg.KeyShare{} |
| 57 | + for _, identityPreimage := range identityPreimages { |
| 58 | + share := &p2pmsg.KeyShare{ |
| 59 | + EpochID: identityPreimage.Bytes(), |
| 60 | + Share: tkg.EpochSecretKeyShare(identityPreimage, 2).Marshal(), |
| 61 | + } |
| 62 | + shares2 = append(shares2, share) |
| 63 | + } |
| 64 | + msg2 := &p2pmsg.DecryptionKeyShares{ |
| 65 | + InstanceID: config.GetInstanceID(), |
| 66 | + Eon: keyperConfigIndex, |
| 67 | + KeyperIndex: 2, |
| 68 | + Shares: shares2, |
| 69 | + } |
| 70 | + |
| 71 | + b.ResetTimer() |
| 72 | + validationResult, err = handler.ValidateMessage(ctx, msg2) |
| 73 | + assert.NilError(b, err) |
| 74 | + assert.Equal(b, pubsub.ValidationAccept, validationResult) |
| 75 | + _, err = handler.HandleMessage(ctx, msg2) |
| 76 | + assert.NilError(b, err) |
| 77 | + b.StopTimer() |
| 78 | + |
| 79 | + assert.NilError(b, err) |
| 80 | + assert.Equal(b, pubsub.ValidationAccept, validationResult) |
| 81 | +} |
0 commit comments