From bf02717f6076fd3c8ae07da925525982c0e8ffe3 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Thu, 19 Nov 2020 20:25:45 +0800 Subject: [PATCH] fix test --- statediff/service.go | 10 +++++----- statediff/service_test.go | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/statediff/service.go b/statediff/service.go index 121279f2e..7127cf5da 100644 --- a/statediff/service.go +++ b/statediff/service.go @@ -116,7 +116,7 @@ type Service struct { // A mapping of subscription params rlp hash to the corresponding subscription params SubscriptionTypes map[common.Hash]Params // Cache the last block so that we can avoid having to lookup the next block's parent - lastBlock blockCache + BlockCache blockCache // Whether or not we have any subscribers; only if we do, do we processes state diffs subscribers int32 // Interface for publishing statediffs as PG-IPLD objects @@ -134,7 +134,7 @@ type blockCache struct { maxSize uint } -func newBlockCache(max uint) blockCache { +func NewBlockCache(max uint) blockCache { return blockCache{ blocks: make(map[common.Hash]*types.Block), maxSize: max, @@ -173,7 +173,7 @@ func New(stack *node.Node, ethServ *eth.Ethereum, params ServiceParams) error { QuitChan: make(chan bool), Subscriptions: make(map[common.Hash]map[rpc.ID]Subscription), SubscriptionTypes: make(map[common.Hash]Params), - lastBlock: newBlockCache(workers), + BlockCache: NewBlockCache(workers), indexer: indexer, enableWriteLoop: params.EnableWriteLoop, numWorkers: workers, @@ -230,7 +230,7 @@ func (sds *Service) WriteLoop(chainEventCh chan core.ChainEvent) { log.Debug("(WriteLoop) Event received from chainEventCh", "event", chainEvent) currentBlock := chainEvent.Block statediffMetrics.lastEventHeight.Update(int64(currentBlock.Number().Uint64())) - parentBlock := sds.lastBlock.replace(currentBlock, sds.BlockChain) + parentBlock := sds.BlockCache.replace(currentBlock, sds.BlockChain) if parentBlock == nil { log.Error("Parent block is nil, skipping this block", "block height", currentBlock.Number()) continue @@ -271,7 +271,7 @@ func (sds *Service) Loop(chainEventCh chan core.ChainEvent) { continue } currentBlock := chainEvent.Block - parentBlock := sds.lastBlock.replace(currentBlock, sds.BlockChain) + parentBlock := sds.BlockCache.replace(currentBlock, sds.BlockChain) if parentBlock == nil { log.Error("Parent block is nil, skipping this block", "number", currentBlock.Number()) continue diff --git a/statediff/service_test.go b/statediff/service_test.go index ef3c1bb2c..ca9a483a5 100644 --- a/statediff/service_test.go +++ b/statediff/service_test.go @@ -94,6 +94,7 @@ func testErrorInChainEventLoop(t *testing.T) { QuitChan: serviceQuit, Subscriptions: make(map[common.Hash]map[rpc.ID]statediff.Subscription), SubscriptionTypes: make(map[common.Hash]statediff.Params), + BlockCache: statediff.NewBlockCache(1), } payloadChan := make(chan statediff.Payload, 2) quitChan := make(chan bool) @@ -177,6 +178,7 @@ func testErrorInBlockLoop(t *testing.T) { QuitChan: make(chan bool), Subscriptions: make(map[common.Hash]map[rpc.ID]statediff.Subscription), SubscriptionTypes: make(map[common.Hash]statediff.Params), + BlockCache: statediff.NewBlockCache(1), } payloadChan := make(chan statediff.Payload) quitChan := make(chan bool) @@ -256,6 +258,7 @@ func testErrorInStateDiffAt(t *testing.T) { QuitChan: make(chan bool), Subscriptions: make(map[common.Hash]map[rpc.ID]statediff.Subscription), SubscriptionTypes: make(map[common.Hash]statediff.Params), + BlockCache: statediff.NewBlockCache(1), } stateDiffPayload, err := service.StateDiffAt(testBlock1.NumberU64(), defaultParams) if err != nil {