@@ -12,6 +12,7 @@ import (
12
12
"time"
13
13
14
14
"github.com/ethereum/go-ethereum/accounts/abi/bind"
15
+ "github.com/ethereum/go-ethereum/params"
15
16
16
17
lru "github.com/hashicorp/golang-lru"
17
18
@@ -53,6 +54,7 @@ type RecvConfig struct {
53
54
54
55
type receiver struct {
55
56
cfg RecvConfig
57
+ config * params.ChainConfig
56
58
chainId * big.Int
57
59
epoch uint64
58
60
startnumber uint64
@@ -83,6 +85,13 @@ func newReceiver(config RecvConfig, log log.Logger) *receiver {
83
85
log : log ,
84
86
}
85
87
88
+ switch config .ChainID {
89
+ case 56 :
90
+ o .config = params .BSCChainConfig
91
+ case 97 :
92
+ o .config = params .ChapelChainConfig
93
+ }
94
+
86
95
if cache , err := lru .NewARC (CacheSize ); err != nil {
87
96
o .log .Panicf ("fail to create lru head cache - size(%d) err(%s)" , CacheSize , err .Error ())
88
97
} else {
@@ -209,7 +218,7 @@ func (o *receiver) recoverable(err error) bool {
209
218
}
210
219
211
220
func (o * receiver ) applyAndCache (snap * Snapshot , head * types.Header ) (* Snapshot , error ) {
212
- next , err := snap .apply (head , o .chainId )
221
+ next , err := snap .apply (o . config , head , o .chainId )
213
222
if err != nil {
214
223
o .log .Warnf ("fail to apply snapshot - err(%s)" , err )
215
224
return nil , err
@@ -239,9 +248,9 @@ var ErrInconsistentCount = 0
239
248
func (o * receiver ) loop (hash common.Hash , och chan <- interface {}) error {
240
249
o .log .Tracef ("StartReceiverLoop" )
241
250
headCh := make (chan * types.Header )
242
- calc := newBlockFinalityCalculator (hash , make ([]common.Hash , 0 ), o .snapshots , o .log )
251
+ calc := newBlockFinalityCalculator (o . config , hash , make ([]common.Hash , 0 ), o .snapshots , o .log )
243
252
244
- snap , err := o .snapshots .get (hash )
253
+ snap , err := o .snapshots .get (o . config , hash )
245
254
if err != nil {
246
255
o .log .Panicf ("NoSnapshot(%s)" , hash )
247
256
}
@@ -271,7 +280,7 @@ func (o *receiver) loop(hash common.Hash, och chan<- interface{}) error {
271
280
final := fnzs [len (fnzs )- 1 ]
272
281
var number uint64
273
282
var hash common.Hash
274
- if snap , err := o .snapshots .get (final ); err != nil {
283
+ if snap , err := o .snapshots .get (o . config , final ); err != nil {
275
284
o .log .Panicln (err .Error ())
276
285
} else {
277
286
// latest finalized block number
@@ -323,7 +332,7 @@ func (o *receiver) updateStatus(number uint64, hash common.Hash, sequence uint64
323
332
func (o * receiver ) queryAndCacheMessages (child , ancestor common.Hash ) (uint64 , error ) {
324
333
var sequence uint64
325
334
for child != ancestor {
326
- snap , _ := o .snapshots .get (child )
335
+ snap , _ := o .snapshots .get (o . config , child )
327
336
o .log .Debugf ("Query Message BlockHash(%d:%s)" , snap .Number , snap .Hash )
328
337
ms , err := o .client .MessagesByBlockHash (context .Background (), child )
329
338
if err != nil {
@@ -340,7 +349,7 @@ func (o *receiver) queryAndCacheMessages(child, ancestor common.Hash) (uint64, e
340
349
}
341
350
}
342
351
343
- if snap , err := o .snapshots .get (child ); err != nil {
352
+ if snap , err := o .snapshots .get (o . config , child ); err != nil {
344
353
return sequence , err
345
354
} else {
346
355
child = snap .ParentHash
@@ -402,7 +411,7 @@ func (o *receiver) selectFork(from common.Hash, blocks *BlockTree) []common.Hash
402
411
403
412
var hash common.Hash
404
413
for _ , child := range children {
405
- snap , err := o .snapshots .get (child )
414
+ snap , err := o .snapshots .get (o . config , child )
406
415
if err == nil {
407
416
hash = snap .Hash
408
417
break
@@ -440,14 +449,14 @@ func (o *receiver) BuildBlockUpdate(status *btp.BMCLinkStatus, limit int64) ([]l
440
449
o .log .Debugf ("Build block updates - P(%d:%.8s) L(%d:%d:%.8s)" ,
441
450
peer .number , peer .blocks .Root ().Hex (), o .local .number , o .local .cache , o .local .hash )
442
451
defer o .log .Debugf ("Done - Build block updates" )
443
- if _ , err := o .snapshots .get (peer .hash ); err != nil {
452
+ if _ , err := o .snapshots .get (o . config , peer .hash ); err != nil {
444
453
o .log .Errorf ("No header for finalized block number(%d)" , peer .number )
445
454
return nil , errors .New ("NoCachedHeader" )
446
455
}
447
456
448
457
canonical := o .selectFork (peer .hash , peer .blocks )
449
458
o .log .Debugf ("Canonical(%v)" , canonical )
450
- calc := newBlockFinalityCalculator (peer .hash , canonical , o .snapshots , o .log )
459
+ calc := newBlockFinalityCalculator (o . config , peer .hash , canonical , o .snapshots , o .log )
451
460
452
461
heads := make ([]* types.Header , 0 )
453
462
parent := peer .hash
@@ -749,7 +758,7 @@ func (o *receiver) prepare() error {
749
758
}
750
759
751
760
if ! ok {
752
- snap , err := BootSnapshot (o .epoch , head , o .client .Client , o .log )
761
+ snap , err := BootSnapshot (o .config , o . epoch , head , o .client .Client , o .log )
753
762
if err != nil {
754
763
return err
755
764
}
@@ -773,7 +782,7 @@ func (o *receiver) synchronize(until *big.Int) error {
773
782
774
783
// synchronize snapshots
775
784
o .log .Infof ("synchronize block snapshots - until(%s)" , hash )
776
- if err := o .snapshots .ensure (hash ); err != nil {
785
+ if err := o .snapshots .ensure (o . config , hash ); err != nil {
777
786
o .log .Errorf ("fail to load past snapshots - err(%+v)" , err )
778
787
return err
779
788
}
0 commit comments