Skip to content

Commit f5831db

Browse files
committed
fix: hot swap relay query both contracts
1 parent 09c5bf8 commit f5831db

File tree

1 file changed

+77
-12
lines changed

1 file changed

+77
-12
lines changed

client/collector/signingPolicy.go

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ import (
1616
"gorm.io/gorm"
1717
)
1818

19+
var (
20+
RelayFlareOld = common.HexToAddress("0x57a4c3676d08Aa5d15410b5A6A80fBcEF72f3F45")
21+
RelayFlareNew = common.HexToAddress("0xCcF30790A93F15e24EB909548a2C58a9b0a7FBd4")
22+
23+
RelayCoston2Old = common.HexToAddress("0x97702e350CaEda540935d92aAf213307e9069784")
24+
RelayCoston2New = common.HexToAddress("0xa10B672D1c62e5457b17af63d4302add6A99d7dE")
25+
26+
RelaySongbirdOld = common.HexToAddress("0x67a916E175a2aF01369294739AA60dDdE1Fad189")
27+
RelaySongbirdNew = common.HexToAddress("0xCB86E8Be709001e01897Bf59847406853da8f14b")
28+
29+
RelayCostonOld = common.HexToAddress("0x92a6E1127262106611e1e129BB64B6D8654273F7")
30+
RelayCostonNew = common.HexToAddress("0x051f214D346Cfd97B107BECb87E2B35D1b4287E9")
31+
)
32+
33+
func RequiresNewRelayAddress(address common.Address) (bool, common.Address) {
34+
switch address {
35+
case RelayFlareOld:
36+
return true, RelayFlareNew
37+
case RelayCoston2Old:
38+
return true, RelayCoston2New
39+
case RelaySongbirdOld:
40+
return true, RelaySongbirdNew
41+
case RelayCostonOld:
42+
return true, RelayCostonNew
43+
default:
44+
return false, address
45+
}
46+
}
47+
1948
// SigningPolicyInitializedListener initiates a channel that serves signingPolicyInitialized events emitted by relayContractAddress.
2049
func SigningPolicyInitializedListener(
2150
ctx context.Context,
@@ -31,23 +60,46 @@ func SigningPolicyInitializedListener(
3160
Number: 3,
3261
}
3362

34-
logs, err := database.FetchLatestLogsByAddressAndTopic0(
35-
ctx, db, params,
36-
)
37-
if err != nil {
38-
logger.Panic("error fetching initial logs:", err)
63+
allLogs := make([]database.Log, 0, 3)
64+
65+
if requires, newAddress := RequiresNewRelayAddress(relayContractAddress); requires {
66+
params.Address = newAddress
67+
68+
newLogs, err := database.FetchLatestLogsByAddressAndTopic0(
69+
ctx, db, params,
70+
)
71+
if err != nil {
72+
logger.Panic("error fetching initial logs new:", err)
73+
}
74+
75+
allLogs = append(allLogs, newLogs...)
3976
}
77+
78+
if len(allLogs) < 3 {
79+
params.Address = relayContractAddress
80+
params.Number = 3 - len(allLogs)
81+
82+
logs, err := database.FetchLatestLogsByAddressAndTopic0(
83+
ctx, db, params,
84+
)
85+
if err != nil {
86+
logger.Panic("error fetching initial logs:", err)
87+
}
88+
89+
allLogs = append(allLogs, logs...)
90+
}
91+
4092
latestQuery := time.Now()
41-
logger.Debug("Logs length:", len(logs))
42-
if len(logs) == 0 {
43-
logger.Panic("No initial signing policies found:", err)
93+
logger.Debug("Logs length:", len(allLogs))
94+
if len(allLogs) == 0 {
95+
logger.Panic("No initial signing policies found:")
4496
}
4597

4698
// signingPolicyStorage expects policies in increasing order
47-
sorted := make([]shared.VotersData, 0, len(logs))
99+
sorted := make([]shared.VotersData, 0, len(allLogs))
48100

49-
for i := range logs {
50-
votersData, err := AddSubmitAddressesToSigningPolicy(ctx, db, registryContractAddress, logs[len(logs)-i-1])
101+
for i := range allLogs {
102+
votersData, err := AddSubmitAddressesToSigningPolicy(ctx, db, registryContractAddress, allLogs[len(allLogs)-i-1])
51103
if err != nil {
52104
logger.Panic("error fetching initial signing policies with submit addresses:", err)
53105
}
@@ -62,7 +114,7 @@ func SigningPolicyInitializedListener(
62114
logger.Info("SigningPolicyInitializedListener exiting:", ctx.Err())
63115
}
64116

65-
spiTargetedListener(ctx, db, relayContractAddress, registryContractAddress, logs[0], latestQuery, votersDataChan)
117+
spiTargetedListener(ctx, db, relayContractAddress, registryContractAddress, allLogs[0], latestQuery, votersDataChan)
66118
}
67119

68120
// spiTargetedListener that only starts aggressive queries for new signingPolicyInitialized events a bit before the expected emission and stops once it gets one and waits until the next window.
@@ -150,6 +202,19 @@ func queryNextSPI(
150202
return nil, err
151203
}
152204

205+
if requires, newAddress := RequiresNewRelayAddress(relayContractAddress); requires {
206+
params.Address = newAddress
207+
208+
newLogs, err := database.FetchLogsByAddressAndTopic0Timestamp(
209+
ctx, db, params,
210+
)
211+
if err != nil {
212+
return nil, err
213+
}
214+
215+
logs = append(logs, newLogs...)
216+
}
217+
153218
if len(logs) > 0 {
154219
votersDataArray := make([]shared.VotersData, 0)
155220
if len(logs) > 1 {

0 commit comments

Comments
 (0)