@@ -3,7 +3,6 @@ package syncer
33import (
44 "context"
55 "fmt"
6- "math/big"
76
87 "github.com/ethereum/go-ethereum/accounts/abi/bind"
98 "github.com/ethereum/go-ethereum/log"
@@ -128,17 +127,23 @@ func (s *EonPubKeySyncer) getInitialPubKeys(ctx context.Context) ([]*event.EonPu
128127 if err != nil {
129128 return nil , err
130129 }
131-
132130 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:
133137 for i := activeEon ; i < numKS ; i ++ {
134138 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?)
138139 if err != nil {
139140 return nil , err
140141 }
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+ }
142147 }
143148 return initialPubKeys , nil
144149}
@@ -158,11 +163,14 @@ func (s *EonPubKeySyncer) GetEonPubKeyForEon(ctx context.Context, opts *bind.Cal
158163 return nil , err
159164 }
160165 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.
163166 if err != nil {
164167 return nil , err
165168 }
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+ }
166174 return & event.EonPublicKey {
167175 Eon : eon ,
168176 Key : key ,
@@ -174,49 +182,16 @@ func (s *EonPubKeySyncer) watchNewEonPubkey(ctx context.Context) error {
174182 for {
175183 select {
176184 case newEonKey , ok := <- s .keyBroadcastCh :
177- s .Log .Info (
178- "pubsyncer received value" ,
179- )
180185 if ! ok {
181186 return nil
182187 }
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- }
208188 pubk := newEonKey .Key
209189 bn := newEonKey .Raw .BlockNumber
210190 ev := & event.EonPublicKey {
211191 Eon : newEonKey .Eon ,
212192 Key : pubk ,
213193 AtBlockNumber : number .NewBlockNumber (& bn ),
214194 }
215- s .Log .Info (
216- "pubsyncer constructed event" ,
217- "event" ,
218- ev ,
219- )
220195 err := s .Handler (ctx , ev )
221196 if err != nil {
222197 s .Log .Error (
0 commit comments