@@ -193,10 +193,8 @@ type ctx struct {
193
193
// timing intervals and vote details. This is a JSON structure for logging
194
194
// purposes.
195
195
type voteInterval struct {
196
- Vote v1.CastVote `json:"vote"` // RPC vote
197
- Votes int `json:"votes"` // Always 1 for now
198
- Total time.Duration `json:"total"` // Cumulative time
199
- At time.Duration `json:"at"` // Delay to fire off vote
196
+ Vote v1.CastVote `json:"vote"` // RPC vote
197
+ At time.Duration `json:"at"` // Delay to fire off vote
200
198
}
201
199
202
200
func newClient (shutdownCtx context.Context , cfg * config ) (* ctx , error ) {
@@ -781,103 +779,6 @@ func (c *ctx) voteIntervalLen() uint64 {
781
779
return uint64 (c .voteIntervalQ .Len ())
782
780
}
783
781
784
- // calculateTrickle calculates the trickle schedule.
785
- func (c * ctx ) calculateTrickle (token , voteBit string , ctres * pb.CommittedTicketsResponse , smr * pb.SignMessagesResponse ) error {
786
- votes := uint64 (len (ctres .TicketAddresses ))
787
- duration := c .cfg .voteDuration
788
- maxDelay := uint64 (duration .Seconds () / float64 (votes ) * 2 )
789
- minAvgInterval := uint64 (35 )
790
- fmt .Printf ("Votes : %v\n " , votes )
791
- fmt .Printf ("Duration : %v\n " , duration )
792
- fmt .Printf ("Avg Interval: %v\n " , time .Duration (maxDelay / 2 )* time .Second )
793
-
794
- // Ensure that the duration allows for sufficiently randomized delays
795
- // in between votes
796
- if duration .Seconds () < float64 (minAvgInterval )* float64 (votes ) {
797
- return fmt .Errorf ("Vote duration must be at least %v" ,
798
- time .Duration (float64 (minAvgInterval )* float64 (votes ))* time .Second )
799
- }
800
-
801
- // Create array of work to be done. Vote delays are random durations
802
- // between [0, maxDelay] (exclusive) which means that the vote delay
803
- // average will converge to slightly less than duration/votes as the
804
- // number of votes increases. Vote duration is treated as a hard cap
805
- // and can not be exceeded.
806
- buckets := make ([]* voteInterval , votes )
807
- var (
808
- done bool
809
- retries int
810
- )
811
- maxRetries := 100
812
- for retries = 0 ; ! done && retries < maxRetries ; retries ++ {
813
- done = true
814
- var total time.Duration
815
- for i := 0 ; i < len (buckets ); i ++ {
816
- seconds , err := util .RandomUint64 ()
817
- if err != nil {
818
- return err
819
- }
820
- seconds %= maxDelay
821
- if i == 0 {
822
- // We always immediately vote the first time
823
- // around. This should help catch setup errors.
824
- seconds = 0
825
- }
826
-
827
- // Assemble missing vote bits
828
- h , err := chainhash .NewHash (ctres .TicketAddresses [i ].Ticket )
829
- if err != nil {
830
- return err
831
- }
832
- signature := hex .EncodeToString (smr .Replies [i ].Signature )
833
-
834
- t := time .Duration (seconds ) * time .Second
835
- total += t
836
- buckets [i ] = & voteInterval {
837
- Vote : v1.CastVote {
838
- Token : token ,
839
- Ticket : h .String (),
840
- VoteBit : voteBit ,
841
- Signature : signature ,
842
- },
843
- Votes : 1 ,
844
- Total : total ,
845
- At : t ,
846
- }
847
-
848
- // Make sure we are not going over our allotted time.
849
- if total > duration {
850
- done = false
851
- break
852
- }
853
- }
854
- }
855
- if retries >= maxRetries {
856
- // This should not happen
857
- return fmt .Errorf ("Could not randomize vote delays" )
858
- }
859
-
860
- // Sanity
861
- if len (buckets ) != len (ctres .TicketAddresses ) {
862
- return fmt .Errorf ("unexpected time bucket count got " +
863
- "%v, wanted %v" , len (ctres .TicketAddresses ),
864
- len (buckets ))
865
- }
866
-
867
- // Convert buckets to a list
868
- for _ , v := range buckets {
869
- c .voteIntervalPush (v )
870
- }
871
-
872
- // Log work
873
- err := c .jsonLog (workJournal , token , buckets )
874
- if err != nil {
875
- return err
876
- }
877
-
878
- return nil
879
- }
880
-
881
782
// _voteTrickler trickles votes to the server. The idea here is to not issue
882
783
// large number of votes in one go to the server at the same time giving away
883
784
// which IP address owns what votes.
@@ -1138,14 +1039,14 @@ func (c *ctx) _vote(token, voteId string) error {
1138
1039
// Calculate vote duration if not set
1139
1040
if c .cfg .voteDuration .Seconds () == 0 {
1140
1041
blocksLeft := vs .EndHeight - bestBlock
1141
- if blocksLeft < c .cfg .blocksPerDay {
1142
- return fmt .Errorf ("less than a day left to " +
1143
- "vote, please set --voteduration " +
1042
+ if blocksLeft < c .cfg .blocksPerHour {
1043
+ return fmt .Errorf ("less than one hour left to" +
1044
+ " vote, please set --voteduration " +
1144
1045
"manually" )
1145
1046
}
1146
1047
c .cfg .voteDuration = activeNetParams .TargetTimePerBlock *
1147
1048
(time .Duration (blocksLeft ) -
1148
- time .Duration (c .cfg .blocksPerDay ))
1049
+ time .Duration (c .cfg .blocksPerHour ))
1149
1050
}
1150
1051
1151
1052
// Generate work
0 commit comments