@@ -164,7 +164,7 @@ var defaultCacheConfig = &CacheConfig{
164
164
SnapshotWait : true ,
165
165
}
166
166
167
- type BlockChainOption func (* BlockChain ) * BlockChain
167
+ type BlockChainOption func (* BlockChain ) ( * BlockChain , error )
168
168
169
169
// BlockChain represents the canonical chain given a database with a genesis
170
170
// block. The Blockchain manages chain imports, reverts, chain reorganisations.
@@ -198,16 +198,16 @@ type BlockChain struct {
198
198
txLookupLimit uint64
199
199
triesInMemory uint64
200
200
201
- hc * HeaderChain
202
- rmLogsFeed event.Feed
203
- chainFeed event.Feed
204
- chainSideFeed event.Feed
205
- chainHeadFeed event.Feed
201
+ hc * HeaderChain
202
+ rmLogsFeed event.Feed
203
+ chainFeed event.Feed
204
+ chainSideFeed event.Feed
205
+ chainHeadFeed event.Feed
206
206
chainBlockFeed event.Feed
207
- logsFeed event.Feed
208
- blockProcFeed event.Feed
209
- scope event.SubscriptionScope
210
- genesisBlock * types.Block
207
+ logsFeed event.Feed
208
+ blockProcFeed event.Feed
209
+ scope event.SubscriptionScope
210
+ genesisBlock * types.Block
211
211
212
212
chainmu sync.RWMutex // blockchain insertion lock
213
213
@@ -451,7 +451,10 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
451
451
}
452
452
// do options before start any routine
453
453
for _ , option := range options {
454
- bc = option (bc )
454
+ bc , err = option (bc )
455
+ if err != nil {
456
+ return nil , err
457
+ }
455
458
}
456
459
// Take ownership of this particular state
457
460
go bc .update ()
@@ -525,7 +528,6 @@ func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, sorted bool) {
525
528
bc .diffLayerCache .RemoveOldest ()
526
529
}
527
530
528
- //json.MarshalIndent()
529
531
bc .diffLayerCache .Add (diffLayer .BlockHash , diffLayer )
530
532
if cached , ok := bc .diffLayerChanCache .Get (diffLayer .BlockHash ); ok {
531
533
diffLayerCh := cached .(chan struct {})
@@ -3145,27 +3147,31 @@ func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscr
3145
3147
}
3146
3148
3147
3149
// Options
3148
- func EnableLightProcessor (bc * BlockChain ) * BlockChain {
3150
+ func EnableLightProcessor (bc * BlockChain ) ( * BlockChain , error ) {
3149
3151
bc .processor = NewLightStateProcessor (bc .Config (), bc , bc .engine )
3150
- return bc
3152
+ return bc , nil
3151
3153
}
3152
3154
3153
- func EnablePipelineCommit (bc * BlockChain ) * BlockChain {
3155
+ func EnablePipelineCommit (bc * BlockChain ) ( * BlockChain , error ) {
3154
3156
bc .pipeCommit = true
3155
- return bc
3157
+ return bc , nil
3156
3158
}
3157
3159
3158
3160
func EnablePersistDiff (limit uint64 ) BlockChainOption {
3159
- return func (chain * BlockChain ) * BlockChain {
3161
+ return func (chain * BlockChain ) ( * BlockChain , error ) {
3160
3162
chain .diffLayerFreezerBlockLimit = limit
3161
- return chain
3163
+ return chain , nil
3162
3164
}
3163
3165
}
3164
3166
3165
3167
func EnableBlockValidator (chainConfig * params.ChainConfig , engine consensus.Engine , mode VerifyMode , peers verifyPeers ) BlockChainOption {
3166
- return func (bc * BlockChain ) * BlockChain {
3167
- bc .validator = NewBlockValidator (chainConfig , bc , engine , mode , peers )
3168
- return bc
3168
+ return func (bc * BlockChain ) (* BlockChain , error ) {
3169
+ validator , err := NewBlockValidator (chainConfig , bc , engine , mode , peers )
3170
+ if err != nil {
3171
+ return bc , err
3172
+ }
3173
+ bc .validator = validator
3174
+ return bc , nil
3169
3175
}
3170
3176
}
3171
3177
@@ -3289,7 +3295,6 @@ func (bc *BlockChain) GenerateDiffLayer(blockHash common.Hash) (*types.DiffLayer
3289
3295
if diffLayer != nil {
3290
3296
diffLayer .BlockHash = blockHash
3291
3297
diffLayer .Number = block .NumberU64 ()
3292
-
3293
3298
bc .cacheDiffLayer (diffLayer , true )
3294
3299
}
3295
3300
0 commit comments