Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit d260d8c

Browse files
authored
feat: force starting period (#32)
1 parent 9f9e048 commit d260d8c

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

chains/evm/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type EVMConfig struct {
2323
RetryInterval uint64 `default:"12" split_words:"true"`
2424
CommitteePeriodLength uint64 `default:"256" split_words:"true"`
2525
StartingPeriod uint64 `required:"true" split_words:"true"`
26+
ForcePeriod bool `default:"false" split_words:"true"`
2627
}
2728

2829
// LoadEVMConfig loads EVM config from the environment and validates the fields

chains/evm/config/config_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad_DefaultValues() {
6464
CommitteePeriodLength: 256,
6565
BeaconEndpoint: "endpoint",
6666
StartingPeriod: 500,
67+
ForcePeriod: false,
6768
})
6869
}
6970

@@ -82,6 +83,7 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() {
8283
os.Setenv("SPECTRE_DOMAINS_1_COMMITTEE_PERIOD_LENGTH", "128")
8384
os.Setenv("SPECTRE_DOMAINS_2_ROUTER", "invalid")
8485
os.Setenv("SPECTRE_DOMAINS_1_STARTING_PERIOD", "500")
86+
os.Setenv("SPECTRE_DOMAINS_1_FORCE_PERIOD", "true")
8587

8688
c, err := config.LoadEVMConfig(1)
8789

@@ -102,5 +104,6 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() {
102104
CommitteePeriodLength: 128,
103105
BeaconEndpoint: "endpoint",
104106
StartingPeriod: 500,
107+
ForcePeriod: true,
105108
})
106109
}

chains/evm/listener/handlers/rotate.go

+3-14
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,8 @@ func NewRotateHandler(
4444
domainID uint8,
4545
domains []uint8,
4646
committeePeriodLenght uint64,
47-
startingPeriod uint64,
48-
) (*RotateHandler, error) {
49-
storedPeriod, err := periodStorer.Period(domainID)
50-
if err != nil {
51-
return nil, err
52-
}
53-
54-
var latestPeriod *big.Int
55-
if storedPeriod.Uint64() >= startingPeriod {
56-
latestPeriod = storedPeriod
57-
} else {
58-
latestPeriod = big.NewInt(int64(startingPeriod))
59-
}
47+
latestPeriod *big.Int,
48+
) *RotateHandler {
6049
return &RotateHandler{
6150
prover: prover,
6251
periodStorer: periodStorer,
@@ -65,7 +54,7 @@ func NewRotateHandler(
6554
msgChan: msgChan,
6655
committeePeriodLength: committeePeriodLenght,
6756
latestPeriod: latestPeriod,
68-
}, err
57+
}
6958
}
7059

7160
// HandleEvents checks if the current period is newer than the last stored

chains/evm/listener/handlers/rotate_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ func (s *RotateHandlerTestSuite) SetupTest() {
4848
s.mockProver = mock.NewMockProver(ctrl)
4949
s.mockPeriodStorer = mock.NewMockPeriodStorer(ctrl)
5050
s.msgChan = make(chan []*message.Message, 2)
51-
s.mockPeriodStorer.EXPECT().Period(uint8(1)).Return(big.NewInt(2), nil)
52-
s.handler, _ = handlers.NewRotateHandler(
51+
s.handler = handlers.NewRotateHandler(
5352
s.msgChan,
5453
s.mockPeriodStorer,
5554
s.mockProver,
5655
1,
5756
[]uint8{2, 3},
5857
256,
59-
3,
58+
big.NewInt(3),
6059
)
6160
}
6261

main.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,22 @@ func main() {
116116
}
117117
beaconProvider := beaconClient.(*http.Service)
118118

119+
storedPeriod, err := periodStore.Period(id)
120+
if err != nil {
121+
panic(err)
122+
}
123+
var latestPeriod *big.Int
124+
if (storedPeriod.Uint64() >= config.StartingPeriod) && !config.ForcePeriod {
125+
latestPeriod = storedPeriod
126+
} else {
127+
latestPeriod = big.NewInt(int64(config.StartingPeriod))
128+
}
129+
119130
lightClient := lightclient.NewLightClient(config.BeaconEndpoint)
120131
p := prover.NewProver(proverClient, beaconProvider, lightClient, prover.Spec(config.Spec))
121132
routerAddress := common.HexToAddress(config.Router)
122133
stepHandler := handlers.NewStepEventHandler(msgChan, client, beaconProvider, p, routerAddress, id, domains, config.BlockInterval)
123-
rotateHandler, err := handlers.NewRotateHandler(msgChan, periodStore, p, id, domains, config.CommitteePeriodLength, config.StartingPeriod)
124-
if err != nil {
125-
panic(err)
126-
}
134+
rotateHandler := handlers.NewRotateHandler(msgChan, periodStore, p, id, domains, config.CommitteePeriodLength, latestPeriod)
127135
listener := listener.NewEVMListener(beaconProvider, []listener.EventHandler{rotateHandler, stepHandler}, id, time.Duration(config.RetryInterval)*time.Second)
128136

129137
messageHandler := message.NewMessageHandler()

0 commit comments

Comments
 (0)