@@ -3,7 +3,6 @@ package syncer
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "math/big"
7
6
8
7
"github.com/ethereum/go-ethereum/accounts/abi/bind"
9
8
"github.com/ethereum/go-ethereum/log"
@@ -128,17 +127,23 @@ func (s *EonPubKeySyncer) getInitialPubKeys(ctx context.Context) ([]*event.EonPu
128
127
if err != nil {
129
128
return nil , err
130
129
}
131
-
132
130
initialPubKeys := []* event.EonPublicKey {}
131
+ // NOTE: These are pubkeys that at the state of s.StartBlock
132
+ // are known to the contracts.
133
+ // That way we recreate older broadcast publickey events.
134
+ // We are only interested for keys that belong to keyper-set
135
+ // that are currently active or will become active in
136
+ // the future:
133
137
for i := activeEon ; i < numKS ; i ++ {
134
138
e , err := s .GetEonPubKeyForEon (ctx , opts , i )
135
- // FIXME: translate the error that there is no key
136
- // to a continue of the loop
137
- // (key not in mapping error, how can we catch that?)
138
139
if err != nil {
139
140
return nil , err
140
141
}
141
- initialPubKeys = append (initialPubKeys , e )
142
+ // if e == nil, this means the keyperset did not broadcast a
143
+ // key (yet)
144
+ if e != nil {
145
+ initialPubKeys = append (initialPubKeys , e )
146
+ }
142
147
}
143
148
return initialPubKeys , nil
144
149
}
@@ -158,11 +163,14 @@ func (s *EonPubKeySyncer) GetEonPubKeyForEon(ctx context.Context, opts *bind.Cal
158
163
return nil , err
159
164
}
160
165
key , err := s .KeyBroadcast .GetEonKey (opts , eon )
161
- // XXX: can the key be a null byte?
162
- // I think we rather get a index out of bounds error.
163
166
if err != nil {
164
167
return nil , err
165
168
}
169
+ // NOTE: Solidity returns the null value whenever
170
+ // one tries to access a key in mapping that doesn't exist
171
+ if len (key ) == 0 {
172
+ return nil , nil
173
+ }
166
174
return & event.EonPublicKey {
167
175
Eon : eon ,
168
176
Key : key ,
@@ -174,49 +182,16 @@ func (s *EonPubKeySyncer) watchNewEonPubkey(ctx context.Context) error {
174
182
for {
175
183
select {
176
184
case newEonKey , ok := <- s .keyBroadcastCh :
177
- s .Log .Info (
178
- "pubsyncer received value" ,
179
- )
180
185
if ! ok {
181
186
return nil
182
187
}
183
- s .Log .Info (
184
- "pubsyncer channel ok" ,
185
- )
186
- // FIXME: this happens, why?
187
- if len (newEonKey .Key ) == 0 {
188
- opts := & bind.CallOpts {
189
- Context : ctx ,
190
- BlockNumber : new (big.Int ).SetUint64 (newEonKey .Raw .BlockNumber ),
191
- }
192
- k , err := s .GetEonPubKeyForEon (ctx , opts , newEonKey .Eon )
193
- s .Log .Error (
194
- "extra call for GetEonPubKeyForEon errored" ,
195
- "error" ,
196
- err .Error (),
197
- )
198
- s .Log .Info (
199
- "retrieved eon pubkey by getter" ,
200
- "eon" ,
201
- k ,
202
- )
203
- } else {
204
- s .Log .Info (
205
- "pubsyncer key lenght ok" ,
206
- )
207
- }
208
188
pubk := newEonKey .Key
209
189
bn := newEonKey .Raw .BlockNumber
210
190
ev := & event.EonPublicKey {
211
191
Eon : newEonKey .Eon ,
212
192
Key : pubk ,
213
193
AtBlockNumber : number .NewBlockNumber (& bn ),
214
194
}
215
- s .Log .Info (
216
- "pubsyncer constructed event" ,
217
- "event" ,
218
- ev ,
219
- )
220
195
err := s .Handler (ctx , ev )
221
196
if err != nil {
222
197
s .Log .Error (
0 commit comments