File tree 4 files changed +50
-7
lines changed
4 files changed +50
-7
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,34 @@ func New(
134
134
broadcaster Broadcaster ,
135
135
committer Committer ,
136
136
catcher Catcher ,
137
+ ) Process {
138
+ return NewWithCurrentHeight (
139
+ whoami ,
140
+ DefaultHeight ,
141
+ f ,
142
+ timer ,
143
+ scheduler ,
144
+ proposer ,
145
+ validator ,
146
+ broadcaster ,
147
+ committer ,
148
+ catcher ,
149
+ )
150
+ }
151
+
152
+ // NewWithCurrentHeight returns a new Process that starts at the given height
153
+ // with empty message logs.
154
+ func NewWithCurrentHeight (
155
+ whoami id.Signatory ,
156
+ height Height ,
157
+ f int ,
158
+ timer Timer ,
159
+ scheduler Scheduler ,
160
+ proposer Proposer ,
161
+ validator Validator ,
162
+ broadcaster Broadcaster ,
163
+ committer Committer ,
164
+ catcher Catcher ,
137
165
) Process {
138
166
return Process {
139
167
whoami : whoami ,
@@ -148,7 +176,7 @@ func New(
148
176
committer : committer ,
149
177
catcher : catcher ,
150
178
151
- State : DefaultState (),
179
+ State : DefaultState (). WithCurrentHeight ( height ) ,
152
180
}
153
181
}
154
182
Original file line number Diff line number Diff line change @@ -8,6 +8,13 @@ import (
8
8
"github.com/renproject/surge"
9
9
)
10
10
11
+ var (
12
+ // DefaulHeight is set to 1, because the genesis block is assumed to exist
13
+ // at Height 0.
14
+ DefaultHeight = Height (1 )
15
+ DefaultRound = Round (0 )
16
+ )
17
+
11
18
// The State of a Process. It should be saved after every method call on the
12
19
// Process, but should not be saved during method calls (interacting with the
13
20
// State concurrently is unsafe). It is worth noting that the State does not
@@ -50,13 +57,11 @@ type State struct {
50
57
TraceLogs map [Round ]map [id.Signatory ]bool
51
58
}
52
59
53
- // DefaultState returns a State with all fields set to their default values. The
54
- // Height default to 1, because the genesis block is assumed to exist at Height
55
- // 0.
60
+ // DefaultState returns a State with all fields set to their default values.
56
61
func DefaultState () State {
57
62
return State {
58
- CurrentHeight : 1 , // Skip genesis.
59
- CurrentRound : 0 ,
63
+ CurrentHeight : DefaultHeight ,
64
+ CurrentRound : DefaultRound ,
60
65
CurrentStep : Proposing ,
61
66
LockedValue : NilValue ,
62
67
LockedRound : InvalidRound ,
Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ package replica
2
2
3
3
import (
4
4
"github.com/renproject/hyperdrive/mq"
5
+ "github.com/renproject/hyperdrive/process"
5
6
6
7
"go.uber.org/zap"
7
8
)
8
9
9
10
// Options represent the options for a Hyperdrive Replica
10
11
type Options struct {
11
12
Logger * zap.Logger
13
+ StartingHeight process.Height
12
14
MessageQueueOpts mq.Options
13
15
}
14
16
@@ -20,6 +22,7 @@ func DefaultOptions() Options {
20
22
}
21
23
return Options {
22
24
Logger : logger ,
25
+ StartingHeight : process .DefaultHeight ,
23
26
MessageQueueOpts : mq .DefaultOptions (),
24
27
}
25
28
}
@@ -30,6 +33,12 @@ func (opts Options) WithLogger(logger *zap.Logger) Options {
30
33
return opts
31
34
}
32
35
36
+ // WithStartingHeight updates the height that the Replica will start at
37
+ func (opts Options ) WithStartingHeight (height process.Height ) Options {
38
+ opts .StartingHeight = height
39
+ return opts
40
+ }
41
+
33
42
// WithMqOptions updates the Replica's message queue options
34
43
func (opts Options ) WithMqOptions (mqOpts mq.Options ) Options {
35
44
opts .MessageQueueOpts = mqOpts
Original file line number Diff line number Diff line change @@ -53,8 +53,9 @@ func New(
53
53
) * Replica {
54
54
f := len (signatories ) / 3
55
55
scheduler := scheduler .NewRoundRobin (signatories )
56
- proc := process .New (
56
+ proc := process .NewWithCurrentHeight (
57
57
whoami ,
58
+ opts .StartingHeight ,
58
59
f ,
59
60
linearTimer ,
60
61
scheduler ,
You can’t perform that action at this time.
0 commit comments