@@ -10,25 +10,39 @@ import (
10
10
11
11
var _ Receiver = (* ImmediateDecide )(nil )
12
12
13
+ type ImmediateDecideOption func (* ImmediateDecide )
14
+
15
+ func ImmediateDecideWithNthParticipant (n uint64 ) ImmediateDecideOption {
16
+ return func (i * ImmediateDecide ) {
17
+ i .additionalParticipant = & n
18
+ }
19
+ }
20
+
13
21
// / An "adversary" that immediately sends a DECIDE message, justified by its own COMMIT.
14
22
type ImmediateDecide struct {
15
23
id gpbft.ActorID
16
24
host Host
17
25
value gpbft.ECChain
26
+
27
+ additionalParticipant * uint64
18
28
}
19
29
20
- func NewImmediateDecide (id gpbft.ActorID , host Host , value gpbft.ECChain ) * ImmediateDecide {
21
- return & ImmediateDecide {
30
+ func NewImmediateDecide (id gpbft.ActorID , host Host , value gpbft.ECChain , opts ... ImmediateDecideOption ) * ImmediateDecide {
31
+ i := & ImmediateDecide {
22
32
id : id ,
23
33
host : host ,
24
34
value : value ,
25
35
}
36
+ for _ , opt := range opts {
37
+ opt (i )
38
+ }
39
+ return i
26
40
}
27
41
28
- func NewImmediateDecideGenerator (value gpbft.ECChain , power * gpbft.StoragePower ) Generator {
42
+ func NewImmediateDecideGenerator (value gpbft.ECChain , power * gpbft.StoragePower , opts ... ImmediateDecideOption ) Generator {
29
43
return func (id gpbft.ActorID , host Host ) * Adversary {
30
44
return & Adversary {
31
- Receiver : NewImmediateDecide (id , host , value ),
45
+ Receiver : NewImmediateDecide (id , host , value , opts ... ),
32
46
Power : power ,
33
47
}
34
48
}
@@ -55,15 +69,39 @@ func (i *ImmediateDecide) StartInstanceAt(instance uint64, _when time.Time) erro
55
69
SupplementalData : * supplementalData ,
56
70
}
57
71
sigPayload := i .host .MarshalPayloadForSigning (i .host .NetworkName (), & justificationPayload )
58
- _ , pubkey := powertable .Get (i .id )
59
- sig , err := i .host .Sign (context .Background (), pubkey , sigPayload )
60
- if err != nil {
72
+ signers := bitfield .New ()
73
+
74
+ signers .Set (uint64 (powertable .Lookup [i .id ]))
75
+
76
+ if i .additionalParticipant != nil {
77
+ signers .Set (* i .additionalParticipant )
78
+ }
79
+
80
+ var (
81
+ pubkeys []gpbft.PubKey
82
+ sigs [][]byte
83
+ )
84
+
85
+ if err := signers .ForEach (func (j uint64 ) error {
86
+ pubkey := gpbft .PubKey ("fake pubkey" )
87
+ sig := []byte ("fake sig" )
88
+ if j < uint64 (len (powertable .Entries )) {
89
+ pubkey = powertable .Entries [j ].PubKey
90
+ var err error
91
+ sig , err = i .host .Sign (context .Background (), pubkey , sigPayload )
92
+ if err != nil {
93
+ return err
94
+ }
95
+ }
96
+
97
+ pubkeys = append (pubkeys , pubkey )
98
+ sigs = append (sigs , sig )
99
+ return nil
100
+ }); err != nil {
61
101
panic (err )
62
102
}
63
103
64
- signers := bitfield .New ()
65
- signers .Set (uint64 (powertable .Lookup [i .id ]))
66
- aggregatedSig , err := i .host .Aggregate ([]gpbft.PubKey {pubkey }, [][]byte {sig })
104
+ aggregatedSig , err := i .host .Aggregate (pubkeys , sigs )
67
105
if err != nil {
68
106
panic (err )
69
107
}
0 commit comments